There is an increase in the number of online web sites on hand and a slow visit. The initial view is that the server resources are insufficient, but after repeated testing, once connected, constantly click on the same page on the different links, can be opened quickly, this phenomenon is that the largest number of Apache connections are full, new visitors can only queue up to have free links, and if once connected on the Keeyalive Lifetime (KeepAliveTimeout, default 5 seconds) do not have to reopen the connection, so the solution is to increase the maximum number of Apache connections.
1. Where to set up.
The server is FreeBSD 6.2, Apache 2.24, with the default configuration (FreeBSD does not load custom MPM configuration by default), and the default maximum number of connections is 250
Load the MPM configuration in/usr/local/etc/apache22/httpd.conf (remove the previous note):
# Server-pool Management (MPM specific)
Include etc/apache22/extra/httpd-mpm.conf
Visible MPM configuration in/usr/local/etc/apache22/extra/httpd-mpm.conf, but inside according to httpd work mode divided a lot of pieces, which is the current httpd mode of work. You can view by executing apachectl-l:
Compiled in Modules:
Core.c
Prefork.c
Http_core.c
Mod_so.c
See Prefork Word so that the current httpd should be working in Prefork mode, the default configuration of Prefork mode is:
<ifmodule mpm_prefork_module>
Startservers 5
Minspareservers 5
Maxspareservers 10
MaxClients 150
Maxrequestsperchild 0
</IfModule>
2. How much do you want to add?
Connection number in theory, of course, the larger the better, but in the server's capabilities, this is related to the server's CPU, memory, bandwidth, and so on.
To view the current number of connections, use:
PS aux | grep httpd | Wc-l
Or:
Pgrep httpd|wc-l
Calculates the average amount of memory consumed by httpd:
PS aux|grep-v Grep|awk '/httpd/{sum+=$6;n++}; End{print sum/n} '
Because the basic is static page, CPU consumption is very low, each process occupies memory is not much, about 200K.
The server memory has 2G, eliminates the general boot service approximately needs 500M (conservatively estimated), has the 1.5G to be usable, then theoretically may support 1.5*1024*1024*1024/200000 = 8053.06368
About 8K processes, support 2W simultaneous access should be no problem (to ensure that 8 K of the people visit quickly, others may need to wait 1 or 2 seconds to connect, and once the connection will be very smooth)
Control the maxclients of the maximum number of connections, so you can try to configure to:
<ifmodule mpm_prefork_module>
Startservers 5
Minspareservers 5
Maxspareservers 10
Serverlimit 5500
MaxClients 5000
Maxrequestsperchild 100
</IfModule>
Note that maxclients defaults to a maximum of 250, to exceed this value will be explicitly set Serverlimit, and serverlimit to be placed before maxclients, the value is either less than maxclients, or restart the httpd will be prompted.
Restart the httpd, through repeated execution of Pgrep httpd|wc-l to observe the number of connections, you can see that the number of connections in the maxclients to achieve the set value is no longer increased, but at this time to visit the site is also very smooth, then do not have to greedy to set a higher value, Otherwise, if the site access to the sudden increase inadvertently consumes the memory of the server, can be based on the future access pressure trends and memory consumption changes to gradually adjust until you find an optimal set value.
(Maxrequestsperchild cannot be set to 0 and may cause server crashes due to memory leaks)
Better formula for maximum value calculation:
Apache_max_process_with_good_perfermance < (total_hardware_memory/apache_memory_per_process) * 2
apache_max_process = apache_max_process_with_good_perfermance * 1.5
Reference:
Parameter settings for Apache
Selection and configuration of Apache 2.0 performance optimized-MPM
How to avoid the httpd process of Apache consuming more memory
Prefork understanding and tuning of concurrent control parameters in Apache
Report:
Real-time detection of httpd connections:
Watch-n 1-d "Pgrep httpd|wc-l"
This article from Csdn Blog, reproduced please indicate the source: http://blog.csdn.net/nich262/archive/2009/04/13/4069078.aspx