Here are my MPM constraints:
<IfModule mpm_prefork_module>
StartServers 10
MinSpareServers 10
MaxSpareServers 10
MaxClients 10
MaxRequestsPerChild 2000
</IfModule>
However despite this, I have over 20 apache processes running currently, and in the past hour or two there have been as many as 40-50. Shouldn't the MaxClient and MaxSpareServers keep the number of processes under control (i.e. about 10)?
Is there something I'm missing?
Apache comes in different flavours, two of the most common being prefork and worker. The prefork model spawns several processes but each process handles only one request at a time. The worker model, on the other hand, spawns several processes and each process has multiple threads, each thread handling one request at a time.
Depending on your distribution you may be running a different model to that which you are expecting. You are expecting prefork but are you sure this is the type that is running? To find out type:
In this case my
Server MPM
isPrefork
but yours may be different. On my Debian server running Apache2 it isWorker
:On some machines (such as RedHat) it is not uncommon for both prefork and worker binaries to be present (one called
httpd
and another calledhttpd.worker
or something similar). You may want to double-check (usingps
ortop
orcat /etc/init.d/httpd
) which is actually being launched.For anyone else who stumbles upon this question, there is another potential cause.
I know you believe you've already found your answer but with prefork you should see the same thing either way you look at it's processes. You must not have been using prefork.
This is why:
http://httpd.apache.org/docs/2.4/mod/prefork.html
A different explanation that I've run into
Loading the prefork module before the configuration options works, but if you load it after it seems to load some defaults instead, rendering your IfModule directive inert. You will likely only see this on a customized apache config, as distributions would have it setup correctly to start.
Works - configuration is applied
Doesn't work - configuration has no effect
I feel kind of stupid now, but this: Why does htop show lots of apache2 processes by ps aux doesn't? explains my problem.