evgeny
By:
evgeny

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

August 30, 2014 15.8k 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?

3 Answers
evgeny February 5, 2017
Accepted Answer

The reason was an XML-RPC attack. Here you can find an article about how to protect you WordPress site: https://www.digitalocean.com/community/tutorials/how-to-protect-wordpress-from-xml-rpc-attacks-on-ubuntu-14-04

P.S. Sorry for keeping silence. I just did't use my DigitalOcean account for a long time:)

WordPress is a popular and powerful CMS (content management system) platform. Its popularity can bring unwanted attention in the form of malicious traffic specially targeted at a WordPress site. There are many instances where a server that has not been protected or optimized could experience issues or errors after receiving a small amount of malicious traffic. This guide will show you how to protect WordPress from XML-RPC attacks on an Ubuntu 14.04 system.

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
</IfModule>

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.

  • Hi, did this solve your problem please?

  • Actually, MaxConnectionsPerChild 0 is the default:

    The MaxConnectionsPerChild directive sets the limit on the number of connections that an individual child server process will handle. After MaxConnectionsPerChild connections, the child process will die. If MaxConnectionsPerChild is 0, then the process will never expire.

    Setting MaxConnectionsPerChild to a non-zero value limits the amount of memory that process can consume by (accidental) memory leakage.

    So, I think your fix works because it is stopping accidental memory leaks. You're getting runaway child server processes that aren't releasing their connections.

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.