Last updated on July 22nd, 2024 at 04:59 am
When you develop websites and apps, it is essential that they are able to handle the visitor traffic easily. Otherwise, your web server will crash and the website/app will stop working. For this purpose, developers often rely on load testing procedure, where a server is hit with a specific number of requests to simulate real-world traffic. There are several load testing tools – paid and free – available for this purpose. Apache bench (also called Apache benchmark) is one of the most popular 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.
What is Apache Bench
Apache bench is a free load testing tool meant to test Apache web server. It is basically an http client that sends requests to Apache server, reviews the responses and summarizes results. Although it was built to test Apache server, you can use it with any server that handles HTTP requests. It is widely used by web developers and system administrators to check if their website/app can handle real-world traffic.
Apache bench offers many useful features to send different kinds of server loads. For example, it allows you to send concurrent requests to simulate real-world conditions. It also allows you to send requests that stay open using HTTP KeepAlive request header, to simulate long running requests.
It allows you to send batches of requests at regular intervals of time to test if your server stays up till the end. Based on server responses, it compiles load testing results. If your server stops responding midway, then it means you may need to upgrade your server.
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
$ sudoapt-get update
$ sudoapt-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. Please note, you can use HTTP as well as HTTPS urls in ab command above.
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.
3. Interpret Results
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.
The results of Apache bench is divided into different sections. The first 8 lines describe your server and load testing setup. The next 10 lines give you the number of requests that were sent, number of completed and failed requests, amount of data transferred, requests per second, mean amount of time for each request, data transfer rate.
The next section gives a statistical analysis of connection times – amount of time to connect, wait and process requests. For each of these parameters, it calculates the min, max, mean and median values.
The last section gives a statistical distribution of the percent of requests served within a given time. It is useful to find out that percent of requests
4. Important Points
There are a few things to keep in mind while running load testing in any server, including Apache.
- It is advisable to incrementally increase load and concurrency instead of starting with high value. If your test fails for a specific number of requests of concurrency, try reducing it and running the test again.
- If you get ‘too many open files’ error, it means your server has reached concurrency limit.
- Sometimes, your server may stop responding even at low loads. Use other commands like top or htop to determine if your server is busy processing other things. If that is the case, terminate those applications and run the test again.
Conclusion
Hopefully, this article will help you set up and run load testing for Apache web server. Basically, it tells you how many requests your server can handle, over what amount of time and at what speed. It is essential to run load testing periodically to monitor how your server responds to growing traffic. It is equally important to do load testing after rolling major updates to see if it slows down your website. For example, if you have installed a new WordPress theme or plugin, then you will need to run load tests. Since most of the blogs, ecommerce platforms and CMS systems run on Apache server, it is a very useful tool for almost every web development team.
Ubiq makes it easy to visualize data, and monitor them in real-time dashboards. Try Ubiq for free.
Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI & software development.