1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

負荷テストツールabコマンドの特徴と使用例

Posted at

abコマンド(Apache Benchmark)は、Webサーバーやアプリケーションの性能を簡易的に測定するためのツールです。主にHTTPリクエストの負荷テストを行い、サーバーがどの程度のリクエストを処理できるかを確認するのに使用されます。以下に特徴と使用例を挙げます。


特徴

  1. シンプルで軽量
    • コマンドラインから利用でき、シンプルな構文で負荷テストを行えます。
  2. HTTP/HTTPSサポート
    • HTTPだけでなくHTTPSにも対応しているため、セキュアなサイトの負荷テストも可能です。
  3. リクエストごとの統計を出力
    • テストの結果として、平均応答時間、秒間リクエスト数(QPS: Requests per Second)、失敗したリクエスト数などを出力します。
  4. 単純な負荷テスト
    • 1台のクライアントからの単純な負荷テストを想定しています。複雑な分散型テストには適していません。
  5. 高い利用率
    • Apache HTTP Serverに付属しているため、幅広い環境で利用可能です。

主なオプション

  • -n [リクエスト数]:総リクエスト数を指定。
  • -c [同時接続数]:同時に発行するリクエスト数を指定。
  • -k:HTTP Keep-Aliveを有効化。
  • -p [POSTデータファイル]:POSTリクエストを送信する際のデータを指定。
  • -T [コンテンツタイプ]:POSTリクエスト時のContent-Typeを指定。
  • -H [ヘッダー]:追加のHTTPヘッダーを送信。

使用例

基本的なリクエスト送信

Webサーバーに100回のリクエストを送信し、その結果を表示します。

ab -n 100 http://example.com/

同時接続数を指定した負荷テスト

10の同時接続で合計100回のリクエストを送信します。

ab -n 100 -c 10 http://example.com/

HTTPSサイトへの負荷テスト

HTTPSサイトに対してテストを実行します。

ab -n 100 -c 10 https://example.com/

POSTリクエストのテスト

POSTリクエストを100回送信します。

ab -n 100 -c 10 -p post_data.txt -T "application/x-www-form-urlencoded" http://example.com/login

post_data.txtにはPOSTするデータを記載します(例:username=test&password=1234)。

Keep-Aliveを有効化したリクエスト

HTTP Keep-Aliveを有効にして、10の同時接続で100回リクエストを送信します。

ab -n 100 -c 10 -k http://example.com/

結果例の解釈

実行後、以下のような統計が表示されます。

Server Software: Apache/2.4.46
Server Hostname: example.com
Server Port: 80

Document Path: / Document Length: 1234 bytes
Concurrency Level: 10
Time taken for tests: 2.345 seconds
Complete requests: 100
Failed requests: 0
Requests per second: 42.65 [#/sec] (mean)
Time per request: 23.45 [ms] (mean)
Time per request: 2.35 [ms] (mean, across all concurrent requests)
Transfer rate: 51.23 [Kbytes/sec] received

コードをコピーする

  • Requests per second: 1秒間に処理できたリクエスト数(QPS)。
  • Time per request: 1リクエストにかかった平均応答時間。
  • Failed requests: 失敗したリクエスト数。
  • Transfer rate: データ転送速度。

注意点

  1. 負荷テストの倫理:
    • 許可なく他者のサーバーに負荷をかける行為は法律や利用規約に違反する可能性があります。
    • テスト対象のサーバー管理者の同意を得てから実施してください。
  2. 過負荷に注意:
    • abコマンド自体がクライアントマシンのリソースを消費するため、サーバー性能の限界を正確に測定できない場合があります。
  3. 分散負荷テストは別ツールを検討:
    • 分散環境での負荷テストにはApache JMeterLocustk6などのツールが適しています。

abコマンドは軽量で素早く負荷テストを行える便利なツールですが、大規模テストには向いていない点を考慮してください。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?