wrk.format这个函数的做用,根据参数和全局变量wrk生成一个http请求
函数签名: function wrk.format(method, path, headers, body)
method:http方法,好比GET/POST等
path: url上的路径(含函数)
headers: http header
body: http body
复制代码
每一个线程先登陆而后压测
token = nil
path = "/authenticate"
request = function()
return wrk.format("GET", path)
end
response = function(status, headers, body)
if not token and status == 200 then
token = headers["X-Token"]
path = "/resource"
wrk.headers["X-Token"] = token
end
end
复制代码
发送json
request = function()
local headers = { }
headers['Content-Type'] = "application/json"
body = {
mobile={"1533899828"},
params={code=math.random(1000,9999)}
}
local cjson = require("cjson")
body_str = cjson.encode(body)
return wrk.format('POST', nil, headers, body_str)
end
复制代码
functiondone(summary, latency, requests)
latency.min -- minimum value seen
latency.max -- maximum value seen
latency.mean -- average value seen
latency.stdev -- standard deviation
latency:percentile(99.0) -- 99th percentile value
latency(i) -- raw value and count
summary = {
duration = N, -- run duration in microseconds
requests = N, -- total completed requests
bytes = N, -- total bytes received
errors = {
connect = N, -- total socket connection errors
read = N, -- total socket read errors
write = N, -- total socket write errors
status = N, -- total HTTP status codes > 399
timeout = N -- total request timeouts
}
}
复制代码