apache spawning too many processes despite maxclient and other constraints

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:

$ httpd -V
Server version: Apache/2.2.15 (Unix)
Server built:   May 28 2010 07:58:25
Server's Module Magic Number: 20051115:24
Server loaded:  APR 1.4.2, APR-Util 1.3.9
Compiled using: APR 1.4.2, APR-Util 1.3.9
Architecture:   32-bit
Server MPM:     Prefork
  threaded:     no
    forked:     yes (variable process count)

In this case my Server MPM is Prefork but yours may be different. On my Debian server running Apache2 it is Worker:

# /usr/sbin/apache2 -V
Server version: Apache/2.2.9 (Debian)
Server MPM:     Worker

On some machines (such as RedHat) it is not uncommon for both prefork and worker binaries to be present (one called httpd and another called httpd.worker or something similar). You may want to double-check (using ps or top or cat /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

This Multi-Processing Module (MPM) implements a non-threaded, pre-forking web server.


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

LoadModule mpm_prefork_module /usr/lib/apache2/modules/mod_mpm_prefork.so

<IfModule mpm_prefork_module>
StartServers         1
MinSpareServers      1
MaxSpareServers      0
ServerLimit          4
MaxClients           4
MaxRequestsPerChild  4000
</IfModule>

Doesn't work - configuration has no effect

<IfModule mpm_prefork_module>
StartServers         1
MinSpareServers      1
MaxSpareServers      0
ServerLimit          4
MaxClients           4
MaxRequestsPerChild  4000
</IfModule>

LoadModule mpm_prefork_module /usr/lib/apache2/modules/mod_mpm_prefork.so