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:

<ifmodule prefork.c>
  StartServers       4
  MinSpareServers    3
  MaxSpareServers   10
  ServerLimit      256
  MaxClients       256
  MaxRequestsPerChild  10000
</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 :

-getApachePerWorkerMem)
   ps -ylC apache2 | awk '{x += $8;y += 1} END {print x/((y-1)*1024)}';;
-getApacheTotalMemPercent)
   sys_mem=`free -m | awk 'NR==2{print $2 }'`
   apache_total_mem=`ps -ylC apache2 | awk '{x += $8;y += 1} END {print x/1024;}'`
   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 :

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

have fun

Mario