, ,

Apache Bench – Doing ab Performance Tests The Right Way

Apache Bench
– 5 Minutes for realistic test
– 1/10/50/100/200/300/400/500/800/1000 Concurrent Users
– latency, error rate, success rate, response time

# CORRECT - this does 1000 requests to the URL.  No problems here.
ab -n 1000 http://my-test-service.com

# WRONG - this always does requests to the URL for 60 seconds.
ab -t 60 http://my-test-service.com

# CORRECT - this does 1000 requests to the URL.  No problems here.
# this goes for 60s
ab -k -c 1 -t 60  -n 1000000000 http://my-test-service.com

# added gzip compression custom headers
ab -k -r -l  -c 250 -t 60 -p post-data.json -T application/json  -H "Accept-Encoding: gzip,deflate" http://my-test-service.com


# WRONG - this does 1000 requests to the URL.  No problems here.
# max limit to 50k
ab -k -c 1 -n 1000000000 -t 60 http://my-test-service.com


ab -k -c 1 -n 1000000000 -t 60 http://my-test-service.com

# this does 1000 requests to the URL. No problems here.
ab -n 1000 http://my-test-service.com

# this always does requests to the URL for 60 seconds. WRONG
ab -t 60 http://my-test-service.com

If you type ab without arguments you get a basic list of options including..

-t timelimit Seconds to max. wait for responses

Easy enough. What else could one possibly need to know to use this.

The man description of this option has a bit more info

-t timelimit
Maximum number of seconds to spend for benchmarking. This implies
a -n 50000 internally. Use this to benchmark the server within a fixed total
amount of time. Per default there is no timelimit.

References

1. http://www.pinkbike.com/u/radek/blog/Apache-Bench-you-probably-are-using-the-t-timelimit-option-incor.html

Apache Bench

1. -t Option
Setting -t automatically limits the total number of requests to 50k.
This means the test will stop when either 50k requests are reached or the defined time – whichever comes first!

ab -t 60 URL
If your test server answers 50k requests in say 5 seconds, then that is when Apache Bench will stop as well.

2. Parameter Order
this is significant. Always use -t BEFORE -n.
Otherwise apache bench sets the maximum requests to 50k!

Real example:

ab -k -c 10 -t 60 -n 100000000 -s 15 http://localhost/helloworld.htm
concurrency: 10
time for test: 60s
timeout: 15 seconds (30 seconds it kind of too high)
requests: 100million

i.e. in this case, you’ll likely get what you want. 10 concurrent users for 60 seconds.

       -t timelimit
              Maximum number of seconds to spend for benchmarking. This implies a -n 50000 internally. Use this to benchmark
              the server within a fixed total amount of time. Per default there is no timelimit.

http://www.pinkbike.com/u/radek/blog/Apache-Bench-you-probably-are-using-the-t-timelimit-option-incor.html

Charting
http://www.kutukupret.com/2011/05/10/graphing-apachebench-results-using-gnuplot/