Stress-testing your server's MaxClients directive

2bits has a great article explaining the theory behind tuning your Apache server's MaxClients directive. It explains how to optimize this setting for your server's available memory based on this simple equation:

(Total Memory - Operating System Memory - MySQL memory) / Size Per Apache process.

The key here is to avoid thrashing (memory swapping to disk, which is extremely slow and sometimes unavailable), while making good use of the memory you have. This becomes particularly important for those hosting using VPS products where memory is precious and expensive.

The following test will quickly provide a real-world reference point for tuning the MaxClients directive:


  1. Start with a reasonable MaxClients value based on the math used in the 2bits article:
    sudo vim /etc/httpd/conf/httpd.conf
  2. Restart Apache:
    sudo /etc/init.d/httpd restart
  3. Start your benchmark tool (ab, JMeter, etc). Concurrency should be equal or higher than the value in step 1.
    ab -n 1000 -c 50
  4. While your benchmark tool is running, observe your server's memory consumption:
    watch -n 1 free -m
  5. Verify available memory use is stable and does not go below 15% of total memory.
  6. Rinse and repeat. Find the sweet spot.



  • Always back up your conf files before you edit them.
  • You may notice slower page load times from your benchmark tool while its concurrency is greater than your MaxClients setting.
  • If your server is a VPS product running without Swap support (on MediaTemple, for example), running out of memory can prove fatal to your VPS. Be careful when running this test against a live production web server.

Share This