Apache hanging with MaxClients is reached

My Apache 2.2 (preform MPM) is hanging when MaxClients is reached, rather than queueing up requests and serving them when child processes become free. When this happens, the web server is totally unresponsive until it is manually restarted.

The server stack is Ubuntu 8, MySQL 5, PHP 5. Hardware is Dual Xeons (2.8) with 2GB of RAM. It serves 30,000 - 50,000 pageviews per day. Static images, CSS, and JS are offloaded to a separate server and PHP is cached using eAccelerator. The HTML output of many pages is cached to the filesystem.

Relevant Apache directives:

KeepAlive On
MaxKeepAliveRequests 50
KeepAliveTimeout 2
StartServers          2
MaxClients          150
MinSpareThreads      25
MaxSpareThreads      75
ThreadsPerChild      25
MaxRequestsPerChild   2000


Solution 1:

It seems that your server is swapping. Assuming a use of 16 MB for the apache processes, 150 x 16MB = 2400 MB, beyond the capacity of your server (2GB)

Check the memory used by Apache, I think you will need to reduce the MaxClients value.

You can find more information about this in the Hardware and OS Issues section from Apache Performance Tuning

Solution 2:

What is your Timeout variable set at?

You may want to push it down if you have not set it:

Timeout 30

As HD has said, you may wish to drop down your MaxClients or increase the RAM to ensure that it is not hitting swap.