loadtest, httperf でお手軽負荷テスト

go で作った WebAPI サーバの速度検証をしてみました。 単に GET リクエストを投げるだけでよいので、JMeter でなくて お手軽にできるツールでやりました。

loadtest

node.js 用のテストツールで 自分でリクエストを好きに定義できるのが特徴です。

例えば、パラメータをランダムに変えたければ requestGeneratorModule.js に

const querystring = require('querystring');

module.exports = function(params, options, client, callback) {
    const random = (max) => Math.floor(Math.random() * Math.floor(max));
    const getParams = { 'id': random(100) };
    const paramStr = querystring.stringify(getParams);

    options.path = options.path + '?' + paramStr

    return client(options, callback);
}

こんな感じで書いて

$ npx loadtest -R requestGeneratorModule.js webapi.example.com/path/to/api/

でいけます。

httperf

loadtest だと秒間あたりのリクエスト数を指定できないので、 こっちも入れてみました。

httperf --server webapi.example.com --port 80 --uri '/path/to/api/&id=100' --num-call 1 --num-conn 100 --rate 100

こんな感じで使えます。 この場合 --rate に 100 を指定してるので秒間 100 リクエストになります。

インストール

brew が使える環境でなかったので github から落としてきて自分でコンパイルしました。

$ git clone git@github.com:httperf/httperf.git
$ cd httperf
$ autoreconf -i
$ ./configure
$ make