Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure the concurrency control parameter prefork in apache

2025-01-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "how to configure the concurrency control parameter prefork in apache". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

An apache has concurrency under linux is not very high, about 3K, ordinary servers will have varying degrees of problems. Apache concurrency control is mainly controlled by one of prefork and worker. We can use httpd-l to determine whether the MPM currently in use is prefork.c or Worker.c. The following is the configuration of prefork in apache. Here are the parameters I have optimized.

# if you have this parameter, you don't have to modify the source code like apache1 to modify the limit on the number of 256customers. It will not take effect until you put it at the front. 2000 is the maximum value of this parameter.

ServerLimit 2000

# specify 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 idle child processes is less than MinSpareServers, then Apache will generate new child processes at a maximum rate of one per second. Do not set this parameter too large.

MinSpareServers 25

# set the maximum number of idle child processes. Default is 10. If there are currently more free child processes than MaxSpareServers, the parent process will kill the extra child processes. This parameter should not be set too large. If you set the value of the instruction to be less than MinSpareServers, Apache will automatically change it to "MinSpareServers+1".

MaxSpareServers 50

# limit the maximum number of client access requests at a time (the number of concurrent threads in a single process). The default is 256. Any request that exceeds the MaxClients limit will enter the waiting queue, and once a link is released, the request in the queue will be served. To increase this value, you must also increase ServerLimit.

MaxClients 2000

# the maximum number of requests allowed for servo per child process during its lifetime, 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

Setting MaxRequestsPerChild to a non-zero value has two benefits:

1. It can prevent (accidental) memory leaks from going on indefinitely, thus running out of memory.

two。 Give processes a limited lifespan, which helps to reduce the number of active processes when the server load is reduced.

Mode of work:

A separate control process (parent) is responsible for generating child processes that are used to listen to requests and respond. Apache always tries to keep some spare or idle child processes for upcoming requests. In this way, the client does not have to wait for the child process to be generated before it is served. In Unix systems, the parent process usually runs as root to secure 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 low-privileged users of child processes. The user running the child process must have read access to the content it serves, but must have as few permissions as possible to resources other than the service content.

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 how many concurrent requests the current Apache can handle. This value Apache is automatically adjusted according to the load.

Check the number of concurrent requests for Apache and their TCP connection status:

# netstat-n | awk'/ ^ tcp/ {+ + S [$NF]} END {for (an in S) print a, S [a]}'

The above sentence comes to a banquet for a friend of mine on Sina.

Example of the returned result:

LAST_ACK 5

SYN_RECV 30

ESTABLISHED 1597

FIN_WAIT1 51

FIN_WAIT2 504

TIME_WAIT 1057

Where SYN_RECV represents the number of requests waiting to be processed; ESTABLISHED represents the normal data transfer status; and TIME_WAIT indicates the number of requests that have been processed and waiting for the timeout to end.

Status: description

CLOSED: connectionless 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 transfer statu

FIN_WAIT1: the application says it's done.

FIN_WAIT2: the other side has agreed to release

ITMED_WAIT: wait for all groups to die

CLOSING: both sides try to shut down at the same time

TIME_WAIT: the other side has initialized a release

LAST_ACK: wait for all groups to die

You can use webbench under Linux for stress testing.

This is the end of "how to configure the concurrency control parameter prefork in apache". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report