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

如何增加Apache中并发连接的最大数量?,apache,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 ma

我需要更改哪些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>
#
#KeepAlive:是否允许持久连接(超过
#每个连接一个请求)。设置为“关闭”以停用。
#
拒之门外
#
#MaxKeepAliverRequests:允许的最大请求数
#在持久连接期间。设置为0以允许无限量。
#我们建议您将此数字保持在较高水平,以获得最佳性能。
#
MaxKeepAliveRequests 100
#
#KeepAliveTimeout:等待来自的下一个请求的秒数
#同一连接上的同一客户端。
#
暂停15分钟
##
##服务器池大小调节(特定于MPM)
## 
#预工作MPM
#StartServers:要启动的服务器进程数
#MinSpareServers:保留备用的最小服务器进程数
#MaxSpareServers:保留备用的最大服务器进程数
#ServerLimit:服务器生存期内MaxClient的最大值
#MaxClient:允许启动的最大服务器进程数
#MaxRequestsPerChild:服务器进程服务的最大请求数
StartServers 8
MinSpareServers 5
MaxSpareServers 20
服务器限制256
MaxClients 256
MaxRequestsPerChild 4000
#工人MPM
#StartServers:要启动的服务器进程的初始数目
#MaxClients:同时进行的客户端连接的最大数量
#MinSpareThreads:保留备用的最小工作线程数
#MaxSpareThreads:保留备用的最大工作线程数
#ThreadsParchild:每个服务器进程中工作线程的固定数量
#MaxRequestsPerChild:服务器进程服务的最大请求数
StartServers 2
MaxClients 150
Minspare25
MaxSpareThreads 75
螺纹预裂25
MaxRequestsPerChild 0

更改MaxClient指令。现在是256页。

下面是有关MaxClient和MaxRequestsParchild计算的详细说明

首先,每当启动apache时,它都会启动两个子进程,这是由
StartServers
参数确定的。然后,每个进程将启动由
threadsParchild
参数确定的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>

服务器限制40
StartServers 2
MaxClients 1000
Minspare25
MaxSpareThreads 75
螺纹预裂25
MaxRequestsPerChild 0

以下是文档:2.3.13版之后似乎有一些变化。例如,MaxClients现在是MaxRequestWorkers。请注意:链接的站点当前正在提供恶意软件(和色情)。。。它可能被黑客入侵了。。。如果你正在stackoverflow上寻找解决方案,并且打开了一个全面的色情网站,那就相当令人担忧了。。。好的,但是这个最佳配置需要多少内存和CPU。或者我该如何考虑CPU和内存来进行优化。我应用了此配置,但仍然达到了当前连接…在其他地方似乎是一个硬限制。此链接可能有助于设置指令以获得可接受的结果。不过,我自己仍在从这篇文章中学习。
<IfModule mpm_worker_module>
    ServerLimit          40
    StartServers          2
    MaxClients          1000
    MinSpareThreads      25
    MaxSpareThreads      75 
    ThreadsPerChild      25
    MaxRequestsPerChild   0
</IfModule>