Recently the company has a customer reported a problem, that is, after running for a while in the Apache log/var/log/httpd/error_log file has an error message
[Fri Mar 04 10:48:20 2011] [ERROR] Server reached maxclients setting, consider raising the maxclients setting
Check, this is due to the number of concurrent links caused by too many, and then check the Apache documents, found that you can modify the Apache configuration text
The maxclients parameters in the/etc/httpd/conf/httpd.conf are adjusted.
Before adjusting the first check the Apache run in which mode is prefork or worker (specific prefork and worker what is the difference, can be Google below), if you do not know your Apache is that mode, you can use the "/usr/ Sbin/httpd-l "command to check, when the check out which mode, you can find the corresponding configuration part of the/etc/httpd/conf/httpd.conf to modify.
Here we first to reproduce the above problem, first write a PHP test program test.php, and put it in the/var/www/html/test.php location, the file content is relatively simple, simulate a simple page, the contents are as follows:
? Sleep (1); Phpinfo ();?>
You can then use the Apache Test tool AB to do the test, run the "Ab-c 512-n 100000 http://localhost/test.php" To do the test, where "-n 100000" refers to a total of 100,000 requests, "C-512" Refers to concurrent 512 requests, which can be found to have few successful requests and will soon appear in the log with the above error, due to the prefork mode in my environment, where the maxclients parameter defaults to 256, So this error occurs when the concurrency is high and this is 512.
Now let's modify the parameters to
<ifmodule prefork.c> startservers 8 minspareservers 5 maxspareservers serverlimit 256 MaxClients 256 MaxRequestsP Erchild 4000 </IfModule>
Amended to
<ifmodule prefork.c> startservers minspareservers maxspareservers-serverlimit 1024 MaxClients 1024 Questsperchild 4000 </IfModule>
Note that I have configured the maxclients=1024, and the test only used 512 concurrent requests, leaving a certain amount of room, this can be in a specific environment to make adjustments.
Then restart Apache "/etc/init.d/httpd restart".
Run the Ab-c 512-n 100000 http://localhost/test.php again, and you can see that all the requests are done correctly and that the error is no longer in the log.
The meaning of the parameters, in the configuration of Apache is described in detail, as follows:
# prefork MPM # Startservers:number of server processes to start # minspareservers:minimum number of server processes WH Ich are kept spare # maxspareservers:maximum number in server processes which are kept spare # Serverlimit:maximum value For maxclients for the lifetime of the server # maxclients:maximum number of servers processes allowed to start # maxrequ Estsperchild:maximum number of requests a server process serves
# worker MPM # startservers:initial number of server processes to start # maxclients:maximum number of simultaneous Clie NT Connections # minsparethreads:minimum number of worker threads which are kept spare # maxsparethreads:maximum number of worker threads which are kept spare # threadsperchild:constant number of worker threads in each server process # Maxre Questsperchild:maximum number of requests a server process serves