What is Apache Bench?
Apache Bench is a benchmarking tool that is included with the Apache web server software. It is designed to provide an impression of how our Apache installation will perform under different circumstances. Specifically, it shows us how many requests per second our Apache installation can serve.
Why is Benchmarking Important?
Benchmarking a website defines how it performs in relation to similar sites. It highlights areas where we can improve and take advantage of providing information on the most effective methods to increase a site’s performance. Performing an analysis using Apache Bench helps keep our website competitive in terms of meeting best practices for our market sector. It provides key metrics to assist with improving issues, which allow us to identify the features, processes, and configurations that may require changes. This way, we can formulate a workable solution of set targets to improve our overall user engagement and conversion rates.
Benchmarking vs. Load Testing
Benchmarking, as we define it, is testing a web server or website with the expectation of meeting a specific goal. In this vein, we set the parameters we want to meet and then evaluate how those factors respond under a predetermined amount of stress. Load testing implies putting our application or server under a heavy load to determine its response.
What are Key Performance Metrics?
The following key performance metrics define how our website or application delivers the information to the end-user. Typically, we should use anywhere from five to ten specific metrics to determine our goals. These metrics should be discussed in advance and planned out for the most favorable outcome. Each business will need to choose their specific goals as all businesses will differ in this aspect. We can divide these metrics into two main areas: Application Benchmarking and Hardware Benchmarking.
These metrics are specifically related to how our application performs on the server. These are directly correlated to the next set of indicators that tie in with the following application benchmarks.
- Requests per Second
- Bytes per Second
- Bytes per Request
- Average Response Time
- Peak Response Time
- Full Page Load Time
- Content Load Time
- User Engagement
- Security & Compliance
Hardware benchmarks rely primarily on the server’s resources and the related configurations of these assets. The capability of the application primarily depends on these components and settings. Ensuring that the hardware and software capabilities that run them are paramount to enabling reliability and uptime.
- Memory Utilization
- CPU Utilization
- Thread Count
- Network Bandwidth
- Disk Usage
- Open Files Descriptors
- Error Rates
Some features of Apache Bench include the following offerings and capabilities.
- Apache Bench is open-source software.
- It is an elementary command-line computer program.
- Apache Bench is platform-independent, meaning it can be utilized on Windows, macOS, or within a Linux/Unix environment.
- It allows for both load and performance testing via HTTP or HTTPS.
Users should have a solid understanding of the following web server technologies. Additionally, identifying a baseline should be a priority.
- Command-Line Interface (CLI)
- Text Editor
- Web Server Functionality
- A baseline configuration setting on the server being tested that is comprised of the following information:
- The server should not be running behind a CDN
- Identify or suspend caching options
- Run an average latency check over the course of several days/hours
- Use the lowest latency average to test
- Identify all Apache and PHP modules being used
- Start with a low number of http connections and work up
- Use the same number of workers
- Enable keep-alive
- Turn the debug log off
- Run tests against three different file types of similar size
- Run the test command against each file type e.g.
ab -kc 1000 -n 10000 http://domain.con/test.php
ab -kc 1000 -n 10000 http://domain.con/test.png
ab -kc 1000 -n 10000 http://domain.con/test.html
- Set a failure condition
We will need information on these tools to successfully complete and understand the use, output, and post configuration settings needed to apply Apache Bench after load testing.
The Apache Bench command-line tool comes bundled with the apache or apache2-utils packages. When Apache is installed on our server, the ab command will be available to benchmark a website. To install ab, run the following command.
Apache Bench should now be available in /bin/ab on CentOS or in /usr/bin/ab on Ubuntu.
To verify the installation of ab, run the following command.
To verify the status of apache, type in the following command.
Apache Bench Syntax
To run a basic ab command, all that is required is the web server’s IP address to test, followed by a /. A single request is then sent to the IP address of the server.
ab <OPTIONS> <IP_ADDRESS>/<PATH>
Below, we have run a quick ab command against one of the servers at Google. As you can see, the output of the command provides a varied amount of output.
Here is a more in-depth look at the information output by Apache Bench.
- Server Software: Returns the HTTP header with the name of the webserver.
- Server Hostname: Returns the DNS or IP address given in the command.
- Server Port: The connection port ab is using—the ab command defaults to port 80 for http and port 443 for HTTPS.
- Document Path: This is the request URL parsed from the command line string.
- Document Length: The byte size of the first successfully returned document.
- Concurrency Level: The number of concurrent clients used during the test.
- Time Taken for Tests: Total time taken to perform the test.
- Complete Requests: Total number of successful responses received.
- Failed Requests: Total number of failed requests.
- Total Transferred: Total number of bytes received from the webserver.
- HTML Transferred: Total number of document bytes received from the server.
- Requests per Second: Total number of requests per second.
- Time per Request: This is the average time spent per request.
- Transfer Rate: The transfer rate calculated using the formula totalread/1024/timetaken.
A full list of all Apache Bench options is available on Apache’s website.
Apache Bench Examples
This command will create 100 connections to your server with one concurrency level of 10 connections simultaneously.
In the above example, we utilize multiple flags to push 1000 requests in batches of 100 while using a keepalive feature. The parameters are explained below.
- -n: Number of requests to perform for the benchmarking session.
- -c: Number of multiple requests to perform at a time.
- -k: Enable the HTTP KeepAlive feature.
- -H: custom-header.
This command outputs the test results to a .csv file, which can then be imported into Google sheets or another spreadsheet application. This allows for better testing over a period of days or even weeks.
In this example, Apache Bench can also test the availability of a Java application.
Here, we can test basic availability of an API connection on port 9500.
Typical constraints or considerations of Apache Bench include the following caveats.
- Consent of the testing server owner (as testing may be interpreted as a DDOS attack).
- Firewall block (The server being tested should whitelist the testing server in the firewall temporarily).
- Network saturation issues if overused.
- Different geographical locations.
- Distance between the servers.
- Routing congestion or latency.
Apache Bench is a useful, feature-packed command that allows us to test a website’s ability to handle various traffic amounts. It has a significant number of options available to implement, which permits multiple scenarios in which testing can take place. There are also numerous other testing solutions available to evaluate our capabilities.
We pride ourselves on being The Most Helpful Humans In Hosting™!
Our Support Teams are filled with experienced Linux technicians and talented system administrators who have intimate knowledge of multiple web hosting technologies, including those discussed in this article.
Should you have any questions regarding this information, we will always answer any inquiries with issues related to this article, 24 hours a day, 7 days a week, 365 days a year.
If you are a Fully Managed VPS server, Cloud Dedicated, VMWare Private Cloud, Private Parent server, Managed Cloud Servers, or a Dedicated server owner and you are uncomfortable with performing any of the steps outlined, we can be reached via phone at 800.580.4985, a chat, or support ticket to assist you with this process.