Score:1

Memory consumption on virtual server too large for applications being run

in flag

I have a Linux Ubuntu virtual server at Digital Ocean with the following specs: 1 vCPU, 2GB of memory, and 25GB of SSD storage.

The server is running a single WordPress website with around 400 unique visitors per day. A caching plugin has been installed and configured. Redis is also installed and configured on the server.

I have setup a memory usage notice in the control panel of Digital Ocean and I am being notified multiples times a day that the server has crossed the 70% threshold for usage.

When I run htop in the terminal, MEM is being shown as using 1.2GB to 1.4GB of 1.92GB at any given moment. SWAP is shown to be using 39.2MB of 2.00GB.

When I view the peak memory usage in the Query Monitor plugin installed in WordPress, it shows only 3.2% of 768 MB server limit being used. I have defined the PHP memory limit to be 768MB in the WordPress configuration file. These numbers seem to run in contrast to what the server is telling me related to memory usage on the server.

In my server's my.cnf, I have the following parameters set:

  • performance_schema = off
  • innodb_buffer_pool_size = 512M
  • key_buffer_size = 64M
  • max_connections = 400

Can anyone suggest where the memory hogging me be taking place on the server?

HBruijn avatar
in flag
Why should 30% of your memory remain unused? Your memory is there to be used. https://www.linuxatemyram.com/
Romeo Ninov avatar
in flag
Questions on Server Fault must be about managing information technology systems in a business environment. Home and end-user computing questions may be asked on Super User, and questions about development, testing and development tools may be asked on Stack Overflow.
ws flag
Your config and metrics are all over the place. What "server limit"? What have you done to analyze the usage? How exactly did you php's memory limit?
ua flag
What version of MySQL?
Mike Hermary avatar
in flag
@RickJames The server is running MySQL 8.0.33
Mike Hermary avatar
in flag
@symcbean The memory limit was set in the PHP 8.0 FPM configuration file. I have tested from a low of 128MB up to 768MB. The same issues occur at all levels.
ua flag
@MikeHermary - OK, that is an upper limit. If the PHP code does get out of control, it would be better to crash PHP because of hitting the limit than crash the system due to running out of swap space.
Mike Hermary avatar
in flag
@RickJames I have changed the memory limit in the php.ini file to 256M. In the WordPress configuration file, I have set the memory limit to 128M with the max memory limit set to 256M. There have been no PHP crashes yet.
Mike Hermary avatar
in flag
@RickJames The server is still encountering memory utilization issues throughout the day. Do you have any other suggestions?
ua flag
What is on the 2GB machine? OS+WP+PHP+Apache+MySQL; anything else? You may need to upgrade to 4GB.
Mike Hermary avatar
in flag
@RickJames The server stack is as follows: Ubuntu 22 LTS, WP, PHP FPM, Nginx, and MySQL 8
ua flag
And what plugins for WP? A "caching plugin" sounds like a memory hog; get rid of it.
ua flag
PHP's memory limit applies only to PHP.
Mike Hermary avatar
in flag
@RickJames Should all caching be managed by Nginx, PHP, and Redis directly on the server?
ua flag
Each product, plus MySQL, has its own caching configuration and management. However, increasing the setting for one product will leave less RAM for the others, but without notifying them.
Score:2
ua flag
  • SHOW STATUS LIKE 'Max_used_connections'; -- It will probably say much less than the 400 allocated; lower max_connections to, say, 30.

  • You should not be using MyISAM; lower `key_buffer_size to 20M

  • Remove the caching; you probably don't have enough activity to warrant the extra cache layers. Anyway, the buffer_pool does most of the work. This, on the other hand, improves the indexes to improve performance. It takes very little RAM: WP Index Improvements

  • "PHP memory limit to be 768MB" -- That seems extremely high. Also it is per connection. Lower it to, say, 100MB. If PHP crashes, then let's look at simplifying the webpage that caused the crash.

  • If you still have memory troubles, lower innodb_buffer_pool_size.

Wilson Hauck avatar
jp flag
@Mike-Hermary If you still need assistance, please let us know.
Mike Hermary avatar
in flag
@RickJames The WordPress tables are mostly using the InnoDB schema. A couple of tables are using MyISAM. I have implemented the other suggestions. Now when I navigate to some pages, a database connection error is displayed intermittently.
ua flag
A couple of _your_ tables are MyISAM? Consider converting them.
Mike Hermary avatar
in flag
@RickJames Can I convert them safely with MySQL in the terminal via SSH?
ua flag
`ALTER TABLE tbl ENGINE=InnoDB`. More discussion of possible (rare) hiccups: http://mysql.rjweb.org/doc.php/myisam2innodb
Mike Hermary avatar
in flag
@RickJames Thanks! I used a plugin to successfully change the engine for the few tables in WordPress.
ua flag
@MikeHermary What was the name of the plugin?
Mike Hermary avatar
in flag
@RickJames I use WP Optimize to handle caching and database optimizations on my WordPress websites. It allows for engine alterations.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.