Mike Mead

Website load testing with Apache Bench

Written by Mike

May 26, 2014

Linux

Website load testing with Apache Bench

For basic website load testing Apache Bench is a fantastic tool that is easy to use and can be integrated into your build/deployment processes. It is not limited to testing Apache webservers and can be used with any website.

To demonstrate Apache Bench (AB) I'm using two AWS EC2 instances, one with an out of the box install of Wordpress running on Apache and the other running Apache Bench.

I would highly recommend using a separate server to run AB.

Start by installing Apache Bench (AB):

apt-get install apache2-utils

or

yum install httpd-tools

Apace Bench (AB) usage:

ab [options] [http[s]://]hostname[:port]/path

More often that not you will use the following switches:

ab -n [number of requests to perform] -c [number of multiple requests to make] [http[s]://]hostname[:port]/path

You can include cookies, basic authentication, headers and more.

Let's get testing:

A very simple test, a single request:

ab -n 1 -c 1 http://10.75.33.123:80/

Output:

Server Software:        Apache/2.2.22
Server Hostname:        10.75.33.123
Server Port:            80

Document Path:          /
Document Length:        7412 bytes

Concurrency Level:      1
Time taken for tests:   0.281 seconds
Complete requests:      1
Failed requests:        0
Write errors:           0
Total transferred:      7681 bytes
HTML transferred:       7412 bytes
Requests per second:    3.56 [#/sec] (mean)
Time per request:       281.030 [ms] (mean)
Time per request:       281.030 [ms] (mean, across all concurrent requests)
Transfer rate:          26.69 [Kbytes/sec] received

Connection Times (ms)
			  min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:   281  281   0.0    281     281
Waiting:      280  280   0.0    280     280
Total:        281  281   0.0    281     281

You can see very quickly from the output that the request took 0.281 seconds to complete.

A test levering more load, 500 requests with a concurrency level of 50:

ab -n 500 -c 50 http://10.75.33.123:80/

Output:

Concurrency Level:      50
Time taken for tests:   145.788 seconds
Complete requests:      500
Failed requests:        0
Write errors:           0
Total transferred:      3840500 bytes
HTML transferred:       3706000 bytes
Requests per second:    3.43 [#/sec] (mean)
Time per request:       14578.770 [ms] (mean)
Time per request:       291.575 [ms] (mean, across all concurrent requests)
Transfer rate:          25.73 [Kbytes/sec] received

Connection Times (ms)
			  min  mean[+/-sd] median   max
Connect:        0    1   1.8      0      12
Processing:  2519 14355 3368.7  14024   27403
Waiting:     2519 14348 3361.0  14023   27403
Total:       2520 14355 3368.6  14030   27404

Let's pick out some key lines in the output:

Time taken for tests:   145.788 seconds

The total time taken for the tests to complete.


Number of failed requests: 0

If you see any errors here it may indicate that the website you are testing is straining under the load of the test, either reduce the concurrency or number of requests.


Requests per second:    3.43 [#/sec] (mean)

The number of requests handled by the website per second, on average.


Time per request:       291.575 [ms] (mean, across all concurrent requests)

The average time per request handled by the website.


Time per request:       14578.770 [ms] (mean)

This is the average time per request factoring in concurrency (i.e. 291.575 * 50)


Connect Times (ms)
			  min  mean[+/-sd] median   max
Total:       2520 14355 3368.6  14030   27404

Min: The shortest request time during the test, 2,520ms (2.52s)

Mean[+/-sd]: The average request time during the test plus the standard deviation, 14,355ms (14.355s) with a deviation of +/- 3,368.6 (3.3686s)

Median: The 'middle' request time during the test, 14,030ms (14s)

Max: The longest request time during the test, 27,404ms (27.4s)


I guess with an average request time of ~14 seconds I should look into adding some layers of cache and optimising the Wordpress install :)

comments powered by Disqus