Reduce number of Apache processes

It depends which mpm module (mpm_worker/mpm_prefork/mpm_event) your apache is using. If you are unsure, then post the output of cat /etc/apache2/mods-enabled/mpm*.conf which reveals the number of StartServers/MinSpareServers/MaxSpareServers, MaxRequestWorkers and maybe ThreadsPerChild and ThreadLimit. If the filenames should be different in your linux distro, then post an output of your enabled modules ls -l /etc/apache2/mods-enabled.

It should look like something like this and explains itself (Debian, Apache2.4):

[email protected]:/# cat /etc/apache2/mods-enabled/mpm*.conf
# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# MaxRequestWorkers: maximum number of server processes allowed to start
# MaxConnectionsPerChild: maximum number of requests a server process serves

<IfModule mpm_prefork_module>
    StartServers             5
    MinSpareServers       5
    MaxSpareServers      10

    # same as MaxClients in Apache 2.2
    MaxRequestWorkers     150
    MaxConnectionsPerChild   0

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

See Reducing Apache Memory usage and Average Process Size Value

The documentation says (as described in the link above):

You can, and should, control the MaxClients setting so that your server does not spawn so many children that it starts swapping. The procedure for doing this is simple: determine the size of your average Apache process, by looking at your process list via a tool such as top, and divide this into your total available memory, leaving some room for other processes.


Tasks: 207 total,   1 running, 206 sleeping,   0 stopped,   0 zombie
%Cpu(s):  2.4 us,  0.8 sy,  0.0 ni, 96.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem : 16307588 total, 14360744 free,  1188636 used,   758208 buff/cache
KiB Swap:        0 total,        0 free,        0 used. 14686936 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                 
 6567 www-data  20   0  296028  15288   5616 S   0.0  0.1   0:00.07 apache2                                                                 
 6569 www-data  20   0  296040  15360   5676 S   0.0  0.1   0:00.08 apache2                                                                 
 6571 www-data  20   0  295996  15200   5676 S   0.0  0.1   0:00.07 apache2                                                                 
 6572 www-data  20   0  296028  15348   5676 S   0.0  0.1   0:00.08 apache2                                                                 
 6573 www-data  20   0  296040  15356   5676 S   0.0  0.1   0:00.07 apache2

Running the cool script from the linked page above gives me:

[email protected]:~# ps -ylC apache2 | awk '{x += $8;y += 1} END {print "Apache Memory Usage (MB): "x/1024; print "Average Process Size (MB): "x/((y-1)*1024)}'
Apache Memory Usage (MB): 100.711
Average Process Size (MB): 16.7852

Note: "Average Process Size" is the "RES" value when you run top.

To determine MaxClients (aka MaxRequestWorkers), I need to calculate:

Maxclients=X/Y where
   X=Max. Available Memory Reserved for Apache
   Y=Average Process Size