Apacheの同時接続の最大数を増やすにはどうすればよいですか?


102

Apacheの同時接続の最大数を増やすには、どのhttpd conf設定を変更する必要がありますか?注:これは主に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>

回答:


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が起動されると、StartServersパラメータによって決定される2つの子プロセスが起動されます。次に、各プロセスはThreadsPerChildパラメーターで決定された25のスレッドを開始するため、2つのプロセスは50の同時接続/クライアント(つまり、25x2 = 50)のみを処理できます。さらに多くの同時ユーザーが来ると、別の子プロセスが開始され、さらに25人のユーザーにサービスを提供できます。ただし、開始できる子プロセスの数はServerLimitパラメーターによって制御されます。つまり、上記の構成では、合計16の子プロセスを作成でき、各子プロセスは25スレッドを処理でき、合計で16x25 = 400の同時ユーザーを処理できます。しかし、MaxClientsここで定義された数が200未満である場合、これは、8つの子プロセスの後、上限のキャップを定義しているため、追加のプロセスが開始されないことを意味しますMaxClients。これはまたMaxClients、1000 に設定した場合、16の子プロセスと400の接続の後、追加のプロセスは開始されず、MaxClientパラメーターを増やしても400を超える同時クライアントにサービスを提供できないことを意味します。この場合、 1000/25に増やす必要もありServerLimitます。つまり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

1
わかりましたが、この最適な構成に必要なメモリとCPU要件は何ですか。または、この最適化のためにCPUとメモリをどのように考慮するか。
indianwebdevil

私はこの構成を適用しましたが、それでも現在の接続に達しています...どこかでハードリミットのようです
ホルヘコルネホベリド

弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.