Apache MaxClientsAugust 1st, 2012
Apache web server has a configuration option called MaxClients. MaxClients determines the maximum number of concurrent connections that Apache will service.
MaxClients is not the same as maximum number of users. That is because a user generally downloads web pages and then spends time reading them and during that time Apache can service other users.
In Apache prefork MPM the MaxClients figure also determines the maximum number of Apache child processes that can be active. The more child processes that are spawned the higher the memory usage so MaxClients is an important server tuning option.
To determine what number you want to use for MaxClients you have to figure out how much RAM you can dedicate to Apache. You take your total memory figure and deduct a suitable amount for other software running on your server. So for example if you have a control panel like Cpanel or a DBMS like mysql running you will have to deduct the memory usage of those programs from your total available memory. Also deduct a suitable number for operating system overhead.
Then you try and determine how much memory a typical Apache process is using. You can use the ps command to find that out. For example in CentOS Linux:
ps -O rss -C httpd
If you are using some other distribution then replace httpd with your Apache binary name. For example apache2 on Debian.
The above command should give you a list of Apache process and their resident set size. An average of that number should give you a rough idea of how much memory an Apache child process will use.
Now you simply divide the amount of memory you can devote to Apache with the average process size to arrive at a suitable figure for Apache MaxClients.
I find that on control panel less servers a number of 75 per GB of RAM is a good starting point.
ServerLimit is a related Apache configuration option. ServerLimit is the maximum value for MaxClients for the life of the Apache server. For the prefork MPM you only need to worry about ServerLimit if you want to set the MaxClients value to above 256. In that case just set MaxClients and ServerLimit to the same number.
Fine tuning Apache MaxClients is more of an art than a science. Because of the way Linux reports process memory usage, and the different workloads Apache processes have to handle it isn’t possible to say with certainty how much memory a typical Apache process will use. So we can only estimate memory usage and that means we can only estimate the ideal MaxClients figure.