In an Apache system, the concurrency in Linux is not very high, and it looks like 3 K (in fact, the HTTP request may only be 300/s). Common servers may encounter problems to varying degrees. the concurrency control of Apache is mainly controlled by one of prefork and worker. we can use httpd-L to determine whether the currently used MPM is prefork. c, or worker. c. the following describes the prefork configuration in Apache. the following are my optimized parameters.
<Ifmodule prefork. c>
# With this parameter, you do not need to modify the source code like apache1 to modify the limit of 256 customers. It takes effect only when you put the lecture at the beginning. 2000 is the maximum value of this parameter.
Serverlimit 2000
# Specify the number of sub-processes created when the server starts. The default value of prefork is 5.
Startservers 25
# Specify the minimum number of idle sub-processes. The default value is 5. If the number of idle sub-processes is less than minspareservers, Apache will generate a new sub-process at a maximum speed per second. Do not set this parameter too large.
Minspareservers 25
# Set the maximum number of idle sub-processes. The default value is 10. If there are idle sub-processes that exceed the number of maxspareservers, the parent process will kill the redundant sub-processes. Do not set this parameter too large. If you set the value of this command to a smaller value than minspareservers, Apache will automatically change it to "minspareservers + 1 ".
Maxspareservers 50
# Limit the maximum number of client access requests (number of concurrent threads in a single process) at the same time. The default value is 256. Any request that exceeds the limit of maxclients will enter the waiting queue. Once a link is released, the request in the queue will be served. To increase this value, you must increase serverlimit at the same time.
Maxclients 2000
# Each sub-process allows the maximum number of requests of the servo within its lifetime. The default value is 10000. When the limit of maxrequestsperchild is reached, the sub-process will end. If maxrequestsperchild is "0", the child process will never end.
Maxrequestsperchild 10000
</Ifmodule>
Setting maxrequestsperchild to a non-zero value has two advantages:
1. It can prevent (accidental) infinite Memory leakage and thus exhaust the memory.
2. A limited life cycle is provided for processes, which helps reduce the number of active processes when server load is reduced.
Working Method:
A separate control process (parent process) is responsible for generating child processes that are used to listen for requests and respond. Apache always tries to keep some standby (spare) or idle sub-processes to meet the upcoming requests. In this way, the client does not need to wait for the sub-process to generate before obtaining the service. In Unix systems, the parent process is usually run as the root to fix port 80, while the sub-process generated by Apache is usually run as a low-privilege user. The user and group commands are used to set low-privilege users for sub-processes. Users running a sub-process must have the read permission on the Content served by the sub-process, but must have as few permissions as possible for resources other than the service content.
For some of the above values, you must note that the bigger the value, the better. This requires several attempts and errors before you can select the value to be used (different hardware processing levels ). The most important value is that maxclient allows enough working processes without causing excessive server exchanges (CRASHES ). If the incoming request exceeds the processing capacity and the server crashes, the requests that meet this value at least will receive services, and other requests will be blocked.
We often need to check the number of httpd processes for optimization (that is, the number of concurrent requests that Apache can process in prefork Mode):
# Ps-Ef | grep httpd | WC-l
The result is the number of concurrent requests that Apache can process. This value is automatically adjusted by Apache based on the load.
View the number of concurrent Apache requests and their TCP connection status:
# Netstat-N | awk '/^ TCP/{++ s [$ NF]} end {for (a in S) print a, s [a]}'
In the above sentence, I am a friend of Sina, Zhang banquet.
Sample returned results:
Last_ack 5
Syn_recv 30
Established 1597
Fin_wait1 51
Fin_wait2 504
Time_wait 1057
Syn_recv indicates the number of requests waiting for processing, established indicates the normal data transmission status, and time_wait indicates the number of requests waiting for timeout.
Status: Description
Closed: No connection is active or in progress
Listen: the server is waiting for incoming call
Syn_recv: a connection request has arrived, waiting for confirmation
Syn_sent: The application has started. Open a connection.
Established: normal data transmission status
Fin_wait1: The application says it has been completed
Fin_wait2: the other side has agreed to release
Itmed_wait: wait until all groups die
Closing: both sides attempt to close at the same time
Time_wait: the other side has initialized a release.
Last_ack: waiting for all groups to die
You can use webshells in Linux for stress testing.