APIの負荷テストをする際にSiegeを使ったけど、ハマったこと
ちょっとした話。
APIの負荷テストにSiegeを使う
今、会社で利用している既存のAPIに、新規機能を追加する案件を請け負っています。
それにあたって、負荷テスト等が必要なのですが何も知識が無いので色々なツールで遊んでいました。
タイトルに書いたSiegeは、そのツール群の中の一つです。
クエリパラメータつきのURLを試すには……??
ひとまず、-h
オプションで使い方を見てみました。
$ siege -h
SIEGE 4.0.4
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.
-p, --print PRINT, like GET only it prints the entire page.
-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
--no-parser NO PARSER, turn off the HTML page parser
--no-follow NO FOLLOW, do not follow HTTP redirects
Copyright (C) 2017 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.
うーん、クエリパラメータをつけてAPIを叩きたい時はどうすれば??
POSTメソッドのやり方ばっかり!
どうやら、--content-type
をつければ良い感じらしい事がググってみて分かりました。
ただ、具体例が全部POSTメソッドばかりでした。
例えば以下のような。
$ siege --concurrent=50 --content-type="text/plain" 'http://example.com/api POST plain-text-content-here'
引用元:https://thornelabs.blog/posts/using-siege-to-load-test-your-website-and-api.html
GETメソッドで試す
じゃあGETメソッドはどうするのか、色々試してみて分かりました。以下のようにすれば、問題ありませんでした。
$ siege --concurrent=50 --content-type="text/plain" 'http://example.com/api?type_id=1&id=1000'
このやり方に気づくのに、半日かかりました。
知識不足が原因でしょうか。。。
何はともあれ、やり方が分かって良かったです。
他の人が同じようにハマらないようにQiitaの記事にしました🤗
Author And Source
この問題について(APIの負荷テストをする際にSiegeを使ったけど、ハマったこと), 我々は、より多くの情報をここで見つけました https://qiita.com/hirokita117/items/ec57de295cca631d5ec2著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .