问题描述
我需要更改哪些 httpd conf 设置来增加 Apache 的最大并发连接数?注意:我关闭了 KeepAlive,因为它主要是一个 API 服务器.
## KeepAlive:是否允许持久连接(超过# 每个连接一个请求).设置为关闭"以停用.#保持活动关闭## MaxKeepAliveRequests:允许的最大请求数# 在持久连接期间.设置为 0 以允许无限量.# 我们建议您将此数字设置为高值,以获得最佳性能.#MaxKeepAliveRequests 100## KeepAliveTimeout:等待下一个请求的秒数# 同一个连接上的同一个客户端.#保持活动超时 15#### 服务器池大小规定(特定于 MPM)### 预分叉 MPM# StartServers:要启动的服务器进程数# MinSpareServers:保持备用的最小服务器进程数# MaxSpareServers:保持备用的服务器进程的最大数量# ServerLimit:服务器生命周期内 MaxClients 的最大值# MaxClients:允许启动的最大服务器进程数# MaxRequestsPerChild:服务器进程服务的最大请求数<IfModule prefork.c>启动服务器 8最小备用服务器 5最大备用服务器 20服务器限制 256第 256 章MaxRequestsPerChild 4000</IfModule># 工人 MPM# StartServers:要启动的服务器进程的初始数量# MaxClients:最大并发客户端连接数# MinSpareThreads:保持空闲的最小工作线程数# MaxSpareThreads:保持空闲的最大工作线程数# ThreadsPerChild:每个服务器进程中的固定工作线程数# MaxRequestsPerChild:服务器进程服务的最大请求数<IfModule worker.c>启动服务器 2最大客户 150最小备用线程 25最大备用线程数 75ThreadsPerChild 25MaxRequestsPerChild 0</IfModule>这里详细解释MaxClients和MaxRequestsPerChild的计算
ServerLimit 16启动服务器 2最大客户 200最小备用线程 25最大备用线程数 75ThreadsPerChild 25
首先,每当一个 apache 启动时,它会启动 2 个由 StartServers
参数决定的子进程.然后每个进程将启动由 ThreadsPerChild
参数确定的 25 个线程,因此这意味着 2 个进程只能服务 50 个并发连接/客户端,即 25x2=50.现在,如果有更多的并发用户到来,那么另一个子进程将启动,可以为另外 25 个用户提供服务.但是可以启动多少个子进程是由ServerLimit
参数控制的,也就是说在上面的配置中,我总共可以有16个子进程,每个子进程可以处理25个线程,总共处理16x25=400 个并发用户.但是如果 MaxClients
中定义的数字小于这里的 200,那么这意味着在 8 个子进程之后,由于我们定义了 MaxClients
的上限,因此不会启动额外的进程.这也意味着,如果我将 MaxClients
设置为 1000,在 16 个子进程和 400 个连接之后,将不会启动额外的进程,即使我们增加了 MaxClient,我们也无法服务超过 400 个并发客户端
参数.在这种情况下,我们还需要将 ServerLimit
增加到 1000/25,即 MaxClients/ThreadsPerChild=40
所以这是服务器 1000 个客户端的优化配置
服务器限制 40启动服务器 2最大客户 1000最小备用线程 25最大备用线程数 75ThreadsPerChild 25MaxRequestsPerChild 0</IfModule>
What httpd conf settings do I need to change to increase the max number of concurrent connections for Apache? NOTE: I turned off KeepAlive since this is mainly an API server.
#
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
#
KeepAlive Off
#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 100
#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 15
##
## Server-Pool Size Regulation (MPM specific)
##
# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# ServerLimit: maximum value for MaxClients for the lifetime of the server
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule prefork.c>
StartServers 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 4000
</IfModule>
# worker MPM
# StartServers: initial number of server processes to start
# MaxClients: maximum number of simultaneous client connections
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule worker.c>
StartServers 2
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>
Here's a detailed explanation about the calculation of MaxClients and MaxRequestsPerChild
ServerLimit 16
StartServers 2
MaxClients 200
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
First of all, whenever an apache is started, it will start 2 child processes which is determined by StartServers
parameter. Then each process will start 25 threads determined by ThreadsPerChild
parameter so this means 2 process can service only 50 concurrent connections/clients i.e. 25x2=50. Now if more concurrent users comes, then another child process will start, that can service another 25 users. But how many child processes can be started is controlled by ServerLimit
parameter, this means that in the configuration above, I can have 16 child processes in total, with each child process can handle 25 thread, in total handling 16x25=400 concurrent users. But if number defined in MaxClients
is less which is 200 here, then this means that after 8 child processes, no extra process will start since we have defined an upper cap of MaxClients
. This also means that if I set MaxClients
to 1000, after 16 child processes and 400 connections, no extra process will start and we cannot service more than 400 concurrent clients even if we have increase the MaxClient
parameter. In this case, we need to also increase ServerLimit
to 1000/25 i.e. MaxClients/ThreadsPerChild=40
So this is the optmized configuration to server 1000 clients
<IfModule mpm_worker_module>
ServerLimit 40
StartServers 2
MaxClients 1000
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>
这篇关于你如何增加Apache中的最大并发连接数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!