ApacheBench (ab) — Benchmark Web Servers from the Command Line
Practical guide to ApacheBench (ab) — HTTP load tests, concurrency, Keep-Alive, POST data and TLS benchmarks on the command line.
ApacheBench is the classic HTTP load-testing tool from the Apache project: a single command fires hundreds or thousands of requests at a web endpoint and instantly returns throughput, response-time percentiles and error counts. It ships on any system with apache2-utils installed – ideal for a quick smoke test after a deployment or a first-pass stress check before a traffic spike. This guide covers the most-used options, from a basic GET benchmark to HTTPS and POST-JSON testing.
Basic Benchmarks
ab -n <requests> -c <concurrent> <url> — Run a benchmark with specified requests and concurrency.
ab -n 1000 -c 10 http://localhost:8080/ab -n 100 <url> — Simple benchmark with 100 requests (1 concurrent).
ab -n 100 http://localhost/ab -t <seconds> -c <concurrent> <url> — Benchmark for a fixed duration instead of request count.
ab -t 30 -c 50 http://localhost:8080/ab -k -n <requests> -c <concurrent> <url> — Use HTTP Keep-Alive (persistent connections).
ab -k -n 5000 -c 100 http://localhost:8080/POST & PUT Data
ab -p <file> -T <content-type> <url> — Send POST data from a file.
ab -p data.json -T 'application/json' -n 100 -c 10 http://localhost:8080/apiab -u <file> -T <content-type> <url> — Send PUT data from a file.
ab -u update.json -T 'application/json' -n 50 http://localhost:8080/api/itemab -p <file> -T 'application/x-www-form-urlencoded' <url> — POST form data.
ab -p form.txt -T 'application/x-www-form-urlencoded' -n 100 http://localhost/loginHeaders & Authentication
ab -H '<header>' <url> — Add a custom HTTP header.
ab -H 'Authorization: Bearer token123' -n 100 http://localhost:8080/apiab -H 'Accept: application/json' <url> — Set Accept header for API requests.
ab -H 'Accept: application/json' -n 100 http://localhost:8080/apiab -A <user>:<pass> <url> — Use HTTP Basic Authentication.
ab -A admin:secret -n 100 http://localhost/admin/ab -C '<cookie>' <url> — Send a cookie with requests.
ab -C 'session=abc123' -n 100 http://localhost/dashboardSSL & Proxy
ab -n <requests> -c <concurrent> https://<url> — Benchmark an HTTPS endpoint.
ab -n 1000 -c 20 https://example.com/ab -f <protocol> <url> — Force a specific SSL/TLS protocol.
ab -f TLS1.2 -n 100 https://example.com/ab -X <proxy:port> <url> — Use a proxy server.
ab -X localhost:8888 -n 100 http://example.com/Output & Reporting
ab -v <level> <url> — Set verbosity level (1=warnings, 2=headers, 3+=body).
ab -v 2 -n 10 http://localhost:8080/ab -g <file> <url> — Export results as TSV (for gnuplot).
ab -g results.tsv -n 1000 -c 50 http://localhost:8080/ab -e <file> <url> — Export percentile data as CSV.
ab -e percentiles.csv -n 1000 -c 50 http://localhost:8080/ab -r <url> — Don't exit on socket receive errors.
ab -r -n 5000 -c 200 http://localhost:8080/ab -s <timeout> <url> — Set maximum seconds to wait for a response (default 30).
ab -s 60 -n 100 http://slow-api.example.com/ Conclusion
ApacheBench is not a replacement for full-featured load-testing frameworks – but for a quick smoke test after a deployment or an early indicator of performance regressions it is unbeatable in its simplicity. If you need percentile charts, HTTP/2 support or more realistic load profiles, take a look at wrk or h2load.
Further Reading
- ab – official Apache documentation – reference and all options
- ab(1) – manual page – every flag at a glance
- ApacheBench – Wikipedia – background and history