wrk & hey Guide
# wrk brew install wrk sudo apt install wrk # hey (Go) brew install hey # or: go install github.com/rakyll/hey@latest
wrk is a multithreaded HTTP benchmarking tool that uses a LuaJIT scripting engine for custom request generation. It's perfect for measuring raw throughput and latency distribution (latency, req/s, transfer rate) on a single endpoint.
hey (formerly boom) is built in Go and is simpler than wrk: it supports POST with body, custom headers, and HTTP/2 out of the box. Use it when you need to benchmark API endpoints with JSON payloads.
Both tools report latency percentiles (p50, p75, p90, p99, max), request rate, and error counts. For distributed load generation across multiple machines, use vegeta or k6 instead. The wrk2 fork adds constant throughput mode.
wrk Basics
wrk -t12 -c400 -d30s http://localhost:8080 # -t: threads, -c: connections, -d: duration
wrk -t4 -c100 -d30s --latency -H "Connection: close" http://localhost:8080 # --latency prints detailed percentile distribution
wrk -t2 -c50 -d10s --timeout 5s http://localhost:8080/api
wrk Scripting
-- post.lua
wrk.method = "POST"
wrk.body = '{"name": "test"}'
wrk.headers["Content-Type"] = "application/json"
wrk -t4 -c100 -d30s -s post.lua http://localhost:8080/users-- auth.lua
token = os.getenv("TOKEN")
request = function()
wrk.headers["Authorization"] = "Bearer " .. token
return wrk.format("GET", "/api/users")
end
TOKEN=abc123 wrk -t2 -c10 -d10s -s auth.lua http://localhost:8080hey Basics
hey -n 10000 -c 100 https://api.example.com/users # -n: total requests, -c: concurrent workers hey -z 30s -c 50 https://api.example.com/users
hey -n 5000 -c 50 -m POST \
-H "Content-Type: application/json" \
-d '{"email":"test@test.com","password":"123456"}' \
https://api.example.com/loginhey -n 1000 -c 10 \
-H "Authorization: Bearer token123" \
-H "X-Request-Id: ${RANDOM}" \
https://api.example.com/protectedhey -n 10000 -c 100 -h2 https://example.com/grpc-endpoint
Analysis
# Extract p99 latency from wrk output wrk -t2 -c50 -d10s --latency http://localhost:8080 | grep "99%" # hey JSON output for programmatic use hey -n 1000 -c 50 -o json https://example.com | jq '.latencyPercentiles