wrk is a modern HTTP benchmarking tool capable of generating significant load when run on a single multi-core CPU.
brew install wrk
wrk -t12 -c400 -d30s --latency http://127.0.0.1:8080/index.html
This runs a benchmark for 30 seconds, using 12 threads, and keeping 400 HTTP connections open.
Running 30s test @ http://localhost:8080/index.html
12 threads and 400 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 635.91us 0.89ms 12.92ms 93.69%
Req/Sec 56.20k 8.07k 62.00k 86.54%
Latency Distribution
50% 250.00us
75% 491.00us
90% 700.00us
99% 5.80ms
22464657 requests in 30.00s, 17.76GB read
Requests/sec: 748868.53
Transfer/sec: 606.33MB
You can see the average latency of the request, but most important (with the parameter --latency) the quantile.
it’s also possible with the parameter -s to send lua script because wrk supports executing a LuaJIT script , and that’s fantastic, to be able to script our benchmark tests.
-- init random
math.randomseed(os.time())
-- the request function that will run at each request
request = function()
-- define the path that will search for q=%v 9%v being a random
number between 0 and 1000)
url_path = "/somepath/search?q=" .. math.random(0,1000)
-- if we want to print the path generated
--print(url_path)
-- Return the request object with the current URL path
return wrk.format("GET", url_path)
end
wrk -c1 -t1 -d5s -s ./my-script.lua --latency http://localhost:8000
wrk run in 3 phase :
setup
running
done
Setup
The setup phase begins after the target IP address has been resolved and all threads have been initialized but not yet started.
At this point you can change for each thread being execute the addresses found during the Ip target phase. you are able to manipulate
thread.addr : get or set the thread’s server address
thread:get(name) : get the value of a global in the thread’s env
thread:set(name, value) — set the value of a global in the thread’s env
thread:stop() — stop the thread
setup = function(thread)
-- code
end
Running
The most useful one.
Running phase are split in 3 others steps :
init
request
response
function init(args)
No comments:
Post a Comment