init由测试线程调用,只会在进入运行阶段时,调用一次。支持从启动wrk的命令中,获取命令行参数; delay在每次发送request之前调用,如果需要delay,那么delay相应时间; request用来生成请求;每一次请求都会调用该方法,所以注意不要在该方法中做耗时的操作; reponse在每次收到一个响应时调用;为提升性能,如果没有定义该方法,那么wrk不会解析headers和body; 结束阶段
结束阶段 function done(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 } }该方法在整个测试过程中只会调用一次,可从参数给定的对象中,获取压测结果,生成定制化的测试报告。
线程变量 wrk = { scheme = "http", host = "localhost", port = nil, method = "GET", path = "http://www.likecs.com/", headers = {}, body = nil, thread = <userdata>, } -- 生成整个request的string,例如:返回 -- GET / HTTP/1.1 -- Host: tool.lu function wrk.format(method, path, headers, body) -- method: http方法, 如GET/POST/DELETE 等 -- path: url的路径, 如 /index, /index?a=b&c=d -- headers: 一个header的table -- body: 一个http body, 字符串类型 -- 获取域名的IP和端口,返回table,例如:返回 `{127.0.0.1:80}` function wrk.lookup(host, service) -- host:一个主机名或者地址串(IPv4的点分十进制串或者IPv6的16进制串) -- service:服务名可以是十进制的端口号,也可以是已定义的服务名称,如ftp、http等 -- 判断addr是否能连接,例如:`127.0.0.1:80`,返回 true 或 false function wrk.connect(addr)原文转载自: https://www.ruoxiaozh.com/blog/article/84