Apache2.4系のMPM(マルチプロセッシングモジュール)はeventがデフォルトらしいのですが、今回Apache2.4.9をインストールする際、MPMはpreforkを指定してインストールしました。理由はPHPを使う場合、preforkが推奨という情報をインターネット上で見かけたので。
Apache2.4をソースからインストールする場合、httpd.conf以外のデフォルトの設定ファイルはextraディレクトリ配下に配置されています。
# ls -l /usr/local/httpd-2.4.9/conf/extra/ total 64 -rw-r--r--. 1 root root 2889 Jul 13 06:21 httpd-autoindex.conf -rw-r--r--. 1 root root 1837 Jul 13 06:21 httpd-dav.conf -rw-r--r--. 1 root root 2942 Jul 13 06:21 httpd-default.conf -rw-r--r--. 1 root root 1119 Jul 13 06:21 httpd-info.conf -rw-r--r--. 1 root root 5078 Jul 13 06:21 httpd-languages.conf -rw-r--r--. 1 root root 1033 Jul 13 06:21 httpd-manual.conf -rw-r--r--. 1 root root 4444 Jul 13 06:21 httpd-mpm.conf -rw-r--r--. 1 root root 2234 Jul 13 06:21 httpd-multilang-errordoc.conf -rw-r--r--. 1 root root 11525 Jul 13 06:21 httpd-ssl.conf -rw-r--r--. 1 root root 694 Jul 13 06:21 httpd-userdir.conf -rw-r--r--. 1 root root 1475 Jul 13 06:21 httpd-vhosts.conf -rw-r--r--. 1 root root 3161 Jul 13 06:21 proxy-html.conf
httpd.confでコメント(#)を外すことで有効になります。
# vi /usr/local/httpd-2.4.9/conf/httpd.conf (省略) # Supplemental configuration # # The configuration files in the conf/extra/ directory can be # included to add extra features or to modify the default configuration of # the server, or you may simply copy their contents here and change as # necessary. # Server-pool management (MPM specific) #Include conf/extra/httpd-mpm.conf # Multi-language error messages #Include conf/extra/httpd-multilang-errordoc.conf # Fancy directory listings #Include conf/extra/httpd-autoindex.conf # Language settings #Include conf/extra/httpd-languages.conf # User home directories #Include conf/extra/httpd-userdir.conf # Real-time info on requests and configuration #Include conf/extra/httpd-info.conf # Virtual hosts #Include conf/extra/httpd-vhosts.conf # Local access to the Apache HTTP Server Manual #Include conf/extra/httpd-manual.conf # Distributed authoring and versioning (WebDAV) #Include conf/extra/httpd-dav.conf # Various default settings #Include conf/extra/httpd-default.conf # Configure mod_proxy_html to understand HTML4/XHTML1 <IfModule proxy_html_module> Include conf/extra/proxy-html.conf </IfModule> # Secure (SSL/TLS) connections #Include conf/extra/httpd-ssl.conf
今回も必要な設定ファイルは別ディレクトリにコピーして使うことにします。
# cd /usr/local/httpd-2.4.9/ # cp conf/extra/httpd-mpm.conf conf.d/mpm.conf
上記のファイルを有効にするためhttpd.confで以下を追加します。
# vi /usr/local/httpd-2.4.9/conf/httpd.conf # 追加 Include conf.d/mpm.conf
preforkのデフォルトの設定を見てみます。
# vi conf.d/mpm.conf # 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 # MaxRequestWorkers: maximum number of server processes allowed to start # MaxConnectionsPerChild: maximum number of connections a server process serves # before terminating <IfModule mpm_prefork_module> StartServers 5 MinSpareServers 5 MaxSpareServers 10 MaxRequestWorkers 250 MaxConnectionsPerChild 0 </IfModule>
Apacheはマニュアルが充実しているので、一読をお勧めします。
http://httpd.apache.org/docs/current/ja/mod/prefork.html
http://httpd.apache.org/docs/2.2/ja/mod/mpm_common.html
preforkの特徴
- マルチプロセスで動作
- 子プロセスを複数起動してリクエストを同時処理
- 子プロセスの起動は時間がかかるため、子プロセスを常時起動しておきレスポンス悪化を防ぐ
preforkディレクティブ
待機プロセスが多過ぎたりするとリソースを無駄消費してしまうので、preforkディレクティブで調整することになりますが、始めはデフォルトで使い問題が発生したときに調整していけばいいのではないかと思います。以下のディレクティブはマニュアルからの引用です。
- StartServers
"起動時に生成される子サーバプロセスの数"(デフォルト:5)
- MinSpareServers
"アイドルな子サーバプロセスの最小個数"(デフォルト:5)
- MaxSpareServers
"アイドルな子サーバプロセスの最大個数"(デフォルト:10)
- MaxRequestWorkers ( 以前はMaxClients )
"リクエストに応答するために作成される 子プロセスの最大個数"(デフォルト:250)
- MaxConnectionsPerChild ( 以前はMaxRequestsPerChild )
"個々の子サーバが稼働中に扱うリクエスト数の上限"(デフォルト:0)
"MaxRequestsPerChild が 0 に設定されている場合は、プロセスは期限切れにより終了することはありません"
ちなみとMaxRequestWorkersとMaxConnectionsPerChildは英語のマニュアルに名前が変わったことが記述されていました。
"MaxRequestWorkers was called MaxClients before version 2.3.13. The old name is still supported."
"Available Apache HTTP Server 2.3.9 and later. The old name MaxRequestsPerChild is still supported."
参考