Tune Apache-MPM prefork with some Webminstats

A couple of days ago I started to do some optimizations on our server backends. Most of them are Apache-Prefork PHP powered.

One part of doing Apache-Tuning is to play around with the MPM configuration:

1<ifmodule prefork.c>
2  StartServers       4
3  MinSpareServers    3
4  MaxSpareServers   10
5  ServerLimit      256
6  MaxClients       256
7  MaxRequestsPerChild  10000
8</ifmodule>

The particular configuration setting for Apache can be found in the file /etc/apache/httpd.conf

I’m using Webmin->Sysstats to get some basic data where I can start from.

First I wanted to know the average and total memory usage of the apache worker process(es).

ApacheMemStat
Apache memory consumption (total, per worker)

As you can see after a few days you get a clew about how our worker memory consumption behaves.

Especially the per worker chart is import which gives you a hint for the MaxClients and ServerLimit settings.

The used bash script :

1-getApachePerWorkerMem)
2   ps -ylC apache2 | awk '{x += $8;y += 1} END {print x/((y-1)*1024)}';;
3-getApacheTotalMemPercent)
4   sys_mem=`free -m | awk 'NR==2{print $2 }'`
5   apache_total_mem=`ps -ylC apache2 | awk '{x += $8;y += 1} END {print x/1024;}'`
6   echo "scale=2;$apache_total_mem/($sys_mem/100)" | bc;;

Another important part is the relation of idle and busy workers.

Apache amount and relation of busy/idle workers
Apache amount and relation of busy/idle workers

Here we see that in this particular case we have an average ratio 10/2 (idle/busy) and our max is about (11/7) which gives a balanced amount of idle and busy workers.

The used bash script :

1-getApacheBusyWorker)
2  echo `wget -q -O - "$URL" --user="$USER" --password=$PASS |grep BusyWorker |cut -d" " -f2`;;
3-getApacheIdleWorker)
4  echo `wget -q -O - "$URL" --user="$USER" --password=$PASS |grep IdleWorker |cut -d" " -f2`;;

have fun

Mario