1. To modify the maximum number of connections first, you must understand the Apache MPM (multi-processing Modules, multi-channel processing module)
MPM in Apache2.0 is divided into 3 types (perfork, worker, event). Perfork inherited from the Apache1.3, it uses the process management method, so it can provide more reliable performance and better compatibility, the worker is the new way in Apache2.0, it adopts the thread control method, can save the system overhead more than Perfork, Processing more data, but at the same time not very good compatibility, many old programs do not work under the worker; The event is still in the experimental phase, which allocates a different process pool for each task.
View method: View the MPM used by your Apache via Http-l
You can see that my Apache is using the Prefork method of working.
2. Configuring the Prefork parameter
The default parameters are as follows:
<ifmodule prefork.c>
Startservers 8
Minspareservers 5
Maxspareservers 20
MaxClients 150
Maxrequestsperchild 1000
</IfModule>
When Apache is started, Apache automatically creates startservers processes and tries to keep the number of idle processes between Minspareservers and maxspareservers.
If the idle process is less than minspareservers,apache, the process will be created at a rate of approximately 1 per second.
If the idle process is less than maxspareservers,apache, the extra idle process is removed and the server resource is freed.
The maximum number of processes is controlled by maxclients and can only be set to 256 in Apache1.3, but in Apache2.0, you may exceed the 256 limit by adding serverlimit items at the beginning of the configuration, at which point you must maxclients≤ serverlimit≤20000
Maxrequestsperchild is used to control how many requests each process is automatically destroyed, and this parameter can be set to 0 for infinity (that is, no process is destroyed).
My personal configuration is as follows:
<ifmodule prefork.c>
Startservers 10
Minspareservers 10
Maxspareservers 15
Serverlimit 4000
MaxClients 2056
Maxrequestsperchild 10000
</IfModule>
Effective after restarting Apache
3. About Apache maximum Connection number setting
To view the current number of connections, you can use:
PS aux | grep httpd | Wc-l
Or:
Pgrep httpd|wc-l
Calculate the average number of httpd occupied memory:
PS aux|grep-v Grep|awk '/httpd/{sum+=$6;n++}; End{print sum/n} '
The static page, CPU consumption is very low, each process consumes memory is not too much, about 200K.
If the server memory is 2G, except for the general boot service needs 500M (conservative estimate), and the remaining 1.5G is available, then theoretically support 1.5*1024*1024*1024/200000 = 8053.06368
About 8K processes, support 2W people at the same time access should be no problem (can guarantee that 8 k people access quickly, others may need to wait 1, 2 seconds to connect, and once the connection will be very smooth)
Reprint Address: http://www.phpddt.com/server/apache-MaxClients.html
Apache modifies the number of connections (RPM)