4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

vegetaとは

どこか聞き覚えのある名前のvegeta(ベジータ)とはHTTP負荷テストツールです。

● コマンドラインツール兼 Goライブラリとして利用可能
単体のCLIツールとしてすぐ使えるだけでなく、Goプログラムに組み込んで独自の負荷テストロジックを構築できます。

● UNIX哲学に基づいたシンプルなCLI設計
UNIXの“compose(組み合わせ)”の精神で構築されており、パイプ(|)やリダイレクトと相性抜群。
既存のツールチェーンへ自然に組み込むことができます。

● Coordinated Omissionを回避
一般的な負荷テストツールで発生しやすい Coordinated Omission(レイテンシ計測の歪み) を防止する仕組みを備え、より正確な結果を得られます。

● 高度で豊富なレポート機能
テキスト、JSON、ヒストグラム、HDRなど多彩な形式で出力可能。
計測データを可視化したり、外部ツールに連携した分析も容易です。

● 分散負荷テストが簡単
複数のインスタンスやマシンにまたがる負荷テストをシンプルに構築でき、大規模なスケールにも対応します。

● インストールが容易
静的バイナリやパッケージマネージャーで手軽に導入可能。
複雑なセットアップなしですぐに利用開始できます。

以下にて公開されております。
https://github.com/tsenart/vegeta

windowsへの導入(powershell)

# ダウンロード先を指定(例:C:\vegeta)
$dest = "C:\vegeta"
# ディレクトリの作成
New-Item -ItemType Directory -Force -Path $dest

# vegeta ZIP のダウンロードURL設定
$url = "https://github.com/tsenart/vegeta/releases/download/v12.13.0/vegeta_12.13.0_windows_amd64.zip"
# ZIP ダウンロード
Invoke-WebRequest -Uri $url -OutFile "$dest\vegeta.zip"
# ZIP 展開
Expand-Archive -Path "$dest\vegeta.zip" -DestinationPath $dest -Force

# 配置確認
PS C:\vegeta> ls


    ディレクトリ: C:\vegeta


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----        2025/10/31     11:32       11425280 vegeta.exe
-a----        2025/12/09     22:37        4463961 vegeta.zip

# PATHの追加
$env:Path += ";C:\vegeta"

# install確認
PS C:\vegeta> vegeta --version
Version: v12.13.0
Commit: 507c4f028fbad80168f3b734dab9530d3aabfefa
Runtime: go1.22.12 windows/amd64
Date: 2025-10-31T11:31:51Z+0000

実行

# リクエスト先としてローカルに簡易サーバーを立てる
PS C:\vegeta> python -m http.server 8000
Serving HTTP on :: port 8000 (http://[::]:8000/) ...

# 負荷テスト用のtargets.txtを作成
# targets.txt … vegeta の攻撃先を定義するファイル
Set-Content -Path "C:\vegeta\targets.txt" -Value "GET http://localhost:8000" -Encoding ascii

# 内容確認
PS C:\vegeta> cat .\targets.txt
GET http://localhost:8000

# 負荷テストの実行
vegeta attack -rate=5 -duration=10s -targets "C:\vegeta\targets.txt" --output "C:\vegeta\result.bin"
・ attack … 負荷を送る
・ -rate=5 … 秒間 5 リクエスト
・ -duration=10s … 10 秒間
・ -targets=... … どのURLに送るか
・ --output "C:\vegeta\result.bin" … 結果をバイナリで保存

# 結果の表示
PS C:\vegeta> vegeta report "C:\vegeta\result.bin"
Requests      [total, rate, throughput]         50, 5.10, 5.10
Duration      [total, attack, wait]             9.802s, 9.8s, 2.07ms
Latencies     [min, mean, 50, 90, 95, 99, max]  1.078ms, 3.201ms, 2.535ms, 3.047ms, 3.079ms, 42.428ms, 42.428ms
Bytes In      [total, mean]                     23950, 479.00
Bytes Out     [total, mean]                     0, 0.00
Success       [ratio]                           100.00%
Status Codes  [code:count]                      200:50
Error Set:

vegeta report の読み方

Requests      [total, rate, throughput]         50, 5.10, 5.10

■ total:攻撃中に送った全リクエスト数
→ 50 回送った

■ rate:攻撃開始から終了までの平均送信レート
→ 5.10 req/sec

■ throughput:実際に成功してレスポンスが返ってきた処理レート
→ 5.10 req/sec
Duration      [total, attack, wait]             9.802s, 9.8s, 2.07ms

■ total:レポートが計測した時間
→ 9.802秒

■ attack:vegetaがリクエストを投げていた時間
→ 9.8秒

■ wait:最後のリクエストが完了するまでの待ち時間
→ 2.07ms
Latencies     [min, mean, 50, 90, 95, 99, max]  
              1.078ms, 3.201ms, 2.535ms, 3.047ms, 3.079ms, 42.428ms, 42.428ms

■ min:最速のレスポンス
→ 1.078ms
■ mean:平均
→ 3.201ms
■ 50(中央値):半分のリクエストはこの時間以下
→ 2.535ms
■ 90:90%がこの時間以下
→ 3.047ms
■ 95:95%がこの時間以下
→ 3.079ms
■ 99:99%がこの時間以下
→ 42.428ms
■ max:最も遅かったレスポンス
→ 42.428ms
Bytes In      [total, mean]                     23950, 479.00


■ total:レスポンスの総サイズ
→ 23950バイト

■ mean:1リクエストあたりのレスポンスサイズ
→ 479バイト
Bytes Out     [total, mean]                     0, 0.00

■ total:リクエストの総サイズ
→ 0バイト

■ mean:1リクエストあたりのリクエストサイズ
→ 0.00バイト
Success       [ratio]                           100.00%

■ ratio:リクエストの成功率
→ 100% 成功
Status Codes  [code:count]                      200:50

■ code:count:ステータスコードの種類と回数
→ ステータス200が50回返却された
Error Set:

■ エラーがあればここに出力される

発展

Vegeta はターゲットファイル(targets.txt)に
HTTPメソッド / URL / ヘッダー / Bodyファイル指定 を書いて利用できます。

targets.txt

POST http://localhost:8000/api/user
Content-Type: application/json
@body.json

Vegetaはターゲットファイル内のURLをラウンドロビン方式で回す為、
以下のように複数にURLを記載することもできます。

POST http://localhost:8000/api/user
Content-Type: application/json
@body1.json

POST http://localhost:8000/api/order
Content-Type: application/json
@body2.json

URLごとに負荷比率を変えたい場合は同じURLを複数行書けば出現回数の比率で分散できます。
例:
/api/user … 75%
/api/order … 25%

targets.txt
POST http://localhost:8000/api/user
Content-Type: application/json
@user.json

POST http://localhost:8000/api/user
Content-Type: application/json
@user.json

POST http://localhost:8000/api/user
Content-Type: application/json
@user.json

POST http://localhost:8000/api/order
Content-Type: application/json
@order.json
4
1
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
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?