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

我需要改变什么httpd conf设置来增加Apache的最大并发连接数? 注:我closures了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> 

以下是有关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参数决定的subprocess。 那么每个进程将启动由ThreadsPerChild参数确定的25个线程,所以这意味着2个进程只能服务50个并发连接/客户端,即25×2 = 50。 现在,如果有更多的并发用户来到,那么另一个subprocess将启动,可以为另外25个用户提供服务。 但是可以启动多less个subprocess由ServerLimit参数控制,这意味着在上面的configuration中,我总共可以有16个subprocess,每个subprocess可以处理25个线程,总共处理16×25 = 400个并发用户。 但是,如果在MaxClients定义的数字less于200,那么这意味着在8个subprocess之后,由于我们已经定义了MaxClients的上限,所以不会有额外的进程启动。 这也意味着,如果我将MaxClients设置为1000,在16个subprocess和400个连接之后,即使增加了MaxClient参数,也不会启动额外的进程,也不能为超过400个并发客户端提供服务。 在这种情况下,我们还需要增加ServerLimit到1000/25,即MaxClients/ThreadsPerChild=40所以这是服务器1000客户端的优化configuration

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

更改MaxClients指令。 现在是256。