Why is my VPS memory usage always so high?

Problem Description

  • My VPS nearly always shows close to (or at) 100% memory usage. Is this a problem?
  • How do I know when to increase my server's memory?
  • How do I lower my memory usage?
Operating System Caching: The apparent high memory usage typically comes from caching. Much like with Windows 7 and newer, the Operating System (OS) caches whatever it can in memory to make frequently repeated requests super-fast. As such, a simple memory query, like the one used to display memory usage in our Client Centre, will show most of your memory in use. By using the right utilities you can see how much of that memory is actually just caching and what the real (often called wired or active) memory usage is like.

Problem Resolution

How to view real memory usage without the cache: If you're using the Plesk control panel, open it up and it will show you the real memory usage value. Similarly, the command line utility called htop will show you the full breakdown of active vs. cached memory in a nice visual display. You may use the HTML 5 serial console button in the Client Centre to login via shell or use your favourite terminal app. If simply running 'htop' doesn't work, you'll probably need to install htop, click here to learn how.

How to know when you must increase memory: if your total memory usage including cache is always at 100% AND your Swap is consistently at 70% usage or higher, that's usually when it's time to increase memory. Another even more reliable indicator is to monitor the Linux Out Of Memory manager to see if it's killed anything recently in order to free up space. This process, frequently just called OOM, ensures the entire system doesn't crash by killing processes using the largest amount of memory. You can run the following command via Shell/SSH to see if this has happened recently:

grep OOM /var/log/messages

If you get any output from this, it will be indicating what processes were killed and when. In the event OOM killed anything, you should probably add more memory to prevent future killings.

Optimizing or Lowering PHP Memory Usage

If you're seeing a large number of php-cgi processes or php-fpm processes at the top of your memory usage report in htop or the Plesk process manager, then that website there's a website is allowed to use a large number of PHP processes. Each of those are loaded into memory, and it's possible they could be reduced to improve memory usage. But keep in mind that you've always got *some* function of CPU to memory. It generally works like this when a site gets, say 10, requests at once: either

a) You've got a domain set to have 15 PHP processes loaded into memory at once so that it can handle 15 simultaneous requests with minimal impact on CPU because no processes need to be loaded, or
b) You've got a domain set to have 0 processes loaded into memory at once and it dynamically loads them as the requests come in (ondemand mode). This will therefore require more CPU to load every process for every request that comes in, but it also means that your average memory usage is lower

Since memory is cheaper than CPU power AND the higher memory option typically results in faster websites (no required time to load a process before responding to it), we typically recommend using more memory when possible. That said, if you really wanted to keep memory usage down, you could always use ondemand mode and limit the max number of processes the site can use to be well within your current memory limits.

  • 1 Users Found This Useful