apache-2.4.1をソースからインストール及びベンチマーク

Apache-2.4.1安定版がリリースされました。これまでの apache-2.2.* では event_mpm の扱いが Experiment な実験的なものでしたが晴れて正式な mpm(Multi Processing Module) として利用可能になりました。

Multi Processing Moduleという名称からも分かるように、mpm とは apache の並列処理を行うmoduleです。 apache-2.4.1 の mpm には、マルチプロセスの prefork と、マルチスレッドの worker と、今回追加されたマルチスレッド+非同期の event があります。 追加された event_mpm は一部非同期型のIO処理をしていて、nginx ライクなアーキテクチャとなっている。

用意するもの

※以下の3つのソースパッケージを取得します

  • apache
  • apr
  • apr-util

これ以外にも BerkeleyDB や pcre とか必要だと思いますが既にインストールされているものとして話を進めます。

apache ソースコードのダウンロード

http://httpd.apache.org/

$ wget http://ftp.meisei-u.ac.jp/mirror/apache/dist//httpd/httpd-2.4.1.tar.gz
$ tar zxvf httpd-2.4.1.tar.gz

apr, apr-util のダウンロード

http://apr.apache.org/

$ wget http://ftp.riken.jp/net/apache//apr/apr-1.4.6.tar.gz
$ wget http://ftp.riken.jp/net/apache//apr/apr-util-1.4.1.tar.gz

apr 及び apr-util については apache の展開したソースコードディレクトリ httpd-2.4.1/srclib 配下にソースを展開して下さい。

httpd-2.4.1/srclib/apr
httpd-2.4.1/srclib/apr-util

この2つのソースは apache を make する際に一緒に自動でコンパイルされますのでソースを配置するだけでokです。

インストール

準備が整ったら apache を make します。今回はインストールする場所を /usr/local/apache241 配下にインストールします。

$ cd httpd-2.4.1
$ sudo mkdir /usr/local/apache241
$ ./configure --prefix=/usr/local/apache241 --enable-modules=all --enable-mods-shared=all --with-mpm=worker --enable-mpms-shared='prefork worker event'

$ make 
$ sudo make install

利用したい mpm を選択する

新機能の一つとして mpm をモジュールとしてロード出来るようになりました。 利用したい mpm(worker, prefork, event) の中から一つ選び httpd.conf に追加してください。

httpd.conf

LoadModule mpm_event_module modules/mod_mpm_event.so
# LoadModule mpm_worker_module modules/mod_mpm_worker.so
# LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

動的に組み込んだモジュールの確認

httpd -M コマンドでDSOを使って動的に組み込んだモジュールの一覧を表示できます。 一覧の中に先程有効にしたmpm_event_moduleが有効になっているのが分かると思います。

$ bin/httpd -M
Loaded Modules:
 core_module (static)
 so_module (static)
 http_module (static)
 authn_file_module (shared)
 authn_core_module (shared)
 authz_host_module (shared)
 authz_groupfile_module (shared)
 authz_user_module (shared)
 authz_core_module (shared)
 access_compat_module (shared)
 auth_basic_module (shared)
 reqtimeout_module (shared)
 filter_module (shared)
 mime_module (shared)
 log_config_module (shared)
 env_module (shared)
 headers_module (shared)
 setenvif_module (shared)
 version_module (shared)
 mpm_event_module (shared)
 unixd_module (shared)
 status_module (shared)
 autoindex_module (shared)
 dir_module (shared)
 alias_module (shared)

apache起動

$ sudo /usr/local/apache/bin/apachectl -k start

起動したか確認してみます

$ tail /usr/local/apache241/log/error_log
[Thu Mar 01 17:34:01.972181 2012] [mpm_event:notice] [pid 56036:tid 34382823872] AH00489: Apache/2.4.1 (Unix) configured -- resuming normal operations
[Thu Mar 01 17:34:01.972220 2012] [core:notice] [pid 56036:tid 34382823872] AH00094: Command line: '/usr/local/apache241/bin/httpd'

各mpmのベンチマーク

以下の条件ベンチを行いました

  • apache のconfigは全てデフォルトの設定で行いました。
  • apacheサーバとは別のホストからabを使って同時接続5、カウント1000
  • OSはいずれもFreeBSD8.2
  • 2台のホストのハードはほぼ同一構成
  • リクエスト先はスタティックなHTMLファイル

mpm_event

$ ab -c 5 -n 1000 http://192.168.0.10:8088/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.0.10 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        Apache/2.4.1
Server Hostname:        192.168.0.10
Server Port:            8088

Document Path:          /
Document Length:        45 bytes

Concurrency Level:      5
Time taken for tests:   0.189 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      288000 bytes
HTML transferred:       45000 bytes
Requests per second:    5296.36 [#/sec] (mean)
Time per request:       0.944 [ms] (mean)
Time per request:       0.189 [ms] (mean, across all concurrent requests)
Transfer rate:          1489.60 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       1
Processing:     0    1   0.2      1       2
Waiting:        0    1   0.2      1       2
Total:          1    1   0.2      1       3

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      1
  80%      1
  90%      1
  95%      1
  98%      2
  99%      2
 100%      3 (longest request)

mpm_prefork

$ ab -c 5 -n 1000 http://192.168.0.10:8088/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.0.10 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        Apache/2.4.1
Server Hostname:        192.168.0.10
Server Port:            8088

Document Path:          /
Document Length:        45 bytes

Concurrency Level:      5
Time taken for tests:   0.155 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      288000 bytes
HTML transferred:       45000 bytes
Requests per second:    3886.80 [#/sec] (mean)
Time per request:       0.776 [ms] (mean)
Time per request:       0.155 [ms] (mean, across all concurrent requests)
Transfer rate:          1811.03 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:     0    0   0.1      0       1
Waiting:        0    0   0.1      0       1
Total:          1    1   0.1      1       2

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      1
  80%      1
  90%      1
  95%      1
  98%      1
  99%      1
 100%      2 (longest request)

mpm_worker

$ ab -c 5 -n 1000 http://192.168.0.10:8088/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.0.10 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        Apache/2.4.1
Server Hostname:        192.168.0.10
Server Port:            8088

Document Path:          /
Document Length:        45 bytes

Concurrency Level:      5
Time taken for tests:   0.227 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      288000 bytes
HTML transferred:       45000 bytes
Requests per second:    4413.16 [#/sec] (mean)
Time per request:       1.133 [ms] (mean)
Time per request:       0.227 [ms] (mean, across all concurrent requests)
Transfer rate:          1241.20 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:     0    1   0.3      1       2
Waiting:        0    1   0.2      1       2
Total:          1    1   0.2      1       2

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      1
  80%      1
  90%      1
  95%      1
  98%      2
  99%      2
 100%      2 (longest request)
created:

Back to top