Learning Notes #4 - Apache HTTP server benchmarking tool for Load Testing
How i came across this Apache Bench aka AB tool ?
When i need to load test to check the rate limiting in my previous blog on Gatekeeper Cloud Pattern, i was searching a new tool to load test. Usually i prefer Locust, but this time i wanted to search new tool. That’s how i came across ab .
Apache Bench
Apache Bench (ab) is a simple and powerful command-line tool for performance testing web servers. It helps developers measure the performance of HTTP services by simulating multiple requests and analyzing the results.
In this blog, we’ll cover everything you need to get started, with examples for various use cases which i tried.
0. Output
Server Software: Werkzeug/3.1.3
Server Hostname: localhost
Server Port: 8090
Document Path: /
Document Length: 16 bytes
Concurrency Level: 10
Time taken for tests: 2.050 seconds
Complete requests: 2000
Failed requests: 0
Total transferred: 378000 bytes
HTML transferred: 32000 bytes
Requests per second: 975.61 [#/sec] (mean)
Time per request: 10.250 [ms] (mean)
Time per request: 1.025 [ms] (mean, across all concurrent requests)
Transfer rate: 180.07 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 1
Processing: 2 10 2.3 10 37
Waiting: 2 10 2.2 10 37
Total: 3 10 2.3 10 37
It gives a detailed output on time taken, data transferred and other stress details.
1. Basic Load Testing
To send 100 requests to a server with 10 concurrent connections
ab -n 100 -c 10 http://example.com/
-n 100: Total 100 requests.-c 10: Concurrent 10 requests at a time.http://example.com/: The URL to test.
2. Testing with POST Requests
For testing POST requests, we can use the -p option to specify the data file and -T to set the content type.
ab -n 50 -c 5 -p post_data.txt -T "application/x-www-form-urlencoded" http://example.com/api
-p post_data.txt– File containing POST data.-T "application/x-www-form-urlencoded"– Content type of the request.
3. Testing with Custom Headers
To add custom headers to your request
ab -n 100 -c 20 -H "Authorization: Bearer <token>" http://example.com/api
-H "Authorization: Bearer <token>"– Adds an Authorization header.
4. Benchmarking with Keep-Alive
By default, ab closes the connection after each request. Use -k to enable keep-alive
ab -n 500 -c 50 -k http://example.com/
-kEnables HTTP Keep-Alive.
5. Outputting Detailed Results
To write the results to a file for analysis
ab -n 200 -c 20 http://example.com/ > results.txt
> results.txt– Saves the results in a text file.
6. Configuring Timeout Values
To set a custom timeout,
ab -n 100 -c 10 -s 60 http://example.com/
-s 60: Sets a 60-second timeout for each request.
Apache Bench outputs key metrics such as
- Requests per second: Average number of requests handled.
- Time per request: Average time per request.
- Transfer rate: Data transfer rate.
Originally published on parottasalna.com.