Top Navigation

Master Tuning Guide – MaxClients

From the documentation:

The MaxClients directive sets the limit on the number of simultaneous requests that will be served. Any connection attempts over the MaxClients limit will normally be queued, up to a number based on the ListenBacklog directive. Once a child process is freed at the end of a different request, the connection will then be serviced.

The exact function depends on the server type:

  • Non-threaded (prefork) – maximum number of child processes that will be launched to serve requests
  • Threaded & hybrid (beos or worker) total number of threads that will be available to serve clients

MaxClients is one of the most important settings for performance and stability.

If MaxClients is too low then the server may not be able to service the incoming requests. Here’s an example of the error message that you’ll see in the error log if the server reaches MaxClients:

If MaxClients is too high then the server may run out of memory. In this case you’ll see the server get progressively slower as it runs out of physical memory, starts swapping and then eventually locks up.

The best value for MaxClients is dependent on the amount of available memory and the size of the Apache processes.

This article which we published in 2009 give the basic process.

1. Determine the max process size from the RSS column with:

2. Divide the available memory by max process size to get an initial value for MaxClients

So for example if you had the following output from the “ps” command:

The the max process size in KB would be 14768. Here’s a one-liner to get the max process size:

If you have 3GB of RAM for Apache then set MaxClients to:

3000000 / 14768 = 203

Here are several other articles that suggest a similar method:

Here are some alternate methods for determining MaxClients:

And of course there are a number of articles with inaccurate or outdated information:

There are several related configuration settings:

  • ServerLimit
  • TreadsPerChild
  • ListenBacklog

NOTE: In Apache 2.4, MaxClients has been renamed to MaxRequestWorkers.