Useful Tools: ApacheBench (ab)
Tags: productivity, webdev, devops, linux
Published: 2019-10-30 07:48:47

Website: [https://httpd.apache.org/docs/2.4/programs/ab.html](https://httpd.apache.org/docs/2.4/programs/ab.html)

ApacheBench (`ab`) is a command line application for bench marking your web application. It was originally developed to test the Apache HTTP server but it is not limited to it — you can use the tool to test any web server. 

### Installation

ApacheBench (`ab`) is bundled in the [`apache2-utils`](https://packages.debian.org/stretch/apache2-utils) package.
You can install it on Debian/Ubuntu platforms with `apt-get install -y apache2-utils`.
If you're on a macOS powered system, `ab` is already installed, because macOS ships with Apache HTTP server.

### Usage

Suppose we want to see how fast `example.com` can handle 100 requests (`-n 100`), with a maximum of 10 requests (`-c 10`) running concurrently.

```zsh
ab -n 100 -c 10 https://example.com/
```

ApacheBench (`ab`) will then generate the following output:

```zsh
Server Software:        ECS
Server Hostname:        example.com
Server Port:            443
SSL/TLS Protocol:       TLSv1.2,ECDHE-RSA-AES128-GCM-SHA256,2048,128
Server Temp Key:        ECDH P-256 256 bits
TLS Server Name:        example.com

Document Path:          /
Document Length:        1256 bytes

Concurrency Level:      10
Time taken for tests:   4.990 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      160293 bytes
HTML transferred:       125600 bytes
Requests per second:    20.04 [#/sec] (mean)
Time per request:       499.031 [ms] (mean)
Time per request:       49.903 [ms] (mean, across all concurrent requests)
Transfer rate:          31.37 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:      309  339  18.4    338     383
Processing:   100  108   6.3    106     129
Waiting:       99  106   6.2    104     124
Total:        410  447  22.1    446     511

Percentage of the requests served within a certain time (ms)
  50%    446
  66%    453
  75%    459
  80%    463
  90%    479
  95%    488
  98%    505
  99%    511
 100%    511 (longest request)
```

You can get some really useful information from it.

```zsh
Complete requests:      100
Failed requests:        0
```

These two lines tell us, that not a single request failed. Which in fact means, that your setup is capable of serving this amount of requests.

```zsh
Requests per second:    20.04 [#/sec] (mean)
Time per request:       499.031 [ms] (mean)
Time per request:       49.903 [ms] (mean, across all concurrent requests)
```

This part gives us information on the number of requests per second your application was able to fulfil.

**Requests per second** gives you an idea of how well your web application is performing. The larger the number, the better the performance.

**Time per request (mean)** tells you the average amount of time it took for a *concurrent group* of requests to process (so in our case 10 requests took 499.031ms).

**Time per request (mean, across all concurrent requests)** tells you the average amount of time it took for a *single request* to process.

```zsh
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:      309  339  18.4    338     383
Processing:   100  108   6.3    106     129
Waiting:       99  106   6.2    104     124
Total:        410  447  22.1    446     511
```

These figures show you the component breakdown of each request.

**Connect** gives you information about the time it took to establish connection with your server (which is most typically the network latency).

The **Processing** time is the total amount of time the web application took to process and send a complete response.

**Waiting** is the time-to-first-byte after the request was sent.

### Alternatives to ApacheBench (ab)

- [Apache JMeter](https://jmeter.apache.org/): Apache JMeter is a Java based application for analyzing and measuring the performance of web applications. As opposed to ApacheBench, JMeter has a GUI to create load test scenarios. JMeter supports variable parameterization, assertions (response validation), plugins, configuration variables and report generation. Apart from the outdated GUI, JMeter is in any case a very good (and free) tool for creating complex load test scenarios.

- [loadtest](https://github.com/alexfernandez/loadtest): loadtest is an easy to use, Node.js based alternative to ApacheBench (ab).

- [weighttp](https://redmine.lighttpd.net/projects/weighttp/wiki): weighttp is a lightweight and small benchmarking tool for web servers. I've never used it, though.

- [artillery](https://artillery.io/): Artillery is a Node.js based load-testing toolkit. Artillery allows you to test HTTP, Socket.io, WebSockets, and AWS Kinesis. You can also emulate complex user behaviour. There is also a paid version to run distributed load tests. Unfortunately I cannot give you any further information or insights, because I did not used Artillery yet.

### Conclusion

I hope you find this article useful and you give ApacheBench (ab) a try.
In my opinion it is a great tool for quickly load testing your web application. If you know how to use it, you get useful results and metrics on how your web application performs.


---

If you like my content, you might want to follow me on Twitter?! [@fullstack_to](https://twitter.com/fullstack_to)