Benchmarking HTTP Services with wrk
Recently I discovered a simple cli tool to performance testing HTTP services, wrk
. It’s really good for generating load on a server and measuring how it handles concurrent traffic.
Basic Usage
wrk -t4 -c25 -d5s http://localhost:3000
-t
: the number of threads to use-c
: connections/requests-d
: the duration of the test
This command simulates 25 users hitting your endpoint for 5 seconds, using 4 threads.
Custom Headers
Need to send headers like Authorization
?
wrk -t2 -c50 -d10s -H "Authorization: Bearer TOKEN" http://localhost:3000
More options
To test POST with a body, you’ll need to use a Lua script:
post.lua
wrk.method = "POST"
wrk.body = '{"name":"filipelinhares"}'
wrk.headers["Content-Type"] = "application/json"
Then run:
wrk -t2 -c50 -d10s -s post.lua http://localhost:3000/api
A Simple Alternative: hey
If you’re looking for something even simpler and easy to install, hey
is a great alternative written in Go.
hey -n 100 -c 10 -m POST -H "Content-Type: application/json" -d '{"name": "filipelinhares"}' http://localhost:3000/api