Use ApacheBench To Do Load Testing

[Total: 5    Average: 5/5]

In this tutorial, we will see How Use ApacheBench To Do Load Testing. Apache Benchmark (ab) help us to accomplish load tests. Apache Benchmark (ab) and Siege are two tools that help us to accomplish load tests. The Apache BenchMark tool is a handy application to have in your toolbox that can perform a number of helpful tasks. First, the primary use for the tool is to simulate how your server may react under maximum load

The Apache BenchMark tool is included with the Apache software but may be available in your distrobution under the Apache-Utils package. You do not need to have the Apache Web Server running on the machine you want to run AB against and you can run it against any HTTP server, not just Apache

The Apache BenchMark tool’s executable is ab. The only parameter required to be passed to ab is the webpage you want to bench mark:

To install AB on CentOS Run the following command

yum install httpd-tools

Installing AB on Debian/Ubuntu

sudo apt-get install apache2-utils

you can start load testing. A call to ab looks like this:

ab -n <num_requests> -c <concurrency> <addr>:<port><path>

Load Testing with Apache Benchmark

# send 10 requests by 5 concurrent users to the url

ab -n 10 -c 5

# 500 requests by 50 concurrent users

ab -n 500 -c 50

# authenticate when blocked by .htaccess or other auth

ab -n 10 -c 5 -A kala:kala

# explicitly accept encoding for better results

ab -n 100 -c 50 -k -H 'Accept-Encoding: gzip,deflate'

Apache Benchmark Example Results

ab -n 100 -c 50

Time taken for tests:   1.374944 seconds
Total transferred:      7502000 bytes
HTML transferred:       7453600 bytes
Requests per second:    72.73 [#/sec] (mean)
Time per request:       687.472 [ms] (mean)
Time per request:       13.749 [ms] (mean, across all concurrent requests)
Transfer rate:          5328.22 [Kbytes/sec] received
ab -n 100 -c 50 -k -H 'Accept-Encoding: gzip,deflate'

Time taken for tests:   1.267539 seconds
Total transferred:      1280900 bytes
HTML transferred:       1230100 bytes
Requests per second:    78.89 [#/sec] (mean)
Time per request:       633.770 [ms] (mean)
Time per request:       12.675 [ms] (mean, across all concurrent requests)
Transfer rate:          986.16 [Kbytes/sec] received

********* after including deflate.conf to compress

Time taken for tests:   1.503498 seconds
Total transferred:      1281100 bytes
HTML transferred:       1230300 bytes
Requests per second:    66.51 [#/sec] (mean)
Time per request:       751.749 [ms] (mean)
Time per request:       15.035 [ms] (mean, across all concurrent requests)
Transfer rate:          832.06 [Kbytes/sec] received

For example if you want to send 10 request, type following command:

ab -n 10 -c 2
This is ApacheBench, Version 2.0.41-dev <$Revision: 1.141 $> apache-2.0
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd,
Copyright (c) 1998-2002 The Apache Software Foundation,
Benchmarking (be patient).....done
Server Software:
Server Hostname:
Server Port:            80
Document Path:          /
Document Length:        16289 bytes
Concurrency Level:      1
Time taken for tests:   16.885975 seconds
Complete requests:      10
Failed requests:        0
Write errors:           0
Total transferred:      166570 bytes
HTML transferred:       162890 bytes
Requests per second:    0.59 [#/sec] (mean)
Time per request:       1688.597 [ms] (mean)
Time per request:       1688.597 [ms] (mean, across all concurrent requests)
Transfer rate:          9.59 [Kbytes/sec] received
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:      353  375  16.1    386     391
Processing:  1240 1312  52.1   1339    1369
Waiting:      449  472  16.2    476     499
Total:       1593 1687  67.7   1730    1756
Percentage of the requests served within a certain time (ms)
  50%   1730
  66%   1733
  75%   1741
  80%   1753
  90%   1756
  95%   1756
  98%   1756
  99%   1756
 100%   1756 (longest request)