Apache Ab



  • Apache Bench Tutorial
  • Apache Bench Useful Resources
  • Selected Reading

Httpd and IHS ship with a cool little command line utility called Apache Bench (ab). At its simplest, you pass the number of requests you want to send (-n), at what concurrency (-c) and the URL to benchmark. Ab will return various statistics on the responses (mean, median, max, standard deviation, etc.). Ab is a tool for benchmarking your Apache Hypertext Transfer Protocol (HTTP) server. It is designed to give you an impression of how your current Apache installation performs. This especially shows you how many requests per second your Apache installation is capable of serving.

In this chapter, we will guide you how to set up your environment for Apache Bench on your VPS.

System Requirement

  • Memory − 128 MB

  • Disk Space − No minimum requirement

  • Operating System − No minimum requirement

Installing Apache Bench

Apache Bench is a stand-alone application, and has no dependencies on the Apache web server installation. The following is a two-step process to install Apache Bench.

Step 1 − Update package database.

Please note that symbol # before a terminal command means that root user is issuing that command.

Step 2 − Install apache2 utils package to get access to Apache Bench.

Apache Bench is now installed. If you want to test a web application hosted on the same VPS, then it is enough to install the Apache web server only −

Being an Apache utility, Apache Bench is automatically installed on installation of the Apache web server.

Apache

Verifying Apache Bench Installation

Let us now see how to verify Apache Bench Installation. The following code will help verify the installation −

Output

Apache

When you see the above terminal output, it means you have successfully installed Apache Bench.

Creating a Privileged Sudo User

From the safety point of view, it is considered a good practice for system administrator to create a sudo user instead of working as root. We will create a test user, named test, for the purpose −

Let us set the password for the new user −

System will prompt for a new password for the user test. You can enter a simple password as we are just testing, and not deploying to the production server. Usually the sudo command will prompt you to provide the sudo user password; it is recommended not to use complicated password as the process becomes cumbersome.

Output

Testing Apache.org Website

In this section, we will test the Apache.org Website. Let us first switch to the sudo user test −

To begin with, we will test the website of Apache organization, https://www.apache.org/. We will first run the command, and then understand the output −

Here -n is the number of requests to perform for the benchmarking session. The default is to just perform a single request which usually leads to non-representative benchmarking results.

And -c is the concurrency and denotes the number of multiple requests to perform at a time. Default is one request at a time.

Apache

So in this test, Apache Bench will make 100 requests with concurrency 10 to the Apache organization server.

Apache About

Output

Having run our first test, it will be easy to recognize the pattern of use for this command which is as follows −

where,

Apache Ab Example

  • ab − Apache Bench command

  • options − flags for particular task we want to perform

  • URL − path url we want to test

Understanding the Output Values

We need to understand the different metrics to understand the various output values returned by ab. Here goes the list −

  • Server Software − It is the name of the web server returned in the HTTP header of the first successful return.

  • Server Hostname − It is the DNS or IP address given on the command line.

  • Server Port − It is the port to which ab is connecting. If no port is given on the command line, this will default to 80 for http and 443 for https.

  • SSL/TLS Protocol − This is the protocol parameter negotiated between the client and server. This will only be printed if SSL is used.

  • Document Path − This is the request URI parsed from the command line string.

  • Document Length − It is the size in bytes of the first successfully returned document. If the document length changes during testing, the response is considered an error.

  • Concurrency Level − This is the number of concurrent clients (equivalent to web browsers) used during the test.

  • Time Taken for Tests − This is the time taken from the moment the first socket connection is created to the moment the last response is received.

  • Complete Requests − The number of successful responses received.

  • Failed Requests − The number of requests that were considered a failure. If the number is greater than zero, another line will be printed showing the number of requests that failed due to connecting, reading, incorrect content length, or exceptions.

  • Total Transferred − The total number of bytes received from the server. This number is essentially the number of bytes sent over the wire.

  • HTML Transferred − The total number of document bytes received from the server. This number excludes bytes received in HTTP headers

  • Requests per second − This is the number of requests per second. This value is the result of dividing the number of requests by the total time taken.

  • Time per request − The average time spent per request. The first value is calculated with the formula concurrency * timetaken * 1000 / done while the second value is calculated with the formula timetaken * 1000 / done

  • Transfer rate − The rate of transfer as calculated by the formula totalread / 1024 / timetaken.

Quick Analysis of the Load Testing Output

Having learned about the headings of the output values from the ab command, let us try to analyze and understand the output values for our initial test −

  • Apache organisation is using their own web Server Software − Apache (version 2.4.7)

  • Server is listening on Port 443 because of https. Had it been http, it would have been 80 (default).

  • Total data transferred is 58769 bytes for 100 requests.

  • Test completed in 1.004 seconds. There are no failed requests.

  • Requests per seconds − 99.56. This is considered a pretty good number.

  • Time per request − 100.444 ms (for 10 concurrent requests). So across all requests, it is 100.444 ms/10 = 10.044 ms.

  • Transfer rate − 1338.39 [Kbytes/sec] received.

  • In connection time statistics, you can observe that many requests had to wait for few seconds. This may be due to apache web server putting requests in wait queue.

In our first test, we had tested an application (i.e., www.apache.org) hosted on a different server. In the later part of the tutorial, we will be testing our sample web-applications hosted on the same server from which we will be running the ab tests. This is for the ease of learning and demonstration purpose. Ideally, the host node and testing node should be different for accurate measurement.

To better learn ab, you should compare and observe how the output values vary for different cases as we move forward in this tutorial.

Plotting the Output of Apache Bench

Here we will plot the relevant outcome to see how much time the server takes as the number of requests increases. For that, we will add the -g option in the previous command followed by the file name (here out.data) in which the ab output data will be saved −

Let us now see the out.data before we create a plot −

Output

Let us now understand the column headers in the out.data file −

Apache
  • starttime − This is the date and time at which the call started.

  • seconds − Same as starttime but in the Unix timestamp format (date -d @1496160697 returns starttime output).

  • ctime − This is the Connection Time.

  • dtime − This is the Processing Time.

  • ttime − This is the Total Time (it is the sum of ctime and dtime, mathematically ttime = ctime + dtime).

  • wait − This is the Waiting Time.

For a pictorial visualization of how these multiple items are related to each other, take a look at the following image −

If we are working over terminal or where graphics are not available, gnuplot is a great option. We will quickly understand it by going through the following steps.

Let us install and launch gnuplot −

Output

As we are working over terminal and supposing that graphics are not available, we can choose the dumb terminal which will give output in ASCII over the terminal itself. This helps us get an idea what our plot looks like with this quick tool. Let us now prepare the terminal for ASCII plot.

Output

As, our gnuplot terminal is now ready for ASCII plot, let us plot the data from the out.data file −

Output

Apache Abbreviation

We have plotted the ttime, total time (in ms) from column 9, with respect to the number of requests. We can notice that for the initial ten requests, the total time was in the nearly 100 ms, for next 30 requests (from 10th to 40th), it increased to 1100 ms, and so on. Your plot must be different depending on your out.data.