apache bench for load testing

How to Use Apache bench for Load Testing

Apache bench (also called Apache benchmark) is a useful load testing tool for websites that run on Apache web server. It is easy to install, and allows you to simulate & test different kinds of website loads, to enable your website to cope with real-world situations. In this article, we will look at how to install, configure & use Apache bench for load testing. We will also look at how to interpret Apache bench results.


How to Use Apache bench for Load Testing

Here are the steps to install and use Apache bench for load testing.


1. Install Apache bench

Open terminal and run the following command to install Apache bench

Ubuntu/Debian

$ sudo apt-get update 
$ sudo apt-get install -y apache2-utils

CentOS/Redhat/Fedora

# yum install httpd-tools

Bonus Read : How to Remove index.php from URL


2. Run Apache bench load testing

Once installed, you can directly use it for load testing. Here’s the syntax for Apache bench.

$ ab <OPTIONS> <WEB_SERVER_ADDRESS>/<PATH>

In the above command, you need to specify your web server address or URL path that you want to test. Please note, if you specify web server address, add a trailing slash (/) at its end, otherwise Apache bench might give an error.

Bonus Read : How to Install Fail2Ban in Apache Web server

For example, here’s the command to send 10000 requests with 100 concurrent connections to URL www.example.com/products

$ ab -n 10000 -c 100 www.example.com/products/

In the above command, we use -n option to specify total number of requests to send, and -c option to specify concurrency. You may alternatively mention -t option to specify the time duration for sending these requests. Here’s a list of all available options in Apache bench.

After Apache bench runs the tests, it will produce an output like the following.

Server Software:        Amazon Cloud Services
Server Hostname:       Your_host
Server Port:            443
SSL/TLS Protocol:       TLSv1.2,ECDHE-RSA-AES128-GCM-SHA256,2048,128
TLS Server Name:        Your_host

Document Path:          /products/
Document Length:        42533 bytes

Concurrency Level:      2
Time taken for tests:   2.955 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      5625689 bytes
HTML transferred:       576800 bytes
Requests per second:    15.19 [#/sec] (mean)
Time per request:       59.294 [ms] (mean)
Time per request:       29.357 [ms] (mean, across all concurrent requests)
Transfer rate:          1212.21 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       30   63   6.1     41      89
Processing:    13   20   7.4     25      89
Waiting:        6   24  9.6     13      75
Total:         57   77  12.0     65     167

Percentage of the requests served within a certain time (ms)
  50%     65
  66%     75
  75%     80
  80%     91
  90%     95
  95%     102
  98%    114
  99%    177
 100%    177 (longest request)

In the above output, Apache will display key metrics such as Time taken for tests, No. of requests completed, Failed requests, Total data transferred, HTML transferred, Requests per second, Time Per Request, Transfer rate.

Bonus Read : How to Install memcached in Apache

It also gives a useful stats (min, mean, median, max) about connection times in milliseconds. It also provides a distribution of percent of requests that were completed within a certain amount of time.

Hopefully, this article will help you set up and run load testing for Apache web server. Ubiq makes it easy to visualize data, and monitor them in real-time dashboards. Try Ubiq for free.

mm

About Ubiq

Ubiq is a powerful dashboard & reporting platform for small & medium businesses. Build dashboards, charts & reports for your business in minutes. Get insights from data quickly. Try it for free today!