# ab -n10 -c2 http://haosou.com/
-- output:
...
Complete requests: 10
Failed requests: 0
Non-2xx responses: 10
Total transferred: 3620 bytes
HTML transferred: 1780 bytes
Requests per second: 22.00 [#/sec] (mean)
Time per request: 90.923 [ms] (mean)
Time per request: 45.461 [ms] (mean, across all concurrent requests)
Transfer rate: 7.78 [Kbytes/sec] received
...
大家可以看到 ab 的使用超级简单,简单的有点弱了。在上面的例子中,我们发起了 10 个请求,每个请求都是一样的,如果每个请求有差异,ab 就无能为力。
wrk 如果要完成和 ab 一样的压力测试,区别不大,只是命令行参数略有调整。下面给大家举的是每个请求都有差异的例子,供大家参考。
scripts/counter.lua
-- example dynamic request script which demonstrates changing
-- the request path and a header for each request
-------------------------------------------------------------
-- NOTE: each wrk thread has an independent Lua scripting
-- context and thus there will be one counter per thread
counter = 0
request = function()
path = "/" .. counter
wrk.headers["X-Counter"] = counter
counter = counter + 1
return wrk.format(nil, path)
end
wrk contains code from a number of open source projects including the 'ae'
event loop from redis, the nginx/joyent/node.js 'http-parser', and Mike
Pall's LuaJIT.