php5-fpm がすべてのコアを最大限に活用する (nginx+php5fpm+wordpress)

php5-fpm がすべてのコアを最大限に活用する (nginx+php5fpm+wordpress)

8 つの CPU コアで 16 GB の Linode を実行していますが、負荷テストを実行すると、かなり基本的な WordPress サイトで 1 秒あたり約 250 件のリクエストでサーバーが異常動作し始めるという問題をデバッグしようとしています。ちなみに、サイトのフロント ページのみにアクセスしています。

サーバーにログインして Htop でサーバーの統計情報を表示すると、すべてのコアが停止し、php5-fpm プロセスが大量に実行されていることがわかります。テストが完了した後もこれらのプロセスは存在し続け、サーバーを稼働状態に戻すには最終的に php-fpm を再起動する必要があります。

今日、負荷テストを実行したときにログでこれを確認しました。

[23-Dec-2013 12:19:03] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 0 idle, and 27 total children
[23-Dec-2013 12:19:04] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 16 children, there are 0 idle, and 35 total children
[23-Dec-2013 12:19:05] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 45 total children
[23-Dec-2013 12:19:06] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 55 total children
[23-Dec-2013 12:19:07] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 65 total children
[23-Dec-2013 12:19:08] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 75 total children
[23-Dec-2013 12:19:19] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 5 idle, and 93 total children

明らかに何かがおかしいのですが、私は現在のシステムでこれらの設定を微調整する専門家ではありません。

こちらがwww.confです

; Start a new pool named 'www'.
; the variable $pool can we used in any directive and will be replaced by the
; pool name ('www' here)
[www]

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
user = www-data
group = www-data

; The address on which to accept FastCGI requests.
; Valid syntaxes are:
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific address on
;                            a specific port;
;   'port'                 - to listen on a TCP socket to all addresses on a
;                            specific port;
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /var/run/php5-fpm.sock

; Set listen(2) backlog. A value of '-1' means unlimited.
; Default Value: 128 (-1 on FreeBSD and OpenBSD)
listen.backlog = 65536

pm = dynamic

; The number of child processes to be created when pm is set to 'static' and the
; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'.
; This value sets the limit on the number of simultaneous requests that will be
; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
; CGI. The below defaults are based on a server without much resources. Don't
; forget to tweak pm.* to fit your needs.
; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'
; Note: This value is mandatory.
pm.max_children = 150
; The number of child processes created on startup.
; Note: Used only when pm is set to 'dynamic'
; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
pm.start_servers = 20
; The desired minimum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.min_spare_servers = 10
; The desired maximum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.max_spare_servers = 35
; The number of seconds after which an idle process will be killed.
; Note: Used only when pm is set to 'ondemand'
; Default Value: 10s
;pm.process_idle_timeout = 10s;

; The number of requests each child process should execute before respawning.
; This can be useful to work around memory leaks in 3rd party libraries. For
; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS.
; Default Value: 0
pm.max_requests = 500

pm.status_path = /status-www

; The log file for slow requests
; Default Value: not set
; Note: slowlog is mandatory if request_slowlog_timeout is set
;slowlog = log/$pool.log.slow
slowlog = /var/log/php-fpm-slow.log

; The timeout for serving a single request after which a PHP backtrace will be
; dumped to the 'slowlog' file. A value of '0s' means 'off'.
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
; Default Value: 0
request_slowlog_timeout = 115s

; The timeout for serving a single request after which the worker process will
; be killed. This option should be used when the 'max_execution_time' ini option
; does not stop script execution for some reason. A value of '0' means 'off'.
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
; Default Value: 0
request_terminate_timeout = 120s

; Set open file descriptor rlimit.
; Default Value: system defined value
rlimit_files = 65536

; Set max core size rlimit.
; Possible Values: 'unlimited' or an integer greater or equal to 0
; Default Value: system defined value
rlimit_core = 0

www.conf に関して何かアドバイスや指摘すべき点はありますか?

答え1

まず、自分自身に次の質問をする必要があります。250 リクエスト/秒は、本当にサイトが処理できる量ですか? これは、ページに対して非常に多くのリクエストです。率直に言って、仮想化システムを使用していることを考えると、CPU が最大になる 250 リクエスト/秒は正常だと思います。

pm.max_children = 150

おそらく、子が最大数に達しているというエラーが引き続き表示されるため、この値を上げ続けているのでしょう。しかし、システムが処理できる範囲を超えてこの値を上げると、実際には自ら足を撃っていることになります。処理できない次のリクエストは、受け入れるよりも受け入れない方がよいでしょう。この値を増やすと、システムが薄くなるだけでなく、リソース要件とオーバーヘッドが増えます。そして、それがシステムが処理できないサイズに爆発すると、フリーズなどの兆候が現れます。VPS が正確に何を提供しているかはわかりません (ノード内の他のユーザーに依存するため静的ではないため、決してわかりません) が、個人的には、指定されたシステムで 20 を超える値は現実的な設定ではないと思います。

また、max を超える子を持つことは意味がないので、それに応じて start/min/max スペアも調整する必要があります。または、気にせずに に設定することもできますpm = static

答え2

プロセス管理をオンデマンドに変更

pm = ondemand

関連情報