LoginSignup
0
2

More than 5 years have passed since last update.

vegeta(負荷試験ツール)

Last updated at Posted at 2019-03-01

概要

vegeta という負荷試験のツールが存在する。
バイナリをダウンロードしてくるだけで利用でき、とても便利なツール。
https://github.com/tsenart/vegeta

手順

インストール方法については、README に記載されているので、
こちらではツールを叩く部分を見てみる。

サーバを立てる

server.go

package main

import (
    "fmt"
    "net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Hello, World")
}

func main() {
    http.HandleFunc("/", handler) // ハンドラを登録してウェブページを表示させる
    http.ListenAndServe(":8080", nil)
}

こちらを起動する

% go run server

別ターミナルでcurl を発行すると次のような感じ

% curl localhost:8080
Hello, World%

query ファイルを準備

% cat query.txt
GET http://localhost:8080

vegeta で負荷をかけてみる

% vegeta attack -targets=query.txt -rate=10 -duration=5s | tee result.bin

結果を確認

% vegeta report result.bin
Requests      [total, rate]            50, 10.20
Duration      [total, attack, wait]    4.904822344s, 4.904353s, 469.344µs
Latencies     [mean, 50, 95, 99, max]  465.922µs, 409.143µs, 619.695µs, 1.810705ms, 1.810705ms
Bytes In      [total, mean]            600, 12.00
Bytes Out     [total, mean]            0, 0.00
Success       [ratio]                  100.00%
Status Codes  [code:count]             200:50
Error Set:

手軽に負荷試験ができて、とても良い感じですね^^

ついでにpython のサーバではこんな感じになった

# サーバを起動しておく
% python -m http.server 8080
Serving HTTP on 0.0.0.0 port 8080 ...

# vegeta を実行の上結果を取得
% vegeta attack -targets=query.txt -rate=10 -duration=5s | tee result.bin

% vegeta report result.bin
Requests      [total, rate]            50, 10.19
Duration      [total, attack, wait]    4.906335987s, 4.904734s, 1.601987ms
Latencies     [mean, 50, 95, 99, max]  1.691173ms, 1.580345ms, 1.904286ms, 5.657317ms, 5.657317ms
Bytes In      [total, mean]            35500, 710.00
Bytes Out     [total, mean]            0, 0.00
Success       [ratio]                  100.00%
Status Codes  [code:count]             200:50
Error Set:

go の方がレイテンシが随分早いですね^^

0
2
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
0
2