Created
April 4, 2023 19:37
-
-
Save tomasbasham/74cf7d4fc8690785db1ef524fb8b9011 to your computer and use it in GitHub Desktop.
wrk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local threads = {} | |
function setup(thread) | |
table.insert(threads, thread) | |
end | |
function init(args) | |
count_2xx = 0 | |
count_3xx = 0 | |
count_400 = 0 | |
count_404 = 0 | |
count_429 = 0 | |
count_4xx = 0 | |
count_500 = 0 | |
count_503 = 0 | |
count_5xx = 0 | |
count_xxx = 0 | |
end | |
function response(status, headers, body) | |
if status < 300 then count_2xx = count_2xx + 1 | |
elseif status < 400 then count_3xx = count_3xx + 1 | |
elseif status == 400 then count_400 = count_400 + 1 | |
elseif status == 404 then count_404 = count_404 + 1 | |
elseif status == 429 then count_429 = count_429 + 1 | |
elseif status < 500 then count_4xx = count_4xx + 1 | |
elseif status == 500 then count_500 = count_500 + 1 | |
elseif status == 503 then count_503 = count_503 + 1 | |
else count_xxx = count_xxx + 1 | |
end | |
end | |
function done(summary, latency, requests) | |
total_2xx = 0 | |
total_3xx = 0 | |
total_400 = 0 | |
total_404 = 0 | |
total_429 = 0 | |
total_4xx = 0 | |
total_500 = 0 | |
total_503 = 0 | |
total_5xx = 0 | |
total_xxx = 0 | |
for index, thread in ipairs(threads) do | |
total_2xx = total_2xx + thread:get("count_2xx") | |
total_3xx = total_3xx + thread:get("count_3xx") | |
total_400 = total_400 + thread:get("count_400") | |
total_404 = total_404 + thread:get("count_404") | |
total_429 = total_429 + thread:get("count_429") | |
total_4xx = total_4xx + thread:get("count_4xx") | |
total_500 = total_500 + thread:get("count_500") | |
total_503 = total_503 + thread:get("count_503") | |
total_5xx = total_5xx + thread:get("count_5xx") | |
total_xxx = total_xxx + thread:get("count_xxx") | |
end | |
io.write("\n------------------------------\n") | |
io.write("Response Latencies\n\n") | |
for _, p in pairs({ 50, 90, 99, 99.999 }) do | |
n = latency:percentile(p) | |
io.write(string.format("%g%%\t=> %d\n", p, n)) | |
end | |
local msg_status = "HTTP Status %s Count: %d\n" | |
io.write("\n------------------------------\n") | |
io.write("Response Codes\n\n") | |
io.write(msg_status:format("2xx", total_2xx)) | |
io.write(msg_status:format("3xx", total_3xx)) | |
io.write(msg_status:format("400", total_400)) | |
io.write(msg_status:format("404", total_404)) | |
io.write(msg_status:format("429", total_429)) | |
io.write(msg_status:format("4xx", total_4xx)) | |
io.write(msg_status:format("500", total_500)) | |
io.write(msg_status:format("503", total_503)) | |
io.write(msg_status:format("5xx", total_5xx)) | |
io.write(msg_status:format("xxx", total_xxx)) | |
end | |
-- Print contents of `tbl`, with indentation. | |
-- `indent` sets the initial level of indentation. | |
function tprint (tbl, indent) | |
if not indent then indent = 0 end | |
for k, v in pairs(tbl) do | |
formatting = string.rep(" ", indent) .. k .. ": " | |
if type(v) == "table" then | |
print(formatting) | |
tprint(v, indent+1) | |
elseif type(v) == 'boolean' then | |
print(formatting .. tostring(v)) | |
else | |
print(formatting .. v) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
wrk $1 \ | |
-R 150 \ | |
-d 100 \ | |
-s loadtest.lua |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment