The maximum number of Apache connections configured under Linux

Source: Internet
Author: User

recently bo friends found my blog often http 503, blog load is not a load problem, it is likely that the maximum number of Apache connections, Apache default support 150 connections.
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: byHttp-l View the MPM used by your Apache

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 a Serverlimit project at the beginning of the configuration, at which point you mustmaxclients≤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

Startservers sets the number of child processes established when the server starts
Minspareservers and Maxspareservers set the minimum and maximum number of idle child processes, respectively

serverlimit is the maximum value that can be used to control the maxclients. Reducing maxclients can make a big difference to the server that runs dynamic content (for example, WordPress). If your VPS encounters a significant increase in traffic and your maxclients is set too high, your server will work indefinitely to swap pages from physical memory to virtual memory, resulting in downtime. The general calculation of the appropriate MaxClients value depends on the total amount of system memory available to you, in addition to the memory used by each Apache process. For example, if you have 500MB of memory available for Apache, and each Apache process uses approximately 20MB of memory, you can set your maxclients to (512-12)/10 = 50 (this calculation seems to be incorrect in the original). Use the command top to get your VPS real-time memory usage.

Maxrequestsperchild This instruction sets the number of requests that a separate subprocess will be able to process. After processing the "Maxrequestsperchild number" request, the child process will be terminated by the parent process, the memory of the child process will be freed, and if there is another access request, the parent process will re-generate the child process to process. If the Maxrequestsperchild preset is 0 (infinity) or a larger number (for example, more than 10000), you can make each subprocess handle more requests, not because the child process is constantly terminating, and the sub-processes start to reduce access efficiency, but Maxrequestsperchild is set to 0 o'clock, If the 200~300m memory is occupied, it will not reduce the amount of memory that is occupied by the load. Servers with large memory can be set to 0 or larger numbers. Servers with smaller memory may wish to be set to 50, 100, 200 to prevent memory overflow.


This article is from the "Dream to Reality" blog, please be sure to keep this source http://lookingdream.blog.51cto.com/5177800/1878963

The maximum number of Apache connections configured under Linux

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.