ab (ApacheBench): Usage, Options & Common CI Errors
ab fires a fixed number of HTTP requests at a URL and reports throughput.
ApacheBench (ab) is the classic single-binary HTTP benchmark. It is simple but strict: the URL must end in a path, and it surfaces connection failures with a distinctive apr_socket error.
What it does
ab sends -n total requests with -c concurrent connections to a single URL and reports requests/sec, latency percentiles, and failure counts. It is a quick way to sanity-check an endpoint under load in a pipeline.
Common usage
ab -n 1000 -c 50 https://example.com/
ab -k -n 5000 -c 100 https://example.com/ # keep-alive
ab -t 30 -c 20 https://example.com/ # run for 30 seconds
ab -H "Authorization: Bearer ${TOKEN}" -n 100 https://api/x
ab -p body.json -T application/json -n 200 https://api/x # POSTOptions
| Flag | What it does |
|---|---|
| -n <N> | Total number of requests to perform |
| -c <N> | Number of concurrent requests |
| -k | Use HTTP KeepAlive |
| -t <secs> | Time limit (implies -n 50000 unless set) |
| -p <file> -T <type> | POST body file and its Content-Type |
| -H "k: v" | Add a request header |
Common errors in CI
apr_socket_connect(): Connection refused (111) - nothing is listening on that host:port; the service has not started (add a readiness wait). "ab: invalid URL" is almost always a missing trailing path: ab needs https://host/ not https://host. "SSL handshake failed" appears on TLS/cert mismatches. "apr_pollset_poll: The timeout specified has expired (70007)" means requests timed out under -c; lower concurrency or raise -s. ab counts non-2xx as "Non-2xx responses" rather than failing - check that line.