さくらVPSのメモリ2GBのやつで運用しているが,ApacheからNginx+php-fpmに変えた時にメモリがあふれたのでメモ.OSはCentOS 6.5.
サーバの応答がやたら遅くなったのでおかしいと思ってメモリ使用量をチェックしたら,php-fpmのプロセスが多数起動していた.
起動するプロセス数の上限がデフォルト値になっていたのが原因.こちらのページを参考に/etc/php-fpm.d/www.conf を編集した.
(リンク先のページはレイアウトが崩れていてよくわからなかったが…)
sudo vi /etc/php-fpm.d/www.conf
以下の部分が,とくに修正をする点.同時に起動する子プロセスの数などを決める.たぶん以下の設定はかなり小さい構成になってると思う.
pm = dynamic ; The number of child processes to be created when pm is set to 'static' and the ; maximum number of child processes to be created when pm is set to 'dynamic'. ; 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. ; Note: Used when pm is set to either 'static' or 'dynamic' ; Note: This value is mandatory. pm.max_children = 5 ; 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 = 4 ; 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 = 3 ; 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 = 5 - ; 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 = 10