functionresponse(status, headers, body) ifstatus ~= 200then print(body) wrk.thread:stop() end end
done函数
在所有请求执行完以后调用, 一般用于自定义统计结果。
1 2 3 4 5 6 7
done = function(summary, latency, requests) io.write("------------------------------\n") for _, p inpairs({ 50, 90, 99, 99.999 }) do n = latency:percentile(p) io.write(string.format("%g%%,%d\n", p, n)) end end
local msg = "thread %d created" print(msg:format(id)) end
functionrequest() requests = requests + 1 return wrk.request() end
functionresponse(status, headers, body) responses = responses + 1 end
functiondone(summary, latency, requests) for index, thread inipairs(threads) do local id = thread:get("id") local requests = thread:get("requests") local responses = thread:get("responses") local msg = "thread %d made %d requests and got %d responses" print(msg:format(id, requests, responses)) end end
local msg = "thread %d created" print(msg:format(id)) end
functionrequest() requests = requests + 1 return wrk.request() end
functionresponse(status, headers, body) responses = responses + 1 ifstatus ~= 200then ns200 = ns200 + 1 else s200 = s200 + 1 end -- local msg = "status %d result %s" -- print(msg:format(status, body)) end
functiondone(summary, latency, requests) for index, thread inipairs(threads) do local id = thread:get("id") local requests = thread:get("requests") local responses = thread:get("responses") local s200 = thread:get("s200") local ns200 = thread:get("ns200") local msg = "thread %d made %d requests and got %d responses, %d status(200) and %d status(not 200)" print(msg:format(id, requests, responses, s200, ns200)) end end
-- local msg = "status: %d decision: %s" -- print(msg:format(status, decision)) end
functionparsejson(body) if body == nilthen returnnil end
local json = cjson.decode(body) ifnot json then returnnil end if json.reason_code == 600then returnnil end return json.final_decision end
functiondone(summary, latency, requests) for index, thread inipairs(threads) do local id = thread:get("id") local requests = thread:get("requests") local responses = thread:get("responses") local s200 = thread:get("s200") local ns200 = thread:get("ns200") local accept = thread:get("accept") local review = thread:get("review") local reject = thread:get("reject") localerror = thread:get("error") local msg = "thread %d made %d requests and got %d responses, %d status(200) and %d status(not 200), decision: accept(%d),review(%d),reject(%d),error(%d)" print(msg:format(id, requests, responses, s200, ns200, accept, review, reject, error)) end end