LoginSignup
2
0

More than 5 years have passed since last update.

wrkでのhttp ベンチマーク測定時のbasic 認証をluaスクリプトで行う.

Posted at

wrk を使って、httpベンチマークを測定する場合に、測定先にbasic認証を必要とする場合、以下のようなluaスクリプトを指定し、認証させます。
利用した wrk のバージョンは、 4.1.0 です。

  • Basic認証用 luaスクリプト
wrk.headers["Authorization"] = "Basic {base64文字列}"
  • 実行方法

-s オプションでluaスクリプトのパスを指定します.
上のBasic認証用luaスクリプトを、 BasicAuth.lua として保存しておきます。

wrk --latency -t2 -c40 -d3s -s ./BasicAuth.lua 'https://domain/xxxxx'

luaスクリプトに記載する base64文字列 は、 username:passwordbase64 化した値です。

 echo -n 'username:password' | base64 -w 0

通常であれは、urlに埋め込んで、認証させますが、認証を通過できなかったので、luaスクリプトで回避しました。

curlなら、これでhttpステータス 200が返ってくる。

curl 'https://username:password@domain/xxxxx'

wrkで同様の指定をしても、200応答にならず..

# NG
wrk --latency -t1 -c1 -d1s 'https://username:password@domain/xxxxx'

# NG
wrk --latency -t1 -c1 -d1s -H"Authorization:Basic ${base64文字列}" 
 'https://domain/xxxxx'

また、wrkでの測定結果でのhttpステータスは、200とそれ以外で丸められてしまう為、200以外の何番で応答しているのか細かく知ることができません。200番以外の値を確認する場合は、以下のようなluaスクリプトを記載して、細かく出力する必要があります。

  • httpステータスを出力するluaスクリプト
function response(status, headers, body)
   local msg = "status: %d"
   print(msg:format(status))
end

上のスクリプトは、標準出力に1アクセスごとのhttpステータスが出力するので、httpステータスの応答結果を分析する場合は、shell等で分析.

wrk --latency -t1 -c1 -d1s -s ./httpResponse.lua 'https://domain/xxxxx' |  tee out.log | grep 'status:' | cut -d':' -f2 | sort | uniq -c
2
0
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
2
0