如何增加Apache中并发连接的最大数量?


102

我需要更改哪些httpd conf设置以增加Apache的最大并发连接数?注意:因为这主要是一个API服务器,所以我关闭了KeepAlive。

#
# 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>

Answers:


170

这是有关MaxClients和MaxRequestsPerChild的计算的详细说明

http://web.archive.org/web/20160415001028/http://www.genericarticles.com/mediawiki/index.php?title=How_to_optimize_apache_web_server_for_maximum_concurrent_connections_or_increase_max_clients_in_apache

ServerLimit 16
StartServers 2
MaxClients 200
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 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个以上的并发客户端提供服务。在这种情况下,我们还需要增加到ServerLimit1000/25,即MaxClients/ThreadsPerChild=40 ,这是服务器1000客户端的优化配置

<IfModule mpm_worker_module>
    ServerLimit          40
    StartServers          2
    MaxClients          1000
    MinSpareThreads      25
    MaxSpareThreads      75 
    ThreadsPerChild      25
    MaxRequestsPerChild   0
</IfModule>

24
版本2.3.13之后似乎有所更改。例如,MaxClients现在是MaxRequestWorkers。
ılǝ

2
请告知:链接的站点当前正在提供恶意软件(和色情内容)...它可能已被黑客入侵...如果您在工作中正在寻找关于stackoverflow的解决方案,并且打开了一个完整的色情网站,则非常烦恼
yoano '16

1
好的,但是此最佳配置需要多少内存和CPU要求。或者我如何同时考虑CPU和内存的优化。
indianwebdevil

我应用了此配置,但仍然达到了当前连接...似乎在其他地方达到了硬限制
Jorge Cornejo Bellido

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.