Understanding and tuning of concurrency control parameter prefork in Apache

Time:2022-1-8

The concurrency of Apache under Linux is not very high. It is about 3K. Ordinary servers will have problems to varying degrees Apache concurrency control is mainly controlled by prefork and worker We can use httpd – L to determine that the MPM currently used is prefork c. Or worker c. The following is the configuration of prefork in Apache Here are my optimized parameters
<IfModule prefork.c>
#With this parameter, you don’t have to modify the source code like apache1 to modify the limit of 256 customers. It will take effect only if you put it at the front. 2000 is the maximum value of this parameter
ServerLimit 2000
#Specifies the number of child processes established when the server starts. Prefork defaults to 5.
StartServers 25
#Specifies the minimum number of idle child processes. The default is 5. If the current number of free child processes is less than minspareservers, Apache will generate new child processes at a maximum rate of one per second. This parameter should not be set too large.
MinSpareServers 25
#Set the maximum number of idle child processes. The default is 10. If there are more free child processes than maxspareservers, the parent process will kill the redundant child processes. This parameter should not be set too large. If you set the value of this instruction to be smaller than minspareservers, Apache will automatically change it to “minspareservers + 1”.
MaxSpareServers 50
#Limit the maximum number of client access requests (concurrent threads of a single process) at the same time. The default is 256. Any request exceeding the maxclients limit will enter the waiting queue. Once a link is released, the requests in the queue will be serviced. To increase this value, you must also increase serverlimit.
MaxClients 2000
#The maximum number of servo requests allowed for each child process in its lifetime. The default is 10000 When the limit of maxrequestsperchild is reached, the child 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 benefits:
1. It can prevent (accidental) memory leakage from going on indefinitely, thus exhausting memory.
2. Give the process a limited lifetime, which helps to reduce the number of active processes when the server load is reduced.
operation mode:
A separate control process (parent process) is responsible for generating child processes, which are used to listen for requests and respond. Apache always tries to keep some spare or idle subprocesses ready for upcoming requests. In this way, the client does not need to wait for the generation of child processes before getting the service. In UNIX systems, the parent process usually runs as root to bind port 80, while the child process generated by Apache usually runs as a low privileged user. The user and group directives are used to set the low privileged users of child processes. The user running the sub process must have read permission on the content it serves, but must have as few permissions as possible on other resources other than the service content.
When tuning, we often need to check the number of httpd processes (that is, the number of concurrent requests that Apache can handle in prefork mode):
#ps -ef | grep httpd | wc -l
The result is the number of concurrent requests that Apache can handle. This value is automatically adjusted by Apache according to the load
To view the number of concurrent requests from Apache and its TCP connection status:
#netstat -n | awk ‘/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}’
I’m a friend of sina, Zhang Yan
Examples of returned results:
LAST_ACK 5
SYN_RECV 30
ESTABLISHED 1597
FIN_WAIT1 51
FIN_WAIT2 504
TIME_WAIT 1057
Where syn_ Recv indicates the number of requests waiting to be processed; Established indicates normal data transmission status; TIME_ Wait indicates the number of requests processed and waiting for the timeout to end.
Status: description
Closed: no connection is active or in progress
Listen: the server is waiting for an 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’s finished
FIN_ Wait2: the other side has agreed to release
ITMED_ Wait: wait for all packets to die
Closing: both sides try to close at the same time
TIME_ Wait: the other side has initiated a release
LAST_ ACK: wait for all packets to die
You can use WEBENCH under Linux for stress testing

Recommended Today

Proper memory alignment in go language

problem type Part1 struct { a bool b int32 c int8 d int64 e byte } Before we start, I want you to calculatePart1What is the total occupancy size? func main() { fmt.Printf(“bool size: %d\n”, unsafe.Sizeof(bool(true))) fmt.Printf(“int32 size: %d\n”, unsafe.Sizeof(int32(0))) fmt.Printf(“int8 size: %d\n”, unsafe.Sizeof(int8(0))) fmt.Printf(“int64 size: %d\n”, unsafe.Sizeof(int64(0))) fmt.Printf(“byte size: %d\n”, unsafe.Sizeof(byte(0))) fmt.Printf(“string size: %d\n”, […]