5

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?

2
  • Two questions: Are you changing the correct config file? Did you restart apache after this change? Commented Dec 22, 2010 at 7:28
  • Yes. I'm changing apache2.conf, theres nothing in my httpd.conf. And yes, i restarted. Commented Dec 22, 2010 at 15:36

3 Answers 3

2

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.

3
  • This. Also, prefork is a memory hog so I would use Worker where possible. Though you may need to verify that Worker is stable when combined with your modules. Commented Dec 22, 2010 at 10:17
  • People often use prefork with modules that cannot be threaded such as mod_perl. Commented Dec 22, 2010 at 11:53
  • Thanks for your reply PP. I'm definitely using Prefork. Any reason why there's more processes running than what I specified in my config? Commented Dec 22, 2010 at 15:38
1

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 
1
  • THIS! Thank you! I've been beating my head on this for a few days now and it was because I put the config before it loaded the module. Commented Jun 8, 2017 at 19:18
0

I feel kind of stupid now, but this: Why does htop show lots of apache2 processes by ps aux doesn't? explains my problem.

1

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.