对于http服务器压力测试工具,类似于ab工具,基于Golang编写的
1、https://github.com/adjust/go-wrk
go get -U github.com/adjust/go-wrk
会自动build
2、https://github.com/wg/wrk
git clone https://github.com/wg/wrk
cd wrk
make
./wrk --help
Usage: wrk <options> <url>
Options:
-c, --connections <N> Connections to keep open
-d, --duration <T> Duration of test
-t, --threads <N> Number of threads to use
-s, --script <S> Load Lua script file
-H, --header <H> Add header to request
--latency Print latency statistics
--timeout <T> Socket/request timeout
-v, --version Print version details
Numeric arguments may include a SI unit (1k, 1M, 1G)
Time arguments may include a time unit (2s, 2m, 2h)
3、示例
wrk -t10 -c100 -d10s -T5s --latency http://localhost:6060
-t:需要模拟的线程数
-c:需要模拟的连接数
-d:测试的持续时间
--timeout 或 -T:超时的时间
--latency:显示延迟统计
-s 或 --script: lua脚本,使用方法往下看
-H, --header: 添加http header, 比如. "User-Agent: wrk"
输出结果
Running 10s test @ http://localhost:6060
10 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev(正负一个标准差占比)
Latency 4.68ms 1.18ms 27.85ms 86.17%
Req/Sec 2.14k 148.28 3.29k 78.02%
Latency Distribution
50% 4.53ms
75% 4.93ms
90% 5.58ms
99% 9.48ms
215164 requests in 10.08s, 29.55MB read
Requests/sec: 21355.38
Transfer/sec: 2.93MB
对于一些复杂的请求则需要借助于LUA脚本
lua脚本为:body中是参数 ,headers为请求头
request = function()
headers = {Connection= "keep-alive"}
body = "name=中文"
return wrk.format("POST",path,headers,body)
end
wrk -t10 -c100 -d10s -T5s --latency -s testpost.lua http://localhost:6060/testpost
Running 10s test @ http://localhost:6060/testpost
10 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 5.45ms 3.04ms 69.77ms 90.50%
Req/Sec 1.89k 260.74 3.20k 82.10%
Latency Distribution
50% 4.88ms
75% 5.55ms
90% 7.19ms
99% 17.54ms
189108 requests in 10.05s, 26.51MB read
Requests/sec: 18816.19
Transfer/sec: 2.64MB