Usage: wrk <options> <url> Options: -c, --connections <N> 跟服务器创建并保持的TCP链接数量 -d, --duration <T> 压测时间 -t, --threads <N> 使用多少个线程进行压测 -s, --script <S> 指定Lua脚本路径 -H, --header <H> 为每个HTTP请求添加HTTP头 --latency 在压测结束后,打印延迟统计信息 --timeout <T> 超时时间 -v, --version 打印正在使用的wrk的详细版本 Numeric arguments may include a SI unit (1k, 1M, 1G) Time arguments may include a time unit (2s, 2m, 2h)
例如: html
wrk -t8 -c200 -d30s --latency "http://www.bing.com"
Running 30s test @ http://www.bing.com (压测时间30s) 8 threads and 200 connections (共8个测试线程,200个链接) Thread Stats Avg Stdev Max +/- Stdev (平均值) (标准差)(最大值)(正负一个标准差所占比例) Latency 46.67ms 215.38ms 1.67s 95.59% (延迟) Req/Sec 7.91k 1.15k 10.26k 70.77% (处理中的请求数) Latency Distribution (延迟分布) 50% 2.93ms 75% 3.78ms 90% 4.73ms 99% 1.35s (99分位的延迟) 1790465 requests in 30.01s, 684.08MB read (30.01秒内共处理完成了1790465个请求,读取了684.08MB数据) Requests/sec: 59658.29 (平均每秒处理完成59658.29个请求) Transfer/sec: 22.79MB (平均每秒读取数据22.79MB)
wrk -t1 -c4 -d100s -T3s --script=post.lua --latency http://localhost:8080/xtopic/newsjava
post.lua脚本文件
paramArr = {} falg = 0 -- 初始化 function init(args) for line in io.lines("requestParams.txt") do //requestParams.txt 请求参数文件 print(line) paramArr[falg] = line falg = falg+1 end end -- 请求 function request() local headers = { } headers['Content-Type'] = "application/json" body = paramArr[math.random(0,table.getn(paramArr))] return wrk.format("POST",nil,headers,body) end -- 响应 function response(status,headers,body) if(status ~= 200) then print("response===error",status,body) else print("response===success",status,body) end end
wrk中执行http请求的时候,调用lua分为3个阶段,setup,running,done,每一个wrk线程中都有独立的脚本环境json