Apache Bench is a useful little tool for testing the response time of a webservice, and thus the performance of the webserver. We can specify the number of requests to send, the target URL, set up concurrency, just to name a few of this tool's settings.
While such simulated workloads will not result exactly the same data that real world traffic will do, it is always a good idea to test before going to production. Maybe before deploying a new version of the application, we could run the tests on the new version, and compare the results with the previous test data to see if our application will serve slower, or faster than the last version. With well-planned testing, this tool can show the possible bottlenecks of the application, and may provide points of interest where we should look into our code for possible optimization.
In this tutorial we will install Apache Bench on Red Hat Enterprise Linux 8, as well as an Apache Webserver to run some tests against.
In this tutorial you will learn:- How to install Apache Bench
- How to install httpd webserver, and add some basic content
- How to run simple tests against the webserver
Software Requirements and Conventions Used
Category | Requirements, Conventions or Software Version Used |
---|---|
System | Red Hat Enterprise Linux 8 |
Software | Apache Bench 2.3 |
Other | Privileged access to your Linux system as root or via the sudo command. |
Conventions | # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command $ - requires given linux commands to be executed as a regular non-privileged user |
How to install apache bench on Redhat 8 step by step instructions
Subscribe to RSS and NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.
Apache Bench is available in the base software sources after enabling subscription management repositories along with the Apache httpd
webserver. To try out our tool, we'll add some basic content to the webserver, both static and written in php
.
- To install Apache Bench, which is in the
httpd-tools
package, we'll usednf
:# dnf install httpd-tools
- To create a test environment we'll use our
ab
tool on, we'll install a webserver with php support:# dnf install httpd php
- We'll add a static HTML page
/var/www/html/index.html
with the following content:
And another page that results in the same content, but is written in php in an intentionally wasteful manner. The file will be<html> <head> <title>Title of the webpage</title> </head> <body> <p>This is a simple html page.</p> </body> </html>
/var/www/html/index.php
, with the below content:
Note that as we serve static text, we would only need one<?php echo "<html>\n"; echo "<head>\n"; echo "<title>Title of the webpage</title>\n"; echo "</head>\n"; echo "<body>\n"; echo "<p>This is a simple html page.</p>\n"; echo "</body>\n"; echo "</html>\n"; ?>
echo
, or no php at all. We only create this page to see the difference in response times. - We can start up our webserver:
# systemctl start httpd
- We don't need
root
privileges for benchmarking. For the first test, we'll runab
against the static pageindex.html
, providing 100000 requests (-n) for the page in 10 concurrent threads (-c), within the maximum timeframe of 60 seconds (-t). On the lab machine this amount of requests will be served in one minute, but depending on the hardware this may not be sufficient. Also note that we eliminated true network traffic by benchmarking from localhost, and we push the load of both running the requests and serving them on the same hardware.$ ab -t 60 -n 100000 -c 10 http://localhost/index.html This is ApacheBench, Version 2.3 <$Revision: 1826891 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking localhost (be patient) Completed 10000 requests Completed 20000 requests Completed 30000 requests Completed 40000 requests Completed 50000 requests Completed 60000 requests Completed 70000 requests Completed 80000 requests Completed 90000 requests Completed 100000 requests Finished 100000 requests Server Software: Apache/2.4.35 Server Hostname: localhost Server Port: 80 Document Path: /index.html Document Length: 116 bytes Concurrency Level: 10 Time taken for tests: 19.556 seconds Complete requests: 100000 Failed requests: 0 Total transferred: 39600000 bytes HTML transferred: 11600000 bytes Requests per second: 5113.63 [#/sec] (mean) Time per request: 1.956 [ms] (mean) Time per request: 0.196 [ms] (mean, across all concurrent requests) Transfer rate: 1977.53 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.2 0 3 Processing: 0 2 0.8 2 26 Waiting: 0 1 0.7 1 26 Total: 0 2 0.8 2 26 Percentage of the requests served within a certain time (ms) 50% 2 66% 2 75% 2 80% 2 90% 3 95% 3 98% 4 99% 5 100% 26 (longest request)
- The second test will run with the same set of parameters, but against the wasteful php page
index.php
.
It isn't a big surprise what the results show. The static content is served much faster than the wasteful page that also need to go trough the php interpreter. And with this we have shown in a simple example how the Apache Bench tool can be used to gather statistics on the response time of our webservices.$ ab -t 60 -n 100000 -c 10 http://localhost/index.php This is ApacheBench, Version 2.3 <$Revision: 1826891 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking localhost (be patient) Completed 10000 requests Completed 20000 requests Completed 30000 requests Completed 40000 requests Completed 50000 requests Completed 60000 requests Completed 70000 requests Completed 80000 requests Completed 90000 requests Completed 100000 requests Finished 100000 requests Server Software: Apache/2.4.35 Server Hostname: localhost Server Port: 80 Document Path: /index2.php Document Length: 116 bytes Concurrency Level: 10 Time taken for tests: 35.064 seconds Complete requests: 100000 Failed requests: 0 Total transferred: 30700000 bytes HTML transferred: 11600000 bytes Requests per second: 2851.89 [#/sec] (mean) Time per request: 3.506 [ms] (mean) Time per request: 0.351 [ms] (mean, across all concurrent requests) Transfer rate: 855.01 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.2 0 3 Processing: 1 3 1.2 3 27 Waiting: 0 3 1.2 3 27 Total: 1 3 1.3 3 28 Percentage of the requests served within a certain time (ms) 50% 3 66% 4 75% 4 80% 4 90% 5 95% 6 98% 7 99% 7 100% 28 (longest request)