Tips記事
» 2002年07月03日 00時00分 UPDATE

httpのパフォーマンスをチェックしたい〜ApacheBench編〜

[木田佳克,ITmedia]

 httpサーバのApacheでは、「ApacheBench」と呼ばれるベンチマークツールが付属されている。収録先ディレクトリは次の通りだ。

・ソースコンパイルからのインストールの場合
 /usr/local/apache/bin/ab

・RPMパッケージでのインストールの場合
 /usr/sbin/ab

 実行方法は次の通りである。表示結果サンプルと共に着目したいポイントも挙げてみよう。

ad -n [連続アクセス数] -c [同時アクセス数] http://[アクセス先]

 次の例は、100件のリクエスト、10の同時接続で10回行うという指定になる(例えば、-n 100000 -c 500では、100000回のアクセスを500個同時に200回という意味だ)。通常はこの方法で数値を調整すればよいが、パラメーターをGETではなくPOSTで送信したい場合には、「-n」でなく「-p」として置き換えればよい。

# ab -n 100 -c 10 http://www.zdnet.co.jp/help/index.html
This is ApacheBench, Version 1.3d <$Revision: 1.58 $> apache-1.3
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 1998-2001 The Apache Group, http://www.apache.org/

Benchmarking www.zdnet.co.jp (be patient).....done
Server Software:    Netscape-Enterprise/3.6
Server Hostname:    www.zdnet.co.jp
Server Port:      80

Document Path:     /help/index.html
Document Length:    49092 bytes

Concurrency Level:   10
Time taken for tests:  29.254 seconds
Complete requests:   100
Failed requests:    77
  (Connect: 0, Length: 77, Exceptions: 0)
Broken pipe errors:   0
Total transferred:   5249131 bytes
HTML transferred:    5211207 bytes
Requests per second:  3.42 [#/sec] (mean)
Time per request:    2925.40 [ms] (mean)
Time per request:    292.54 [ms] (mean, across all concurrent requests)
Transfer rate:     179.43 [Kbytes/sec] received

Connnection Times (ms)
       min mean[+/-sd] median  max
Connect:    40  118 343.7   49 2058
Processing:  332 2392 2860.6  2230 16488
Waiting:   291 2391 2860.6  2230 16487
Total:    332 2510 2897.9  2285 16540

Percentage of the requests served within a certain time (ms)
 50%  2285
 66%  2430
 75%  2788
 80%  3620
 90%  5729
 95%  6802
 98% 12117
 99% 13549
100% 16540 (last request)

 上記実行結果は、次のような点をポイントとして判断しよう。幾つかの条件下でベンチマークを実行し、Apacheの設定によってどのように変化するのかを調べてみるのもよいだろう。

 また、上記の例ではindex.htmlとしてhtmlファイルを指定しているが、特にスクリプトファイル(PerlやPHPなど)を指定しても構わない。

 表示結果で注目したい行と、その示す意味は次の通りだ。

・アクセス先htmlファイル
 Document Path:     /help/index.html
・アクセス先ファイル容量
 Document Length:    49092 bytes
・送信リクエスト数
 Concurrency Level:   10
・リクエスト完了までの所要時間
 Time taken for tests:  29.254 seconds
・総リクエスト数
 Complete requests:   100
・取りこぼしたリクエスト数
 Failed requests:    77
・1秒あたりに処理されたリクエスト数
 Requests per second:  3.42 [#/sec] (mean)
・1秒あたりに処理された所要時間
 Time per request:    2925.40 [ms] (mean)
・1秒あたりに受信された容量
 Transfer rate:    179.43 [Kbytes/sec] received
・上から順に接続(Connect)、処理(Processing)、待ち時間(Wait)を集計し、最小値、平均、最大値、平均で表している
 Connnection Times (ms)
・処理時間の推移
 Percentage of the requests served within a certain time (ms)

Copyright © ITmedia, Inc. All Rights Reserved.

注目のテーマ