Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

my vps memory usage

Here is a screenshot of my usage today on an idle unfinished cms drupal site with a maximum of 14 added modules besides core and no activity or users.

As you can see I am at my limit which is crazy so I need to limit memory usage of apache and mysql and php because my VPS is smallest one which should suit my current needs.

My system file my.cnf does not have a list of parameters as I've seen posted elsewhere but this is the file which apparently will lessen usage of memory amongst other things I've read like memory leaks and apache MPM workers vs apache prefork which seems to be what I have.

So how can I significantly reduce memory usage without removing apache or php5?

I am using mysql version 5.1.66 and looks like innodb and show variable yabbit.net/mysql.txt

share|improve this question
Are you using MyISAM, InnoDB or both? And what version of MySQL are you running? And could you post (pastebin or something) the output of all MySQL variables? (e.g. mysql -e "show variables" > /path/to/outputfile. And have you looked at other similar questions like this one? – gertvdijk Dec 6 '12 at 11:29
mysql 5.1.66 looks like only Innodb. – freja Dec 6 '12 at 13:50
Looks good. Caches are set fairly small (8MB InnoDB, 8MB MyISAM) as with default 5.1 MySQL. I don't think MySQL is causing this memory usage. You could verify that with mysqltuner.pl (download, run, report back the Maximum possible memory usage:) Have you locked down Apache MPM-Prefork to not scale to ~ 150 x 20MB as with Debian default for example? What is your MaxClients setting there? And can you be quantitative about "VPS is smallest one"? – gertvdijk Dec 6 '12 at 14:08
Basic 1 virtual CPU 256 MB 15 GB 60 GB – freja Dec 6 '12 at 14:18
up vote 3 down vote accepted

I'm suspecting that your Apache configuration is the culprit here, instead of your MySQL configuration. The current MySQL settings should not get it beyond about 50MB total (typically even lower I think).

However, from the configuration of Apache you posted in the comments along with the fact that your VPS only provides 256 MB of memory, I see that a setting of

MaxClients       256

for the Prefork MPM is way too much for such a machine. On my Debian Squeeze webservers I see about 20MB usage per fork, so about 15 connections will already consume all the memory in your machine. It's not hard to get so many concurrent connections and as a result processes will be killed, probably, or a lot of swap will be used. Result: disfunctional server or slow service response respectively.

I suggest you to either:

  • Scale down your prefork configuration significantly to for example this:

    <IfModule mpm_prefork_module>
        StartServers         10
        MinSpareServers      5
        MaxSpareServers      15
        MaxClients           15
        MaxRequestsPerChild  2000

    And live with the fact you can't serve more than about 8 concurrent visitors (usually two client connections per browser). This is a limitation of the amount of memory in combination with the chosen LAMP configuration.

  • Move to PHP-FPM, set up a small pool and move to the worker MPM or even another web server such as nginx. The worker MPM uses threads that share memory, rather than forks, which don't. This should allow you to handle more concurrent visitors.

share|improve this answer
Thanks for that help! I will see how I go with scaling it down because the other option will take me many hours to figure out.At the moment it is the slowest delivery in the history of mankind- embarrassingly slow. Lucky not live. Thanks again. – freja Dec 7 '12 at 0:07
and following this hosting.com/support/linux/tuning-the-apache-prefork-mpm I included ServerLimit and made it 15 equal to MaxClients. Still plan on upgrading ram. – freja Dec 7 '12 at 0:21
so made mine startservers 2; minspare & maxspare 3; clients &server 15 and 1000 maxresquests – freja Dec 7 '12 at 0:23
thanks to you my memory has now dropped down to 199.3mb – freja Dec 7 '12 at 8:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.