ApacheBenchでBasic認証つきプロキシ通してベンチマーク
初めてab使いました。
- OS: Amazon Linux
- ApacheBench: Version 2.3 <$Revision: 1843412 $>
もくじ
ApacheBenchインストール
ApacheBenchはhttpdに入ってます。
sudo yum update
sudo yum install httpd24
インストールできたら、abコマンドが使えるようになったことを確認します。
ab -V
以下のようにバージョン情報が表示されればOKです。
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
使ってみた
- 対象のURLは http://example.com とします。
- プロキシはIPアドレス 1.1.1.1 の、ポート 8080 とします。
- プロキシのBasic認証のユーザー名は pxuser、パスワードは pxpass とします。
- ※対象がBasic認証付きページなのではなく、Basic認証付きのプロキシを使ってるという意味です。
同時に20個ずつのリクエストを、60秒間投げ続ける設定で行いました。オプション名の -X
と -P
は必ず大文字で指定します。
ab -c 20 -t 60 -X 1.1.1.1:8080 -P pxuser:pxpass http://example.com
結果の見方は、ざっと以下のような感じです。
Server Software:
Server Hostname: (対象のホスト名)
Server Port: (対象のポート)
Document Path: (対象のURLのパス)
Document Length: (レスポンスボディのバイト数)
Concurrency Level: (同時アクセス数)
Time taken for tests: (テスト全体でかかった秒数)
Complete requests: (成功したリクエスト数)
Failed requests: (失敗したリクエスト数)
Total transferred: (全体で受信したバイト数)
HTML transferred: (全体で受信したバイト数から、HTTPヘッダを差し引いたバイト数)
Requests per second: (秒あたりリクエスト回数)
Transfer rate: (秒あたり受信キロバイト)
なお、今回は対象からのレスポンスが速すぎて、リクエストを合計50000件投げたところでベンチマークが終わってしまいました。
そもそも -t
オプション使用時は、暗黙的に -n 50000
が固定で指定されるみたいです。
-t timelimit Maximum number of seconds to spend for benchmarking. *This implies a -n 50000 internally.* Use this to benchmark the server within a fixed total amount of time. Per default there is no timelimit.
abコマンド使い方メモ
リクエストを10回投げる
ab -n 10 http://example.com
同時に2個ずつのリクエストを計10回投げる (=2人が5回ずつアクセスする)
ab -n 10 -c 2 http://example.com
リクエストを30秒間投げ続ける
ab -t 30 http://example.com
同時に20個ずつのリクエストを30秒間投げ続ける
ab -c 20 -t 30 http://example.com
プロキシを通してリクエストを10回投げる
ab -n 10 -X 1.1.1.1:8080 http://example.com
Basic認証つきページにリクエストを10回投げる
ab -n 10 -A user:pass http://example.com
Basic認証つきプロキシを通してBasic認証つきページにリクエストを10回投げる
ab -n 10 -A user:pass -X 1.1.1.1:8080 -P pxuser:pxpass http://example.com
リクエストを10回投げた結果をHTMLで出力してファイルに保存する
ab -n 10 -w http://example.com > results.html
参考記事
コマンドは、大まかなところは以下の記事を参考にさせていただきました。
Apache Benchでサクッと性能テスト - Qiita
細かいところは公式ドキュメントを参照しました。
ab - Apache HTTP server benchmarking tool - Apache HTTP Server Version 2.4