Why Apache needs so much children when almost there is no connections?

August 30, 2014 14.6k views

I'm using 1-click app Ubintu+Wordpress for a small blog on minimal configuration (with 512 MB of RAM).
New, small blog, just 1 page and 2 posts. Maximum pageviews per day - 156 (2 days ago).

Yesterday I've experienced a problem with RAM (details are here: https://www.digitalocean.com/community/questions/mysql-keeps-crashing-kill-process-919-mysqld-score-86-or-sacrifice-child). I've created a 1GB swap but it didn't help (mysql crushed anyway at some point).

Blog was just started. There is no much visitors for the moment. I believe, I was the only visitor yesterday and today. So I though it shouldn't be normal that 512 MB of RAM is not enough.

I found a tutorial for Apache optimization: https://www.digitalocean.com/community/tutorials/how-to-optimize-apache-web-server-performance

For example, it suggests to decrease number of children by changing parameter MaxClients in apache2.conf (for mpmpreforkmodule). Actually, in my case it's a parameter MaxRequestWorkers in mpm_prefork.conf.

Initially I changed it to 15 as it was suggested in tutorial (default setting was 150). But Apached stopped to work just after a restart. There was an error in Apache log: "server reached MaxRequestWorkers setting, consider raising the MaxRequestWorkers setting".

Then I set MaxRequestWorkers to 100. But again Apache stopped to work, but in this case a little later than previously.

So service doesn't work because of lack of memory of because of too small MaxRequestWorkers value. But if I increase MaxRequestWorkers it will eat all memory again.

What am I doing wrong? Should I be an experienced Linux user to use 1-click app Wordpress? Should I know how to fine tune Apache and MySQL.
(I don't believe 512 GB is not enough for a blog with a small number of visitors)

1 comment
  • I've set MaxRequestWorkers to the default value (150) and experienced the same problem.
    Did anyone had the same problem?

2 Answers

I'm not as familiar with apache and wordpress and was facing similar issues. I had this server that had enough ram and space to host a simple wordpress site but it kept running up the number of apache processes that it was allowed to create. I adjusted the MaxRequestWorkers as you had noted and still had no luck. I also noticed that even when no one was hitting my server the number of spawned child processes increased for no apparent reason.

That is until I saw this in my /etc/apache2/mods-enabled/mpm_prefork.conf:

<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxRequestWorkers 30
MaxConnectionsPerChild 0

I overlooked it initially but the MaxConnectionsPerChild is set to ZERO for some reason.... DER, no matter how many child processes are spawned, none of them will be able to connect to requests. I've changed that value to 10 right now and will keep monitoring the performance. Things are looking much better. Let me know if this helps.

I just got the same error. Apache hangs - had to restart manually. Saw this in the main error.log:

[mpm_prefork:error] [pid 10889] AH00161: server reached MaxRequestWorkers setting, consider raising the MaxRequestWorkers setting

Have another answer? Share your knowledge.