Configuring apache

Apache configuration should be set accordingly to the instance apache runs on. If the configuration values are too high - on a large number of requests, apache might choke by starting too many httpd processes which will increase the load average on the instance drastically and kill the server. Each one of these processes will open an sql connection, but won’t close it since it will never complete properly. You might notice a lot of open mysql connections when it happens.

When using apache with the recommended (and more popular) prefork configuration, you need to configure the following values:

StartServers - number of server processes to start

MinSpareServers - minimum number of server processes which are kept spare

MaxSpareServers - maximum number of server processes which are kept spare

MaxClients - maximum number of server processes allowed to start

MaxRequestsPerChild - maximum number of requests a server process serves

The value for MaxClients should be set according to the value of the available RAM:

available RAM / RAM per httpd process

To check RAM on your server, run the following command:

egrep --color 'Mem|Cache|Swap' /proc/meminfo

RAM on an aws medium instance is ~3.6GB

To determine the optimal values, try to test the server under high load and run the top command and examine the load average.

To edit any one of these values from the command line you can use:

sed -i 's/StartServers          16/StartServers          12/g' /etc/httpd/conf/httpd.conf

don’t forget to restart apache for the changes to take effect

apachectl restart

(NOTE: if you're using AWS OpsWorks to setup apache, the default template configures apache for a large ec2 instance, so you must adjust httpd.conf if you're running a smaller instance)

Follow me for updates on similar new posts I write or tweet about this post.