Tag Archives: Apache prefork

Tuning the Apache Prefork MPM

To find httpd process avg memory usage:

[root@webserverpage /]#ps -ylC httpd | awk ‘{x += $8;y += 1} END {print “Apache Memory Usage (MB): “x/1024; print “Average Proccess Size (MB): “x/((y-1)*1024)}’
TOTAL: 31.6831

To find after excluding httpd and mysql total memory so that we can get
other processes usage memory:

[root@webserverpage /]# ps -eo user,%cpu,%mem,rsz,args|sort -rnk4|awk ‘BEGIN
{printf
“%8st%6st%6st%8st%sn”,”USER”,”%CPU”,”%MEM”,”RSZ”,”COMMAND”}{printf
“%8st%6st%6st%8s MBt%-12sn”,$1,$2,$3,$4/1024,$5}’ | grep -v -e
httpd -e mysqld | awk ‘{sum+=$4}END{print sum}’
TOTAL: 439.859

Mysqld Memory Usage:

[root@webserverpage /]# ps -eo user,%cpu,%mem,rsz,args|sort -rnk4|awk ‘BEGIN
{printf
“%8st%6st%6st%8st%sn”,”USER”,”%CPU”,”%MEM”,”RSZ”,”COMMAND”}{printf
“%8st%6st%6st%8s MBt%-12sn”,$1,$2,$3,$4/1024,$5}’ | grep mysqld |
awk ‘{sum+=$4}END{print sum/NR}’
TOTAL: 795.617

———–
CALCULATION
———–

Apache Avg Memory per httpd Process: 32MB
All other processes memory usage: 440MB
Max_Clients = (7943MB – 440MB) / 32MB = 235

Find the apache mode in your server by executing the command below.

[root@webserverpage /]# httpd -V
Server version: Apache/2.2.3
Server built: Jun 6 2012 10:00:42
Server’s Module Magic Number: 20051115:3
Server loaded: APR 1.2.7, APR-Util 1.2.7
Compiled using: APR 1.2.7, APR-Util 1.2.7
Architecture: 64-bit
Server MPM: Prefork
threaded: no
forked: yes (variable process count)

As you can see the MPM is “Prefork” so locate prefork in your apache settings.

vi /etc/httpd/conf/httpd.conf

From

StartServers 5
MinSpareServers 5
MaxSpareServers 10
ServerLimit 156
MaxClients 156
MaxRequestsPerChild 1000

To

StartServers 5
MinSpareServers 5
MaxSpareServers 10
ServerLimit 235
MaxClients 235
MaxRequestsPerChild 1000

Restart the httpd.

/etc/init.d/httpd stop
/etc/init.d/httpd start