abコマンドとは
abコマンドは、ApacheでWEBサーバのベンチマークを取得するためのコマンドです。
abとはApache Benchの略で、このabコマンドは標準でApacheについてきます。
abコマンドを実行すると、サーバに同時にいくつものリクエストを送信したりできます。
そして、そのリクエストを処理するのにかかった時間や、ファイルの転送量などを数値化することができます。
それらをWEBアプリのスクリプトを改善したときなどに、処理が高速化できているかを計る目安にすることができます。
abコマンドの実行
abコマンドは、端末上から以下のような書式で実行することができます。
下記は、単に引数で指定したURLのベンチマーク結果を出力しています。
# ab http://linuxserver/
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 linuxserver (be patient).....done
Server Software: Apache/2.2.14
Server Hostname: linuxserver
Server Port: 80
Document Path: /
Document Length: 16176 bytes
Concurrency Level: 1
Time taken for tests: 0.104 seconds
Complete requests: 1
Failed requests: 0
Write errors: 0
Total transferred: 16367 bytes
HTML transferred: 16176 bytes
Requests per second: 9.58 [#/sec] (mean)
Time per request: 104.431 [ms] (mean)
Time per request: 104.431 [ms] (mean, across all concurrent requests)
Transfer rate: 153.05 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 0
Processing: 104 104 0.0 104 104
Waiting: 19 19 0.0 19 19
Total: 104 104 0.0 104 104
下記は、同時接続数100・リクエスト数1000になるまでhttp://linuxserver/にアクセスする例です。
# ab -n 1000 -c 100 http://linuxserver/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Completed 900 requests
Completed 1000 requests
Finished 1000 requests
Server Software: Apache/2.2.14
Server Hostname: linuxserver
Server Port: 80
Document Path: /
Document Length: 16176 bytes
Concurrency Level: 100
Time taken for tests: 36.596 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 16600475 bytes
HTML transferred: 16404700 bytes
Requests per second: 27.33 [#/sec] (mean)
Time per request: 3659.646 [ms] (mean)
Time per request: 36.596 [ms] (mean, across all concurrent requests)
Transfer rate: 442.98 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 399 305.1 572 840
Processing: 279 3149 999.8 2845 6420
Waiting: 51 1381 899.6 956 4093
Total: 296 3548 879.9 3468 6421
Percentage of the requests served within a certain time (ms)
50% 3468
66% 3577
75% 3807
80% 3918
90% 4543
95% 5247
98% 5777
99% 6037
100% 6421 (longest request)
abコマンドのオプションには以下のようなものがあります。
| -n 数値 | テストで発行するリクエストの回数を数値で指定 |
|---|---|
| -c 数値 | テストで同時に発行するリクエストの数を数値で指定 |
| -A ユーザー名:パスワード | ベーシック認証が必要なページでテストを行う |
| -h | abのヘルプを表示 |
abコマンド実行時の注意
abコマンド実行時に念頭に置いておく事項・懸念すべき事項は以下の通りです。
- abは単一かつ同一のファイルにしかリクエストできない。つまり、リクエスト対象であるファイルの中に画像や外部ファイルを読み込む設定がされていてもそれらのファイルは読み込まれない。
- リクエストを処理するまでの時間を計算するものであり、接続にかかる時間などは測定されない
最終更新 2010-06-06

この記事へのコメント
まだコメントは投稿されていません。