Maxclients
Settings MaxClients can be found in the Apache configuraton file, ie. by default: /etc/apache2/apache2.conf
<IfModule mpm_prefork_module>
under the sign:
After the setting is done, you can initiate a test run:
apache2ctl -t
and if there are no errors, the configuration will be activated with:
apache2ctl graceful
MaxClients is possible to increase up till the ServerLimit value, without the need to restart the server (ie. without terminating of current connection). The change of settings does not require even the slightest unavailability of the service.
After you set the ServerLimit we restart the Apache by:
apache2ctl restart
Correct value of MaxClients is key part for managing server resources, especially memory.
It is important to take this value into account before and after the deployment of the hosting on VPS, if you expect a high number of visitors or you think that the website is slow to load.
If you experience a “crashes” of the server or the website loads slowly, it is most likely that the fault lies in the wrong value of MaxClients.
From the perspective of RAM load and resistance to the sudden fluctuations it is possible to set the MaxClients by the equation:
MaxClients = (free RAM of the Apache) / (maximum RAM used for one process of the Apache2). And that is actually: ( [RAM VPS] – [memory for MySQL] – [other processes] ) / ( php.memory_limit + 15mb )
Gained values are for guidance only, the memory state is necessary to track. Let the maximum number of processes be such that even if they all take up the maximum possible RAM, together they do not exceed the available RAM.
Max value of RAM taken by child processes is set mostly by the memory_limit php, except that each process takes memory from 12mb to 20mb depending on the used apache2 modules and php.
Why is this value important? With the higher number of visitors the requests on the server, that the server has to process, increase accordingly. For loading the website from Apache2, the child processes start and they take up a connection each. Each child process requires a memory to run. The amount of memory that is require, depends on the PHP application and of course it is not the same for each load.
If the server does not have enough free memory, it will start to use swap – storage space on the disk. Disk is however much slower than RAM, which is noticeable. System also takes up more recourses to constantly move the data from the disk to the memory and back. It is only a temporary reserve solution for temporary memory spike.
With the increase of the visitors the status is unsustainable and when the free memory drops bellow critical limit, server gets to an inconsistent state, where the operating system is forced to terminate running processes to sustain itself.
On the other hands if the MaxClients value is too low, the child processes do not have enough time to complete themselves, it results in slow loading speed and often in error HTTP 503 SERVICE UNAVAILABLE.