How to increase the maximum number of connections by Apache _linux

Source: Internet
Author: User
MaxClients N

1, apache1.x
n is an integer that represents the maximum number of connections between 1 and 256, if you want to allow Apache to support more connections, then you need to modify the Httpd.h file in the source code, edit the/httpd-2.0.59/include/httpd.h in the Hard_server_ The limit value is changed to large and then compiled.
Ways to increase the maximum number of Apache connections:
Set in httpd.conf:
MaxClients N
n is an integer that represents the maximum number of connections between 1 and 256, if you want to allow Apache to support more connections, then you need to modify the Httpd.h file in the source code, the definition of the Hard_server_limit value and then compile
2, apache2.x
The system defaults to the number of 150 connections, and the following example is modified to 1500.
modifying httpd.conf files
Found it
<ifmodule prefork.c>
Startservers 8
Minspareservers 5
Maxspareservers 20
MaxClients 150
Maxrequestsperchild 1000
</IfModule>
Modify
MaxClients 150
For
Serverlimit 1500
MaxClients 1500
Then save the exit.
Restart the HTTP service (/etc/rc.d/init.d/httpd restart)
Every time you redo the server, you will learn something new, so the most concise and effective way to understand Linux is to constantly redo the system, reconfigure the optimization system (xd!).
The use of apache2.2.6, after the completion of the compilation, the maximum number of connections by default of 150, run a period of time after a large number of close_wait, and then modify the default number of connections. After apache2.2 many functions are extracted to be stored separately, in the http.conf for reference. Storage connection number and other related instructions of the file is Httpd-mpm.conf,apache using the Prefork mode to connect the number of control, Prefork module format is as follows:
<ifmodule mpm_prefork_module>
Startservers 5
Minspareservers 5
Maxspareservers 10
MaxClients 150
Maxrequestsperchild 0<ifmodule>
its working principle is as follows:
After initially establishing the Startservers subprocess, the control process creates a process to meet the needs of the minspareservers settings, waits a second, continues to create a second, waits a second, and then creates four, which increases the number of processes created, up to 32 per second, at the point of magnitude. Until the value of the Minspareservers setting is met, which is the origin of the pre-derivation (prefork). This pattern can reduce system overhead to increase performance by eliminating the need to generate new processes when requests arrive.
Maxspareservers sets the maximum number of idle processes, and if the number of idle processes is greater than this value, Apache automatically kill some redundant processes. This value is generally not set too large, but if the set is smaller than Minspareservers, Apache will automatically adjust it to minspareservers+1. If the site load is large, you can consider increasing minspareservers and maxspareservers at the same time.
Maxrequestsperchild sets the number of requests that each child process can handle. Each child process is automatically destroyed after processing the maxrequestsperchild request. 0 means infinite, that is, the child process never destroys. Although the default setting of 0 allows each subprocess to handle more requests, it has two important benefits if set to a value other than 0:
1. To prevent accidental memory leaks;
2. The number of child processes is reduced automatically when the server load drops.
Therefore, according to the server load to adjust this value, if not 0, I think about 10000 is more appropriate. In fact, this value does not affect Apache performance very much.
MaxClients is one of the most important of these directives, and it sets the request that Apache can handle at the same time, which is the most influential parameter to Apache performance. In my opinion, the default of 150 is far from enough, if the total number of requests has reached this value (available via ps–ef| grep httpd|wc–l to confirm), the following request is queued until a processed request has been completed. This is why there is still a lot of system resources left, and the main reason why HTTP access is slow. The system administrator can dynamically adjust this value based on the hardware configuration and load conditions, although the larger the value in theory, the more requests can be processed, but the default limit for Apache is no greater than 256. If you set this value to greater than 256, then Apache will not start. In fact, 256 is not enough for a site with a heavier load. In Apache1.3 this is a hard limit, if you want to increase this value, you must manually modify the source tree before configure Src/include/httpd.h, look for 256, you will find #define HARD_SERVER_LIMIT 256 this line, Change the 256 to the value you want to increase, such as 4000, and then recompile Apache. I think the Apache system administrator who has some experience with this method knows that, but I believe there are not too many people in Apache2.0 who know how to increase this value.
New Serverlimit instructions are added to the Apache2.0, making it possible to increase maxclients without recompiling Apache. The following is the author's prefork configuration section.
<ifmodule prefork.c>
Startservers 10
Minspareservers 10
Maxspareservers 15
Serverlimit 2000
MaxClients 1500
Maxrequestsperchild 10000
</IfModule>
The maximum value for Btw:serverlimit is 20000, which is sufficient for most sites, but if you must increase it, the value is in the SERVER/MPM/PREFORK/PREFORK.C under the source tree. Inside the
#define DEFAULT_SERVER_LIMIT 256
#define MAX_SERVER_LIMIT 20000
These two lines correspond to the maxclients and serverlimit limits. But I believe very few people can use the number of concurrent connections in 20000.
The above is from the Unix Chinese to the Prefork work mode can achieve the function description more detailed. I used to find that serverlimits and maxclients the order of the two parameters can not be reversed, otherwise, when the Apache will alarm. According to the Mr Zhou classmate's reminding, all has the dependence relations the command, the writing should have the order.
At the same time, in the process of searching the data, pick a command:
Netstat-n | awk '/^tcp/{++s[$NF]} end {[markup error: for] print a, s[a]} '
This statement returns the following results
Last_ack 5
SYN_RECV 30
Established 1597
Fin_wait1 51
Fin_wait2 504
Time_wait 1057
The SYN_RECV represents the number of requests waiting to be processed, established represents the normal data transfer status, and Time_wait represents the number of requests that have been processed and waiting for the timeout to end.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.