Tuning Apache2 prefork MaxClients ServerLimit
Solution 1:
Apache prefork settings, per apache performance tuning guidelines
quote:
The single biggest hardware issue affecting webserver performance is RAM.
A webserver should never ever have to swap, as swapping increases the latency
of each request beyond a point that users consider "fast enough".
This causes users to hit stop and reload, further increasing the load.
You can, and should, control the MaxClients setting so that your server does
not spawn so many children it starts swapping. This 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.
you should set it up like this based on your input to:
- Total Memory : 128 GB
- -10% memory for everything except apache: 115 GB
- Now we need to figure out how much single apache process is using.
To calculate this you can use following script :
pgrep apache2 | xargs -n1 -I{} cat /proc/{}/smaps | \
awk '{if ($0 ~ /stack/) {pids+=1} else if ($0 ~/^Shared_/)
{shared+=$2} else if ($0 ~ /^Pss:/) {priv+=$2}} END {
printf "%.2f MB\n",(priv+shared/(pids*pids))/1024}'
This is best estimate of how much single apache process is using memory while trying to proportionally dividing shared usage per number of active apache processes and adding it on top of Pss (proportional set size)
Finally you divide 115 GB with this figure and you get MaxClients/ServerLimit
. From here you can relatively calculate other figures like
-
StartServers
30% of MaxClients -
MinSpareServers
5% of MaxClients -
MaxSpareServers
10% of MaxClients -
ServerLimit
== MaxClients -
MaxConnectionsPerChild
10000 (as conservative alternative to address possible problem with memory leaky apps)