Geoff Garbers

Husband. Programmer. Tinkerer.

Calculating the average Apache process size

Jun 14, 2018

A long time ago, I used to always run my PHP websites using Apache’s prefork MPM with PHP. It was important to ensure that Apache was tuned correctly, ensuring that the memory on the server wasn’t exhausted.

The shell command shown below is what I used to use to calculate the average size of all the Apache processes running. This was a good indicator for limiting the maximum number of available processes that Apache was allowed to spawn.

ps -ylC apache2 | awk '{x += $8;y += 1} END {print "Process Memory Usage (MB): "x/1024; print "Average Proccess Size (MB): "x/((y-1)*1024); print "Total Number of Processes: "(y-1)}'