Apache config for high traffic websites

Case:
Set up a Apache config that takes the max out of your server abilities.
The only goal is to serve as much visitors as possible.
Other things, like server load or bandwidth usage are not taken into account.

First step:
Check if there are any AH00161 errors


sudo cat /var/log/apache2/error.log | grep MaxRequestWorkers;
sudo cat /var/log/apache2/error.log | grep ServerLimit;

Check the average process size for Apache:


sudo 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)}'

Determine a good setting by available memory:

Max instances = ((free mem + cached mem) - amount to keep spare) / Apache avg process size

Set MaxRequestWorkers and ServerLimit to this calculation in mpm_prefork.conf and restart Apache

Check again if there are any AH00161 errors


sudo cat /var/log/apache2/error.log | grep MaxRequestWorkers;
sudo cat /var/log/apache2/error.log | grep ServerLimit;