5

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

Ash White
  • 151
  • 1
  • 3
  • Ash, I was having the same problem as you and I found the solution. Check it out [here](http://serverfault.com/questions/133561/apache-maxclients-reaching-max-and-locking-the-server/133603#133603), maybe it could also help you. – Rodrigo Sieiro Apr 18 '10 at 21:00

3 Answers3

3

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

hdanniel
  • 4,253
  • 22
  • 25
  • I forgot to address that... each process is actually averaging around 10MB, so 150*10 = 1500MB. Even if these numbers spike and the server does start swapping, would the lack of free memory cause Apache to hang like it is? That seems like a strange cause-and-effect. – Ash White Sep 02 '09 at 18:57
  • Yes, if Apache is swapping, then the server will stop to answer. Is really really painful. Also remember that the OS needs memory for other processes besides Apache. – hdanniel Sep 02 '09 at 19:01
  • 3
    I thought I had it fixed when I upped the RAM to 6GB, but Apache is still becoming unresponsive when MaxClients is reached, no matter how much RAM is free. Any other ideas? – Ash White Sep 06 '09 at 13:05
1

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.

Dave Drager
  • 8,315
  • 28
  • 45
0

Calculate MaxClients and set a value based on that rather than the default value.

Calculating Max-Client

first calculate average memory for apache children when the traffic is high.

Divide that with memory that you wish to allocate for Apache.

in your case if you wish to give 1 GB ram for webserver and average process mem usage is 16 mb then 1000 MB/16=62

this is the max_client value that you should give.

Also make sure that your are configuring for prefork rather than worker

if i am not wrong these are the variables for prefork-

MinSpareServers

MaxSpareServers      

MaxClients          

MaxRequestsPerChild   

since you are running mysql and apache on the same machine.You need to add more RAM otherwise it will ran out of memory and start swapping.Which slows down further.

Kevin Parker
  • 757
  • 1
  • 13
  • 29