Optimize the prefork mode in apache

Source: Internet
Author: User

(1) In prefork mode (not applicable in other modes ),ApacheMain parameters to be optimized:
ServerLimit 3000
Start servers 750
MinSpareServers 5
MaxSpareServers 100
MaxClients 3000
MaxRequestsPerChild 10000
First, let's take a look at the meaning of each apache parameter (quotes reference the description in the official documentation ):
(1) the maximum number of simultaneous response requests of ServerLimit and MaxClients servers
This is the maximum number of concurrent responses to apache that you have configured. It corresponds to the number of apache processes. The two parameters are modified at the same time. MaxClients must not be greater than the ServerLimit parameter.
The size of ServerLimit depends on the resources of your system. By default, each apache process occupies 2 MB of memory. You can use this formula to calculate the maximum memory size: * 80%/2 M = ServerLimit.
(2) number of processes started by default when StartServers 750 is started
The default value of this parameter is 5, because apache will automatically start a new process to increase the number of processes responding to the service. This value is fine without being adjusted, the number of processes that meet the service is increased from 5 by default, but the system will be stuck at startup.
One advantage of a small startup parameter is that it increases the stress of backend tomcat after passing, rather than increasing the pressure at once. You can adjust this to the maximum number of concurrent connections of the current service, which can be obtained by monitoring the number of apache processes: ps-ef | grep httpd | wc-l. You do not need to tune it too much. Otherwise, it is unnecessary to add a connection between apache and tomcat through jk.
Note:ApacheAfter the process establishes a connection with tomcat, the connection will not be released and will remain connected until timeout. If there is no timeout time, the connection will be established permanently. Timeout settings are described in later jk configurations.
So do not start too many apache processes at a time, just start enough processes. For other traffic increases, apache automatically adjusts the number of processes until the range specified by the MaxClients parameter.
(3) MinSpareServers 5 minimum idle Process
The MinSpareServers command sets the minimum number of idle sub-processes. Idle sub-processes are sub-processes that are not processing requests. If the number of idle sub-processes is less than MinSpareServers, Apache will generate a new sub-process at an exponential increase of one second, two second, and four third second.
(4) MaxSpareServers 10 maximum idle Processes
The MaxSpareServers command sets the maximum number of idle sub-processes. Idle sub-processes are sub-processes that are not processing requests. If there are idle sub-processes that exceed the number of MaxSpareServers, the parent process will kill the redundant sub-processes.
You can adjust these two parameters, but the values of these two parameters cannot be too large. Otherwise, too many apache processes will lead to many tomcat processes.
On the official website, there is a saying about these two parameters: "setting this parameter too large is usually a bad idea ."
MaxSpareServers is set to 2800 on a high-stress (concurrent access 200) server.
The advantage of setting this value is that there will not be too many idle processes consuming resources while reducing the connection ports between apache and tomcat.
When idle apache processes are disabled, jk connections are released and tomcat connections are released to reduce system resource consumption.
(5) MaxRequestsPerChild 10000
"MaxRequestsPerChild command sets the maximum number of requests allowed by the servo for each sub-process during its lifetime. When the limit of MaxRequestsPerChild is reached, the sub-process will end. If MaxRequestsPerChild is "0", the child process will never end.
Setting MaxRequestsPerChild to a non-zero value has two advantages:
* It can prevent (accidental) unlimited memory leakage and thus exhaust the memory.
* A limited life cycle is provided for processes, which helps reduce the number of active processes when server load is reduced.
Note:
For KeepAlive links, only the first request is counted. In fact, it changes the behavior of each sub-process to limit the maximum number of links. "
That is to say, the maximum number of connections of sub-processes is equal to MaxRequestsPerChild * MaxKeepAliveRequests.
Therefore, after enabling KeepAlive, you need to set MaxRequestsPerChild and MaxRequestsPerChild at the same time to ensure that each apache process is closed after a certain number of requests are served and restart the new sub-process, avoid Memory leakage and resource usage caused by apache process exceptions.
(6) Keep-Alive
Default: ON
Only one request is sent in MaxRequestsPerChild, regardless of the number of requests sent by the connection.
(7) MaxKeepAliveRequests
Default Value: 100
"A established Keep-Alive connection allows the number of requests sent. Once a connection is established, either the number reaches the disconnected level or the KeepAliveTimeout time reaches the disconnected level.
The MaxKeepAliveRequests command limits the number of requests allowed by each connection when KeepAlive is enabled. If you set this value to "0", the number of requests is not limited. We recommend that you set this value to a relatively large value to ensure optimal server performance. "
To set this number, you must consider the number of requests sent by the same user to access your service within a period of time. It should be considered in combination with the KeepAliveTimeout parameter.
For example, if the user needs to request 10 files consecutively at intervals not greater than the KeepAliveTimeout time, this parameter should be set to 10. If the user continuously requests access for a continuous period of time, the value must be set to more. Otherwise, the connection will be re-established for download. Once the user has made 10 consecutive requests, and this user will certainly not request again within 5 seconds after completing these requests, even after a long time, therefore, the KeepAliveTimeout time can be set very short to disconnect such users as soon as possible and allow resources to be used by other users.
(8) KeepAliveTimeout
Default Value: 5
"In a established Keep-Alive connection, when the number of MaxKeepAliveRequests is not full, wait for the time of the next request. "
If a request arrives, apache waits for the timeout time of the IO response to take effect. If the timeout time does not wait for the response, the connection is disconnected. If no request arrives within the KeepAliveTimeout time, the connection is disconnected.
For specific settings, see use the MaxKeepAliveRequests parameter. At the same time, this parameter is also affected by the TimeOut parameter. In a successful connection, the connection will be closed if the response is not received within the TimeOut time.
(9) TimeOut
Default Value: 300
The TimeOut command is used to set the length of time for Apache to wait for the following three events:
1. The total time it takes to receive a GET request.
2. When a POST or PUT request is sent, the time between two TCP packets is accepted.
3. The time between two ACK packets in TCP packet transmission during response.
We plan to gradually make them easier to configure in the course of development. The default value of the timer before version 1.2 is 1200, but now it is set to 300, but it is still sufficient in most cases. The reason for not setting the default value smaller is that there is still a problem in the Code: Sometimes the timer is not reset after a packet is sent ."

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.