Monday, May 21, 2012

Why apache shows multiple processes?


The multiple apache processes we see is by design to handle multiple requests. Those multiple processes is basically listeners with multiple threads, so that it can handle simultaneous traffic more efficiently.

By default, apache spawns10 processes and each process generally takes about 10MB. Assuming all the sub processes takes the same memory its about 100MB for apache running on a machine.

Example of apache running:
#top -U nobody

Memory: 8064M phys mem, 2620M free mem, 12G total swap, 9550M free swap

   PID USERNAME LWP PRI NICE  SIZE   RES STATE    TIME    CPU COMMAND
 14436 nobody     1  59    0   12M 3272K sleep    0:09  0.00% httpd
 14435 nobody     1  59    0   12M 3232K sleep    0:08  0.00% httpd
 17184 nobody     1  59    0   12M 4488K sleep    0:06  0.00% httpd
 14437 nobody     1  59    0   12M 4152K sleep    0:06  0.00% httpd
 17182 nobody     1  59    0   12M 4040K sleep    0:06  0.00% httpd
 14439 nobody     1  59    0   12M 3272K sleep    0:06  0.00% httpd
 16956 nobody     1  59    0   12M 4032K sleep    0:05  0.00% httpd
 14438 nobody     1  59    0   12M 3272K sleep    0:04  0.00% httpd
 17579 nobody     1  59    0   12M 3208K sleep    0:04  0.00% httpd
 17183 nobody     1  59    0   12M 3144K sleep    0:03  0.00% httpd



The defaults in httpd.conf include :


StartServers 8

MinSpareServers 5

User apache


That means start 8 listeners (total 9 processes - root httpd process + 8 servers) and have a minimum of 5 idle listeners at all times (dynamically creating new listeners as necessary). The 'User' directive controls which non-root account the listeners run as (usually 'apache' or 'nobody').

There are lots of other related directives but, unless you have low traffic and are trying to save memory, I wouldn't recommend changing the defaults.

No comments: