wrk — Modern Multi-Threaded HTTP Benchmarking with Lua
Practical guide to wrk — modern multi-threaded HTTP benchmarking with Lua. Configure load profiles, measure latency percentiles, automate POST requests.
wrk is a modern, multi-threaded HTTP benchmarking tool that generates significant load with minimal system resources. Its event-driven model (epoll/kqueue) delivers far higher throughput than classic tools like ab while using only a handful of threads and connections. Lua scripting lets you customise requests, headers and response handling on the fly – from simple GET throughput tests to complex scenarios with dynamic bodies. Perfect when you need to know whether an endpoint holds up under real pressure.
Basic Usage
wrk -t <threads> -c <connections> -d <duration> <url> — Run a benchmark with threads, connections, and duration.
wrk -t4 -c100 -d30s http://localhost:8080/wrk <url> — Quick benchmark with defaults (2 threads, 10 connections, 10s).
wrk http://localhost:8080/wrk -t <threads> -c <connections> -d <duration> --latency <url> — Show detailed latency percentiles.
wrk -t4 -c100 -d30s --latency http://localhost:8080/wrk -t1 -c1 -d5s <url> — Single-thread single-connection test (baseline latency).
wrk -t1 -c1 -d5s http://localhost:8080/apiConnections & Duration
wrk -c <connections> <url> — Set the number of concurrent connections.
wrk -c 200 -d 10s http://localhost:8080/wrk -d <duration> <url> — Set the test duration (s=seconds, m=minutes).
wrk -d 1m http://localhost:8080/wrk -t <threads> <url> — Set the number of threads (usually = CPU cores).
wrk -t $(nproc) -c 400 -d 30s http://localhost:8080/wrk --timeout <duration> <url> — Set request timeout.
wrk --timeout 5s -c 100 -d 30s http://localhost:8080/Headers & Custom Requests
wrk -H '<header>' <url> — Add a custom HTTP header.
wrk -H 'Authorization: Bearer token123' -c 50 -d 10s http://localhost:8080/apiwrk -H 'Content-Type: application/json' <url> — Set content type header.
wrk -H 'Content-Type: application/json' -c 50 -d 10s http://localhost:8080/apiwrk -H '<h1>' -H '<h2>' <url> — Add multiple custom headers.
wrk -H 'Accept: application/json' -H 'X-API-Key: abc123' -c 50 -d 10s http://localhost/apiLua Scripts
wrk -s <script> <url> — Use a Lua script for custom requests.
wrk -s post.lua -t4 -c100 -d30s http://localhost:8080/apiwrk -s <script> -- <arg1> <arg2> — Pass arguments to a Lua script.
wrk -s bench.lua -t4 -c100 -d30s http://localhost/ -- arg1 arg2Common Patterns
wrk -t4 -c10 -d10s --latency <url> — Light load test with latency distribution.
wrk -t4 -c10 -d10s --latency http://localhost:8080/wrk -t8 -c500 -d60s --latency <url> — Heavy load test for stress testing.
wrk -t8 -c500 -d60s --latency http://localhost:8080/for c in 10 50 100 500; do echo "--- $c connections ---"; wrk -t4 -c$c -d10s <url>; done — Progressive load test at different concurrency levels.
for c in 10 50 100 500; do echo "--- $c connections ---"; wrk -t4 -c$c -d10s http://localhost:8080/; done Conclusion
wrk is your go-to measuring instrument when you need hard numbers on how many requests per second an endpoint can actually sustain. A single command covers simple throughput tests; Lua scripts unlock realistic scenarios – POST bodies, token authentication, dynamic payloads. Focus on latency percentiles and error rate alongside raw requests per second for a complete picture.
Further Reading
- wrk – GitHub Repository – source code, README and Lua scripting API
- wrk Scripting Documentation – Lua hooks for request generation and result evaluation