Configure the maximum number of Apache connections in Linux

Source: Internet
Author: User
Recently, some bloggers found that my blog often uses http503, which is not very load-intensive and should not cause load problems. it is likely that this is the cause of the maximum number of connections to Apache,

Recently, some bloggers found that my blog often has http 503, but the blog has little load and there should be no load problems. it is likely that this is the cause of the maximum number of connections to Apache. Apache supports 150 connections by default.
1. modify the maximum number of connections first. you must understand Apache's MPM (Multi-Processing Modules, Multi-channel Processing module)
In Apache2.0, MPM is divided into three types: worker K, worker, and event ). The worker k is inherited from Apache1.3. it adopts the process management method, so it can provide more reliable performance and better compatibility. worker is the newly added method of Apache2.0, it adopts the thread control method, which can reduce the system overhead and process more data than the worker K, but the compatibility is not very good at the same time, and many old programs cannot work under the worker; the event is still in the test phase, and it assigns a different process pool to each task.
View method: use http-l to view the MPM used by your apache

We can see that my apache adopts the prefork working method.
2. configure prefork parameters
The default parameters are as follows:

StartServers 8
MinSpareServers 5
MaxSpareServers 20
MaxClients 150
MaxRequestsPerChild 1000

When Apache is started, Apache automatically creates StartServers processes and tries its best to keep the number of idle processes between MinSpareServers and MaxSpareServers.
If the number of idle processes is less than MinSpareServers, Apache creates a process at an interval of about one second.
If the number of idle processes is smaller than that of MaxSpareServers, Apache deletes redundant idle processes and releases server resources.
The maximum number of processes is controlled by MaxClients. in Apache1.3, the maximum number can only be set to 256. However, in Apache2.0, you can increase the ServerLimit project at the beginning of the configuration to exceed the 256 limit, maxClients ≤ ServerLimit ≤ 20000
MaxRequestsPerChild is used to control the number of requests processed by each process that are automatically destroyed. this parameter can be set to 0 to indicate that the process is infinite (that is, the process is not destroyed ).
My personal configuration is as follows:

StartServers 10
MinSpareServers 10
MaxSpareServers 15
ServerLimit 4000
MaxClients 2056
MaxRequestsPerChild 10000

It takes effect after Apache is restarted.
3. about apache Max connections settings
You can view the current number of connections:
Ps aux | grep httpd | wc-l

Or:
Pgrep httpd | wc-l

Calculate the average memory usage of httpd:
Ps aux | grep-v grep | awk '/httpd/{sum + = $6; n ++}; END {print sum/n }'

For static pages, CPU consumption is very low, and the memory occupied by each process is not much, about 200 KB.

If the server memory is 2 GB, 500 MB (conservatively estimated) is required except for services started normally, and 1.5 GB is available, 1024*1024*1024/200000*8053.06368 = is supported theoretically.

There are about 8 K processes, and it should be no problem to support 2 W simultaneous access (8 k of them can be accessed quickly, and other processes may need to wait 1 or 2 seconds to connect, and it will be smooth once connected)

Related Article

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.