October 28, 2007

Make your webserver stable…

I gathered some ideas and tricks how to configure your webserver to prevent it from not serving request anymore. Sadly I cannot try it out on my blog, because it is not my own server.

Slashdot, Reddit, delicious, Furl, Newsvine and Digg are direct an enormous amount of user in a short time to very interesting articles. To prevent your server to fail I suggest you to check these things.

Check the mpm_prefork mod

In this module you should focus on the following three values:

  • StartServers: Defines how many servers should be created at startup
  • MaxClients: Number of servers allowed tobe started
  • MaxRequestPerChild: Defines how many requests a server should handle before beeing killed.

Suggestion: Put your StartServers around 32 and keep the MaxClients high. When tweaking here don’t forget to check how many connections your database can handle, you might have to change things there too.

Disable KeepAlive

… make the math. Apache is keeping the connection alive by default for about 15 sec. It supports a max of 256 connections at a time. If you have 800 people requesting your site at a time Apache will serve the max amount of supported connections (256) and let the other 544 people wait. A workaround would be to decrease the KeepAlive to a lower value.

Focus on the PHP settings

You should check if PHP is running in CGI mode, because if that is the case it is damn slow. It should be configured to run as a module (mod-php5), thats the fastest way you can have it.

Benchmarking

To benchmark your site just checkout ab. It normally comes with the default Apache installation.
Run ab -n 10000 -c 100 http://yourhost/index.php

This makes 10k requests split over 100 smiultaneous connections. The results are somehow self speaking.

Comments (2)

  1. October 28, 2007
    iCalvyn said...

    great infor. i will try it at my webserver..will fully build it soon, and host my own website…thank dude…

  2. May 17, 2008
    adf said...

    will you please read the docs before posting stuff like this? MaxClient is NOT the number of servers allowed, 256 connections is not a fixed limit, your logic about KeepAlive is totally broken. Results of ab are in no way “self speaking”, how do you know if your results are good or bad?

Leave a Reply