Vegeta について
Vegeta は HTTP サービス向けの高性能な負荷テストツールです。一定のリクエストレートを維持しながらテストを実行でき、パイプラインの組み合わせにより柔軟なテストシナリオを構築できます。レイテンシー分布やスループットなど詳細なメトリクスを生成します。
主な機能
- 01指定したリクエストレートで持続的な負荷テストを実行
- 02Unix スタイルのパイプラインでテストステージを組み合わせ
- 03レイテンシー分布を含む詳細なパフォーマンスレポートを生成
活用シーン
- 01並行アクセス下での API サーバーのパフォーマンス測定
- 02本番環境への配置前にアプリケーション容量を検証
- 03CI/CD パイプラインでのパフォーマンステスト自動化
インストール
OS またはパッケージマネージャーを選び、コマンドをターミナルで実行します。
インストール後にvegeta --versionを実行して確認します。
コマンド例
よく使うコマンドを使う順に並べています。
詳細
Vegeta

Vegeta は、一定のリクエストレートで HTTP サービスに負荷をかける必要性から開発された、汎用的な HTTP 負荷テストツールです。桁違いの威力です!

特徴
- コマンドラインツールおよび Go ライブラリとして利用できます。
- UNIX での組み合わせやすさを考慮して設計された CLI です。
- 厄介な協調的欠落を回避します。
- 充実したレポート機能を備えています。
- 分散負荷テストに簡単に使用できます。
- インストールと実行が簡単です(静的バイナリ、パッケージマネージャーなど)。
インストール
コンパイル済み実行ファイル
こちらから入手できます。
macOS
Homebrew を使用して Vegeta をインストールできます。
$ brew update && brew install vegeta
または、MacPorts を使用します。
$ port install vegeta
Arch Linux
$ pacman -S vegeta
FreeBSD
FreeBSD では、Vegeta パッケージが提供されているため、組み込みのパッケージマネージャーで Vegeta をインストールできます。
$ pkg install vegeta
ソース
git clone https://github.com/tsenart/vegeta
cd vegeta
make vegeta
mv vegeta ~/bin # Or elsewhere, up to you.
バージョン管理
ライブラリと CLI はどちらも、SemVer v2.0.0 に従ってバージョン管理されています。
v8.0.0 以降、各コンポーネントの破壊的変更をより適切に切り分けられるよう、両者は個別にバージョン管理されています。
CLI のリリースには cli/vMAJOR.MINOR.PATCH のタグが付けられ、GitHub のリリースページで公開されます。
ライブラリについては、新しいバージョンに lib/vMAJOR.MINOR.PATCH と vMAJOR.MINOR.PATCH の両方のタグが付けられます。
後者のタグは go mod との互換性に必要です。
コントリビューション
CONTRIBUTING.md を参照してください。
使用方法
Usage: vegeta [global flags] <command> [command flags]
global flags:
-cpus int
Number of CPUs to use (default = number of cpus)
-profile string
Enable profiling of [cpu, heap]
-version
Print version and exit
attack command:
-body string
Requests body file
-cert string
TLS client PEM encoded certificate file
-chunked
Send body with chunked transfer encoding
-connect-to value
A mapping of (ip|host):port to use instead of a target URL's (ip|host):port. Can be repeated multiple times.
Identical src:port with different dst:port will round-robin over the different dst:port pairs.
Example: google.com:80:localhost:6060
-connections int
Max open idle connections per target host (default 10000)
-dns-ttl value
Cache DNS lookups for the given duration [-1 = disabled, 0 = forever] (default 0s)
-duration duration
Duration of the test [0 = forever]
-format string
Targets format [http, json] (default "http")
-h2c
Send HTTP/2 requests without TLS encryption
-header value
Request header
-http2
Send HTTP/2 requests when supported by the server (default true)
-insecure
Ignore invalid server TLS certificates
-keepalive
Use persistent connections (default true)
-key string
TLS client PEM encoded private key file
-laddr value
Local IP address (default 0.0.0.0)
-lazy
Read targets lazily
-max-body value
Maximum number of bytes to capture from response bodies. [-1 = no limit] (default -1)
-max-connections int
Max connections per target host
-max-workers uint
Maximum number of workers (default 18446744073709551615)
-name string
Attack name
-output string
Output file (default "stdout")
-prometheus-addr string
Prometheus exporter listen address [empty = disabled]. Example: 0.0.0.0:8880
-proxy-header value
Proxy CONNECT header
-rate value
Number of requests per time unit [0 = infinity] (default 50/1s)
-redirects int
Number of redirects to follow. -1 will not follow but marks as success (default 10)
-resolvers value
List of addresses (ip:port) to use for DNS resolution. Disables use of local system DNS. (comma separated list)
-root-certs value
TLS root certificate files (comma separated list)
-session-tickets
Enable TLS session resumption using session tickets
-targets string
Targets file (default "stdin")
-timeout duration
Requests timeout (default 30s)
-unix-socket string
Connect over a unix socket. This overrides the host address in target URLs
-workers uint
Initial number of workers (default 10)
encode command:
-output string
Output file (default "stdout")
-to string
Output encoding [csv, gob, json] (default "json")
plot command:
-output string
Output file (default "stdout")
-threshold int
Threshold of data points above which series are downsampled. (default 4000)
-title string
Title and header of the resulting HTML page (default "Vegeta Plot")
report command:
-buckets string
Histogram buckets, e.g.: "[0,1ms,10ms]"
-every duration
Report interval
-output string
Output file (default "stdout")
-type string
Report type to generate [text, json, hist[buckets], hdrplot] (default "text")
examples:
echo "GET http://localhost/" | vegeta attack -duration=5s | tee results.bin | vegeta report
vegeta report -type=json results.bin > metrics.json
cat results.bin | vegeta plot > plot.html
cat results.bin | vegeta report -type="hist[0,100ms,200ms,300ms]"
-cpus
内部で使用する CPU 数を指定します。 デフォルトでは、システムで利用可能な CPU 数が設定されます。
-profile
実行中に有効にするプロファイラーを指定します。cpu と heap のプロファイルに対応しています。デフォルトでは何も有効になりません。
-version
バージョンを表示して終了します。
attack コマンド
-body
各リクエストのボディとして設定する内容を含むファイルを指定します。攻撃対象ごとに上書きされない限り適用されます。詳しくは -targets を参照してください。
-cert
HTTPS リクエストで使用する、PEM エンコードされた TLS クライアント証明書ファイルを指定します。
-key が指定されていない場合、このフラグの値が設定されます。
-chunked
リクエストボディをチャンク転送エンコーディングで送信するかどうかを指定します。
-connections
ターゲットホストごとの、アイドル状態で開いている接続の最大数を指定します。
-dns-ttl
DNS ルックアップ結果をキャッシュする期間を指定します。値が 0 の場合、永久にキャッシュします。 負の値を指定すると、キャッシュを無効にします。
-max-connections
ターゲットホストごとの接続の最大数を指定します。
-duration
ターゲットにリクエストを送信する時間を指定します。 内部の並行処理構造のセットアップでは、この値が可変として扱われます。 レスポンスの遅延により、実際のテスト実行時間は指定した時間より長くなる場合があります。無期限に攻撃を実行するには 0 を指定します。
-format
デコードするターゲットの形式を指定します。
json format
JSON フォーマットを使うと、ターゲットを動的に生成するプログラムとの統合が容易になります。 各ターゲットは、独立した行に 1 つの JSON オブジェクトとして記述します。method フィールドと url フィールドは必須です。 body フィールドがある場合は、Base64 でエンコードする必要があります。生成された JSON Schema で、フォーマットの詳細を定義しています。
jq -ncM '{method: "GET", url: "http://goku", body: "Punch!" | @base64, header: {"Content-Type": ["text/plain"]}}' |
vegeta attack -format=json -rate=100 | vegeta encode
http format
http フォーマットは、RFC 2616 で定義されている プレーンテキストの HTTP メッセージフォーマットにほぼ似ていますが、 インラインの HTTP ボディには対応していません。対応しているのは、読み込んでリクエストボディとして使用する ファイルへの参照のみです(以下の例を参照)。
このフォーマットのターゲットは他のプログラムでも生成できますが、もともとは 簡単なユースケースで、人が手作業でターゲットを記述するためのものです。
http フォーマットで有効なターゲットファイルの例をいくつか示します。
シンプルなターゲット
GET http://goku:9090/path/to/dragon?item=ball
GET http://user:password@goku:9090/path/to
HEAD http://goku:9090/path/to/success
カスタムヘッダーを含むターゲット
GET http://user:password@goku:9090/path/to
X-Account-ID: 8675309
DELETE http://goku:9090/path/to/remove
Confirmation-Token: 90215
Authorization: Token DEADBEEF
カスタムボディを含むターゲット
POST http://goku:9090/things
@/path/to/newthing.json
PATCH http://goku:9090/thing/71988591
@/path/to/thing-71988591.json
カスタムボディとヘッダーを含むターゲット
POST http://goku:9090/things
X-Account-ID: 99
@/path/to/newthing.json
コメントの追加
# で始まる行は無視されます。
# get a dragon ball
GET http://goku:9090/path/to/dragon?item=ball
# specify a test account
X-Account-ID: 99
-h2c
HTTP2 リクエストを TLS 暗号化なしで TCP 経由で送信するよう指定します。
-header
定義されたすべてのターゲットで使用するリクエストヘッダーを指定します。-targets を参照してください。
このフラグを繰り返すことで、必要な数だけ指定できます。
-http2
HTTP/2 に対応しているサーバーへのリクエストで、HTTP/2 を有効にするかどうかを指定します。
-insecure
無効なサーバー TLS 証明書を無視するかどうかを指定します。
-keepalive
HTTP リクエスト間で TCP 接続を再利用するかどうかを指定します。
-key
HTTPS リクエストで使用する、PEM エンコードされた TLS クライアント証明書の秘密鍵ファイルを指定します。
-laddr
使用するローカル IP アドレスを指定します。
-lazy
入力ターゲットを先読みせず、遅延読み込みするかどうかを指定します。 これにより、ターゲットを attack コマンドにストリーミングでき、メモリー使用量を 削減できます。 その代わり、ターゲットに対する各リクエストのレイテンシーが増加します。
-max-body
各レスポンスのボディから取得する最大バイト数を指定します。 残りの未読バイトはすべて読み込まれますが、破棄されます。 制限なしにするには -1 を設定します。次のような値を解釈できます。
"10 MB"->10MB"10240 g"->10TB"2000"->2000B"1tB"->1TB"5 peta"->5PB"28 kilobytes"->28KB"1 gigabyte"->1GB
-name
レスポンスに記録する攻撃の名前を指定します。
-output
バイナリー形式の結果を書き込む出力ファイルを指定します。 report コマンドの入力にパイプで渡すことを想定しています。デフォルトは stdout です。
-rate
ターゲットに対して送信する、時間単位あたりのリクエスト数を指定します。 ガベージコレクションなどの要因により、実際のリクエストレートはわずかに変動することがありますが、 全体としては指定値に非常に近い値を保ちます。 時間単位を指定しない場合は、1s が使用されます。
-rate に 0 または infinity を指定すると、vegeta は可能な限り速くリクエストを送信します。
-max-workers と併用すると、リクエストを順番に送信する(つまり、次のリクエストを送信する前にレスポンスを待つ)
同時ユーザー数が固定された状態をモデル化できます。
-rate=0 を設定したまま -max-workers に非常に大きな値を設定すると、
vegeta がリソースを過剰に消費してクラッシュすることがあります。注意して使用してください。
-redirects
各リクエストで追従するリダイレクトの最大数を指定します。デフォルトは 10 です。 値が -1 の場合、リダイレクトには追従しませんが、レスポンスは成功として扱われます。
-resolvers
名前解決に使用するカスタム DNS リゾルバーのアドレスを指定します。オペレーティングシステムで 設定されているものの代わりに使用します。Windows 以外のシステムでのみ動作します。
-root-certs
信頼する TLS ルート CA 証明書ファイルを、コンマ区切りの リストで指定します。指定しない場合は、システムのデフォルト CA 証明書が使用されます。
-session-tickets
セッションチケットを使用した TLS セッション再開に対応するかどうかを指定します。
-targets
ターゲットを読み込むファイルを指定します。デフォルトでは stdin から読み込みます。
さまざまなターゲット形式については、-format のセクションを参照してください。
-timeout
各リクエストのタイムアウトを指定します。値を 0 にすると、タイムアウトが無効になります。
-workers
攻撃で使用するワーカーの初期数を指定します。-max-workers を超えない限り、要求されたレートを維持するため、必要に応じて実際のワーカー数が増加します。
-max-workers
攻撃で使用するワーカーの最大数を指定します。攻撃で使用する並行数を制御するために使用できます。
report コマンド
Usage: vegeta report [options] [<file>...]
Outputs a report of attack results.
Arguments:
<file> A file with vegeta attack results encoded with one of
the supported encodings (gob | json | csv) [default: stdin]
Options:
--type Which report type to generate (text | json | hist[buckets] | hdrplot).
[default: text]
--buckets Histogram buckets, e.g.: '[0,1ms,10ms]'
--every Write the report to --output at every given interval (e.g 100ms)
The default of 0 means the report will only be written after
all results have been processed. [default: 0]
--output Output file [default: stdout]
Examples:
echo "GET http://:80" | vegeta attack -rate=10/s > results.gob
echo "GET http://:80" | vegeta attack -rate=100/s | vegeta encode > results.json
vegeta report results.*
report -type=text
Requests [total, rate, throughput] 1200, 120.00, 65.87
Duration [total, attack, wait] 10.094965987s, 9.949883921s, 145.082066ms
Latencies [min, mean, 50, 95, 99, max] 90.438129ms, 113.172398ms, 108.272568ms, 140.18235ms, 247.771566ms, 264.815246ms
Bytes In [total, mean] 3714690, 3095.57
Bytes Out [total, mean] 0, 0.00
Success [ratio] 55.42%
Status Codes [code:count] 0:535 200:665
Error Set:
Get http://localhost:6060: dial tcp 127.0.0.1:6060: connection refused
Get http://localhost:6060: read tcp 127.0.0.1:6060: connection reset by peer
Get http://localhost:6060: dial tcp 127.0.0.1:6060: connection reset by peer
Get http://localhost:6060: write tcp 127.0.0.1:6060: broken pipe
Get http://localhost:6060: net/http: transport closed before response was received
Get http://localhost:6060: http: can't write HTTP request on broken connection
Requests 行には、次の情報が表示されます。
- 発行されたリクエストの
total数。 attack期間中に維持された実際のリクエストrate。total期間における成功したリクエストのthroughput。
Duration 行には、次の情報が表示されます。
- すべてのリクエストの発行にかかった
attack時間(total-wait) - 最後に発行されたリクエストへの応答を待つ
wait時間(total-attack) - 攻撃にかかった
total時間(attack+wait)
レイテンシーは、リクエストに対する応答を読み取るのにかかった時間です(応答本文から -max-body バイトを読み取る時間を含みます)。
minは、攻撃中のすべてのリクエストの最小レイテンシーです。meanは、攻撃中のすべてのリクエストのレイテンシーの算術平均です。50、90、95、99はそれぞれ、攻撃中のすべてのリクエストのレイテンシーにおける 50、90、95、99 パーセンタイル(https://en.wikipedia.org/wiki/Percentile)です。これらが役立つ理由について詳しく知るには、@tylertreat によるこちらの記事をおすすめします。maxは、攻撃中のすべてのリクエストの最大レイテンシーです。
Bytes In 行と Bytes Out 行には、次の情報が表示されます。
- リクエストまたはレスポンスの本文で送信(out)または受信(in)されたバイト数の
total。 - リクエストまたはレスポンスの本文で送信(out)または受信(in)されたバイト数の
mean。
Success 比率は、エラーがなく、ステータスコードが 200 から 400 の間(両端を含まない)である応答を返したリクエストの割合を示します。
Status Codes 行には、ステータスコードのヒストグラムが表示されます。ステータスコード 0 は、リクエストの送信に失敗したことを意味します。
Error Set には、発行されたすべてのリクエストが返したエラーの一意な集合が表示されます。これには、成功以外のレスポンスステータスコードを返したリクエストも含まれます。
report -type=json
期間を表すフィールドはすべてナノ秒単位です。
{
"latencies": {
"total": 237119463,
"mean": 2371194,
"50th": 2854306,
"90th": 3228223,
"95th": 3478629,
"99th": 3530000,
"max": 3660505,
"min": 1949582
},
"buckets": {
"0": 9952,
"1000000": 40,
"2000000": 6,
"3000000": 0,
"4000000": 0,
"5000000": 2
},
"bytes_in": {
"total": 606700,
"mean": 6067
},
"bytes_out": {
"total": 0,
"mean": 0
},
"earliest": "2015-09-19T14:45:50.645818631+02:00",
"latest": "2015-09-19T14:45:51.635818575+02:00",
"end": "2015-09-19T14:45:51.639325797+02:00",
"duration": 989999944,
"wait": 3507222,
"requests": 100,
"rate": 101.01010672380401,
"throughput": 101.00012489812,
"success": 1,
"status_codes": {
"200": 100
},
"errors": []
}
buckets フィールドでは、各キーはバケットの下限を表すナノ秒の値です。
上限は、次に大きいバケットによって示されます。
上限は含まれません。
最も大きいバケットはオーバーフローバケットで、上限はありません。
値は、そのバケットに該当するリクエスト数です。
-buckets パラメーターが指定されていない場合、buckets フィールドは省略されます。
report -type=hist
指定されたバケットを使って、テキスト形式のヒストグラムを計算して出力します。 各バケットの上限は含まれません。
cat results.bin | vegeta report -type='hist[0,2ms,4ms,6ms]'
Bucket # % Histogram
[0, 2ms] 6007 32.65% ########################
[2ms, 4ms] 5505 29.92% ######################
[4ms, 6ms] 2117 11.51% ########
[6ms, +Inf] 4771 25.93% ###################
report -type=hdrplot
結果を https://hdrhistogram.github.io/HdrHistogram/plotFiles.html でプロットできる形式で書き出します。
Value(ms) Percentile TotalCount 1/(1-Percentile)
0.076715 0.000000 0 1.000000
0.439370 0.100000 200 1.111111
0.480836 0.200000 400 1.250000
0.495559 0.300000 599 1.428571
0.505101 0.400000 799 1.666667
0.513059 0.500000 999 2.000000
0.516664 0.550000 1099 2.222222
0.520455 0.600000 1199 2.500000
0.525008 0.650000 1299 2.857143
0.530174 0.700000 1399 3.333333
0.534891 0.750000 1499 4.000000
0.537572 0.775000 1548 4.444444
0.540340 0.800000 1598 5.000000
0.543763 0.825000 1648 5.714286
0.547164 0.850000 1698 6.666667
0.551432 0.875000 1748 8.000000
0.553444 0.887500 1773 8.888889
0.555774 0.900000 1798 10.000000
0.558454 0.912500 1823 11.428571
0.562123 0.925000 1848 13.333333
0.565563 0.937500 1873 16.000000
0.567831 0.943750 1886 17.777778
0.570617 0.950000 1898 20.000000
0.574522 0.956250 1911 22.857143
0.579046 0.962500 1923 26.666667
0.584426 0.968750 1936 32.000000
0.586695 0.971875 1942 35.555556
0.590451 0.975000 1948 40.000000
0.597543 0.978125 1954 45.714286
0.605637 0.981250 1961 53.333333
0.613564 0.984375 1967 64.000000
0.620393 0.985938 1970 71.113640
0.629121 0.987500 1973 80.000000
0.638060 0.989062 1976 91.424392
0.648085 0.990625 1979 106.666667
0.659689 0.992188 1982 128.008193
0.665870 0.992969 1984 142.227279
0.672985 0.993750 1986 160.000000
0.680101 0.994531 1987 182.848784
0.687810 0.995313 1989 213.356091
0.695729 0.996094 1990 256.016385
0.730641 0.996484 1991 284.414107
0.785516 0.996875 1992 320.000000
0.840392 0.997266 1993 365.764448
1.009646 0.997656 1993 426.621160
1.347020 0.998047 1994 512.032770
1.515276 0.998242 1994 568.828214
1.683532 0.998437 1995 639.795266
1.887487 0.998633 1995 731.528895
2.106249 0.998828 1996 853.242321
2.325011 0.999023 1996 1023.541453
2.434952 0.999121 1996 1137.656428
2.544894 0.999219 1996 1280.409731
2.589510 0.999316 1997 1461.988304
2.605192 0.999414 1997 1706.484642
2.620873 0.999512 1997 2049.180328
2.628713 0.999561 1997 2277.904328
2.636394 0.999609 1997 2557.544757
2.644234 0.999658 1997 2923.976608
2.652075 0.999707 1997 3412.969283
2.658916 0.999756 1998 4098.360656
2.658916 0.999780 1998 4545.454545
2.658916 0.999805 1998 5128.205128
2.658916 0.999829 1998 5847.953216
2.658916 0.999854 1998 6849.315068
2.658916 0.999878 1998 8196.721311
2.658916 0.999890 1998 9090.909091
2.658916 0.999902 1998 10204.081633
2.658916 0.999915 1998 11764.705882
2.658916 0.999927 1998 13698.630137
2.658916 0.999939 1998 16393.442623
2.658916 0.999945 1998 18181.818182
2.658916 0.999951 1998 20408.163265
2.658916 0.999957 1998 23255.813953
2.658916 0.999963 1998 27027.027027
2.658916 0.999969 1998 32258.064516
2.658916 0.999973 1998 37037.037037
2.658916 0.999976 1998 41666.666667
2.658916 0.999979 1998 47619.047619
2.658916 0.999982 1998 55555.555556
2.658916 0.999985 1998 66666.666667
2.658916 0.999986 1998 71428.571429
2.658916 0.999988 1998 83333.333333
2.658916 0.999989 1998 90909.090909
2.658916 0.999991 1998 111111.111111
2.658916 0.999992 1998 125000.000000
2.658916 0.999993 1998 142857.142858
2.658916 0.999994 1998 166666.666668
2.658916 0.999995 1998 199999.999999
2.658916 0.999996 1998 250000.000000
2.658916 0.999997 1998 333333.333336
2.658916 0.999998 1998 500000.000013
2.658916 0.999999 1998 999999.999971
2.658916 1.000000 1998 10000000.000000
encode コマンド
Usage: vegeta encode [options] [<file>...]
Encodes vegeta attack results from one encoding to another.
The supported encodings are Gob (binary), CSV and JSON.
Each input file may have a different encoding which is detected
automatically.
The CSV encoder doesn't write a header. The columns written by it are:
1. Unix timestamp in nanoseconds since epoch
2. HTTP status code
3. Request latency in nanoseconds
4. Bytes out
5. Bytes in
6. Error
7. Base64 encoded response body
8. Attack name
9. Sequence number of request
10. Method
11. URL
12. Base64 encoded response headers
Arguments:
<file> A file with vegeta attack results encoded with one of
the supported encodings (gob | json | csv) [default: stdin]
Options:
--to Output encoding (gob | json | csv) [default: json]
--output Output file [default: stdout]
Examples:
echo "GET http://:80" | vegeta attack -rate=1/s > results.gob
cat results.gob | vegeta encode | jq -c 'del(.body)' | vegeta encode -to gob
plot コマンド

Usage: vegeta plot [options] [<file>...]
Outputs an HTML time series plot of request latencies over time.
The X axis represents elapsed time in seconds from the beginning
of the earliest attack in all input files. The Y axis represents
request latency in milliseconds.
Click and drag to select a region to zoom into. Double click to zoom out.
Choose a different number on the bottom left corner input field
to change the moving average window size (in data points).
Arguments:
<file> A file output by running vegeta attack [default: stdin]
Options:
--title Title and header of the resulting HTML page.
[default: Vegeta Plot]
--threshold Threshold of data points to downsample series to.
Series with less than --threshold number of data
points are not downsampled. [default: 4000]
Examples:
echo "GET http://:80" | vegeta attack -name=50qps -rate=50 -duration=5s > results.50qps.bin
cat results.50qps.bin | vegeta plot > plot.50qps.html
echo "GET http://:80" | vegeta attack -name=100qps -rate=100 -duration=5s > results.100qps.bin
vegeta plot results.50qps.bin results.100qps.bin > plot.html
使用方法:生成されたターゲット
静的なターゲット一覧を受け取るだけでなく、Vegeta はターゲットをストリーミング形式で生成する別のプログラムと組み合わせて使用できます。以下は、本文にインクリメントする ID を含むターゲットを生成する jq ユーティリティを使った例です。
jq -ncM 'while(true; .+1) | {method: "POST", url: "http://:6060", body: {id: .} | @base64 }' | \
vegeta attack -rate=50/s -lazy -format=json -duration=30s | \
tee results.bin | \
vegeta report
使用方法:分散攻撃
オープンファイル数、メモリ、CPU、ネットワーク帯域幅などのマシンの限界に Vegeta が達し、負荷テストを実行できない場合は、Vegeta を分散して使用することをおすすめします。
目標の攻撃レートが毎秒 60k リクエストの仮想シナリオを想定し、vegeta がインストールされたマシンが 3 台あるとします。
ulimit コマンドを使用して、各マシンでユーザーのオープンファイルディスクリプター数とプロセス数の上限が十分に高く設定されていることを確認してください。
攻撃を開始する準備ができました。目標レートをマシン数で割り、その値を各攻撃で使用するだけです。ここでは、オーケストレーションに pdsh を使用します。
$ PDSH_RCMD_TYPE=ssh pdsh -b -w '10.0.1.1,10.0.2.1,10.0.3.1' \
'echo "GET http://target/" | vegeta attack -rate=20000 -duration=60s > result.bin'
前のコマンドの実行が完了したら、レポートに使用する結果ファイルを収集できます。
$ for machine in 10.0.1.1 10.0.2.1 10.0.3.1; do
scp $machine:~/result.bin $machine.bin &
done
report コマンドは複数の結果ファイルを受け付けます。
レポートを生成する前に、ファイルを読み込み、タイムスタンプ順に並べ替えます。
vegeta report *.bin
分散テストで結果を収集する別の方法として、組み込みの Prometheus Exporter を使用し、すべての Vegeta インスタンスからテスト結果を取得するよう Prometheus Server を設定できます。詳しくは、attack オプションの「prometheus-addr」と、「Prometheus Support」セクションの完全な例を参照してください。
使用方法:リアルタイム分析
iTerm をお使いの場合は、jaggr を使用して vegeta を jplot と連携させることで、ターミナル上で快適に vegeta のレポートをリアルタイムにグラフ化できます。
echo 'GET http://localhost:8080' | \
vegeta attack -rate 5000 -duration 10m | vegeta encode | \
jaggr @count=rps \
hist\[100,200,300,400,500\]:code \
p25,p50,p95:latency \
sum:bytes_in \
sum:bytes_out | \
jplot rps+code.hist.100+code.hist.200+code.hist.300+code.hist.400+code.hist.500 \
latency.p95+latency.p50+latency.p25 \
bytes_in.sum+bytes_out.sum

使用方法:ライブラリ
ライブラリのバージョン管理には SemVer v2.0.0 を採用しています。 lib/v9.0.0 以降、各コンポーネントの破壊的変更をより適切に分離できるよう、ライブラリと CLI は別々にバージョン管理されています。
git タグの命名規則と go mod との互換性について詳しくは、バージョン管理を参照してください。
package main
import (
"fmt"
"time"
vegeta "github.com/tsenart/vegeta/v12/lib"
)
func main() {
rate := vegeta.Rate{Freq: 100, Per: time.Second}
duration := 4 * time.Second
targeter := vegeta.NewStaticTargeter(vegeta.Target{
Method: "GET",
URL: "http://localhost:9100/",
})
attacker := vegeta.NewAttacker()
var metrics vegeta.Metrics
for res := range attacker.Attack(targeter, rate, duration, "Big Bang!") {
metrics.Add(res)
}
metrics.Close()
fmt.Printf("99th percentile: %s\n", metrics.Latencies.P99)
}
制限事項
サポートされる rate には上限があり、その値は使用するマシンによって異なります。
CPU がボトルネックになる(可能性は低い)場合や、メモリがボトルネックになる(可能性はより高い)場合があります。また、プロセスの実行に合わせて調整すべきシステムリソースの上限に達することもあります。重要な上限は、ファイルディスクリプター数とプロセス数です。UNIX システムでは、ユーザーの現在のソフトリミット値を取得および設定できます。
$ ulimit -n # file descriptors
2560
$ ulimit -u # processes / threads
709
変更するには、新しい値を引数として指定します。
Prometheus のサポート
Vegeta には組み込みの Prometheus Exporter があり、攻撃の実行中に有効にすることで、任意の Prometheus インスタンスから Vegeta の攻撃プロセスに接続し、攻撃メトリクスを監視できます。
コマンドラインで Prometheus Exporter を有効にするには、「prometheus-addr」フラグを設定します。
Prometheus の HTTP エンドポイントは攻撃の実行中のみ利用でき、攻撃の終了直後に閉じられます。
公開されるメトリクスは次のとおりです。
request_bytes_in- 「url」、「method」、「status」別に、対象サーバーから受信したバイト数request_bytes_out- 「url」、「method」、「status」別に、対象サーバーへ送信したバイト数request_seconds- 「url」、「method」、「status」別のリクエストレイテンシーのヒストグラムとカウンターrequest_fail_count- 「url」、「method」、「status」、「message」別の失敗したリクエスト数
Grafana のサンプルダッシュボードのソースは、ファイル lib/prom/grafana.json を確認してください。
制限事項
- Prometheus は実行中の vegeta 攻撃プロセスからメトリクスをスクレイプし、サーバー上でサンプルにタイムスタンプを割り当てます。そのため、結果のタイムスタンプは正確ではありません(つまり、結果の時刻ではなくスクレイプした時刻です)。
- Prometheus が vegeta をスクレイプするように設定するには、別途作業が必要です。これは面倒です!
- vegeta 攻撃プロセスと Prometheus サーバー間で調整が行われないため、Prometheus が最新の観測値をスクレイプする前に、攻撃プロセスが終了してしまいます。
代わりに pushgateway を使わないのはなぜでしょうか?こちらのコメントをご覧ください。
これらの制限すべてに対する適切な解決策であるリモートライト統合を追跡するイシューがあります。
ライセンス
LICENSEをご覧ください。
寄付
Vegeta を使って気に入っていただけた場合は、
1MDmKC51ve7Upxt75KoNM6x1qdXHFK6iW2 にサトシを送ることをご検討ください。スポンサーとして名前を掲載してほしい場合は、お知らせください!
