What it does
ab comes with Apache httpd tools and is on almost every server. It sends one URL again and again and prints a summary: requests per second, time per request, failed requests and the latency percentiles. It is simple: one URL, no scripts. For real scenarios use k6.
Good for: a quick before/after check of an nginx change, a cache, or a new server size.
How to write it
ab [OPTIONS] URLOptions 14
Most used
Options
Nothing matches this filter.
Examples 10
$ run as a normal user# run as root (or with sudo)
11000 requests, 50 at a time
ab -n 1000 -c 50 https://staging.example.com/ Requests per second: 812.40 [#/sec] (mean) Time per request: 61.546 [ms] (mean) Failed requests: 02With keep-alive (like real browsers)
ab -k -n 5000 -c 100 https://staging.example.com/3Test an API with a token
ab -n 500 -c 20 -H "Authorization: Bearer $TOKEN" https://staging.example.com/api/products4POST JSON
echo '{"sku":"BA-101"}' > body.json ab -n 200 -c 10 -p body.json -T application/json https://staging.example.com/api/cart5Run for 30 seconds
ab -t 30 -c 50 https://staging.example.com/6Dynamic pages have different lengths: do not count them as failed
ab -l -n 1000 -c 50 https://staging.example.com/search?q=racket7Compare before and after a change
ab -k -n 2000 -c 50 https://staging.example.com/ | grep -E 'Requests per second|95%'8Save the percentiles for a report
ab -n 1000 -c 50 -e result.csv https://staging.example.com/9Install on RHEL / Ubuntu
dnf install httpd-tools apt install apache2-utils10Debug the headers of one request
ab -n 1 -v 2 https://staging.example.com/
Nothing matches this filter.
Watch out
- The URL needs a path:
https://host/(with the last slash), nothttps://host. - ab uses HTTP/1.0 and one URL; results look better than real traffic.
- Do not benchmark production or other people's servers without permission.
Exit codes
0 | The test ran. |
1 | Error (bad URL, cannot connect). |