apache performance optimization

Collection from: http://sookk8.blog.51cto.com/455855/275759/

The configuration of Apache is configured for the original lower server, and the original configuration is obviously not suitable, so today I started to study the problem of Apache configuration.

1. First of all, we must understand the MPM (Multi-Processing Modules) adopted by
Apache. MPM is the core of Apache, and its role is to manage network connections and schedule requests.

MPM in Apache2.0 is divided into three types (perfork, worker, event). Perfork is inherited from Apache1.3, it adopts process management method, so it can provide more reliable performance and better compatibility; worker is a newly added method in Apache2.0, it adopts thread control method , which can save system overhead and process more data than perfork, but at the same time the compatibility is not very good, many old programs cannot work under workers; event is still in the experimental stage, it assigns different processes to each task pool, should not be used at this time.
The command httpd -l can be used to get which MPM is currently used
by Apache :


Server limit 256
StartServers 5
MinSpareServers 10
MaxSpareServers   15
MaxClients       256
MaxRequestsPerChild  4000

When Apache is started, Apache will automatically create StartServers processes, and try to keep the number of idle processes between MinSpareServers and MaxSpareServers.
If the idle processes are less than MinSpareServers, Apache will create new processes at a rate of about 1 per second.
If the idle process is less than MaxSpareServers, Apache will delete the redundant idle process and release server resources.
The maximum number of processes is controlled by MaxClients. In Apache1.3, the maximum can only be set to 256, but in Apache2.0, the limit of 256 can be broken by adding the ServerLimit item at the beginning of the configuration. At this time, MaxClients ≤ ServerLimit ≤ 20000
MaxRequestsPerChild is used to control how many requests each process is automatically destroyed after processing. This parameter can be set to 0 to indicate infinite (that is, no process is destroyed).

3. Optimize perfork
First of all, for a website with a relatively high load, the process limit of 256 is not enough. If the server has reached the limit of 256, then the next access needs to be queued, which is why some servers are loaded Not high, but one of the reasons why access is slow. So first you should understand the number of processes the server has when it is busy.
You can use the command ps -ef|grep httpd|wc -l to know the number of Apache processes in the current system. By setting ServerLimit and MaxClients, you can achieve the purpose of soft expansion of the server.

Then, during peak traffic times, it often happens that all of a sudden there are a lot of concurrent connections, and then all of a sudden there's a lot less access. If Apache does not prepare a sufficient number of preparatory processes, the access can only wait for Apache to add one new process per second, and then delete the redundant process, then Apache can only be busy creating and destroying processes all the time, which greatly reduces the access. speed. You can appropriately increase StartServers, MinSpareServers, MaxSpareServers so that Apache does not need to be busy doing useless work all the time.

Finally, it is strongly recommended that MaxRequestsPerChild not be set to 0, set to non-0, can protect the Apache process from memory leaks, because you do not know when the application running on Apache will fail and cause memory leaks.

After setting it is roughly like this:

Server limit 1000
StartServers 30
MinSpareServers 30
MaxSpareServers   45
MaxClients       1000
MaxRequestsPerChild  4000

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326940073&siteId=291194637