LoginSignup
21
15

More than 5 years have passed since last update.

Siege を使って WebAPI の負荷テストを実施する

Last updated at Posted at 2017-06-28

Web API の負荷テストツールとして Siege を試してみたときのメモです。
<!-- Apache Bench も試しましたが、パラメータの容量が大きいとリクエストが送信されなかったため Siege を採用しました。 -->

インストール

% brew install siege

実行オプション

% siege --help
[alert] Zip encoding disabled; siege requires zlib support to enable it
SIEGE 4.0.2
Usage: siege [options]
       siege [options] URL
       siege -g URL
Options:
  -V, --version             VERSION, prints the version number.
  -h, --help                HELP, prints this section.
  -C, --config              CONFIGURATION, show the current config.
  -v, --verbose             VERBOSE, prints notification to screen.
  -q, --quiet               QUIET turns verbose off and suppresses output.
  -g, --get                 GET, pull down HTTP headers and display the
                            transaction. Great for application debugging.
  -c, --concurrent=NUM      CONCURRENT users, default is 10
  -r, --reps=NUM            REPS, number of times to run the test.
  -t, --time=NUMm           TIMED testing where "m" is modifier S, M, or H
                            ex: --time=1H, one hour test.
  -d, --delay=NUM           Time DELAY, random delay before each requst
  -b, --benchmark           BENCHMARK: no delays between requests.
  -i, --internet            INTERNET user simulation, hits URLs randomly.
  -f, --file=FILE           FILE, select a specific URLS FILE.
  -R, --rc=FILE             RC, specify an siegerc file
  -l, --log[=FILE]          LOG to FILE. If FILE is not specified, the
                            default is used: PREFIX/var/siege.log
  -m, --mark="text"         MARK, mark the log file with a string.
                            between .001 and NUM. (NOT COUNTED IN STATS)
  -H, --header="text"       Add a header to request (can be many)
  -A, --user-agent="text"   Sets User-Agent in request
  -T, --content-type="text" Sets Content-Type in request

Copyright (C) 2016 by Jeffrey Fulmer, et al.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE.

使い方

siege コマンドの引数に URL を指定すると、その URL に対して負荷テストを行います。
デフォルトではテスト時間が無制限のため、Ctrl+C で手動終了する必要があります。

% siege http://example.com/
[alert] Zip encoding disabled; siege requires zlib support to enable it
** SIEGE 4.0.2
** Preparing 25 concurrent users for battle.
The server is now under siege...
HTTP/1.1 200     0.25 secs:    1270 bytes ==> GET  /
HTTP/1.1 200     0.25 secs:    1270 bytes ==> GET  /
HTTP/1.1 200     0.24 secs:    1270 bytes ==> GET  /

...

^C
Lifting the server siege...
Transactions:                     75 hits
Availability:                 100.00 %
Elapsed time:                   1.56 secs
Data transferred:               0.09 MB
Response time:                  0.25 secs
Transaction rate:              48.08 trans/sec
Throughput:                     0.06 MB/sec
Concurrency:                   11.87
Successful transactions:          75
Failed transactions:               0
Longest transaction:            0.29
Shortest transaction:           0.23

使い方パターン

基本系

% siege -c 5 -r 1 -t 10S http://example.com

-c は同時接続数、-rは毎秒あたりの1接続でのリクエスト数、-t はテスト時間(S/s = 秒、M/m = 分、H/h = 時間)を指定します。
この場合だと、同時接続数5で毎秒1回ずつ、10秒間の負荷テストを行います。

POST リクエストを送信する場合

% siege -c 1 -T "text/plain" 'http://example.com/api POST key1=value1&key2=value2'

URL に続けて POST キーワードと送信するデータを指定することで POST リクエストを送信できます。
-T で Content-Type を指定します。
(デフォルトはapplication/x-www-form-urlencoded形式)

POST リクエストで JSON 形式のデータを送信する場合

% siege -c 1 -T "application/json" "http://example.com/api POST {"key1":"value1","key2":"value2"}"

URLをファイルから読み込む場合

% siege -c 1 -T "application/json" -f json.txt
json.txt
http://example.com/api POST {"key1":"value1","key2":"value2"}

-f でファイルから URL リストを受け取ることもできます。
一方、パラメータだけをファイルから受け取る場合は下記のようにします。

% siege -c 1 -T "application/json" "http://example.com/api POST < /path/to/json.txt"
json.txt
{"key1":"value1","key2":"value2"}

参考文献

21
15
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
21
15