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

时间:2010-08-02 16:02:53

标签: apache

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

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

2 个答案:

答案 0 :(得分:160)

以下是有关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个并发客户端提供服务。在这种情况下,我们还需要将ServerLimit增加到1000/25,即MaxClients/ThreadsPerChild=40 所以这是服务器1000客户端的优化配置

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

答案 1 :(得分:6)

更改MaxClients指令。它现在是256。

相关问题