ApacheBench (ab) is a very handy webserver benchmarking tool which can be run from command line. It is extremely simple to use. A quick outcome can be obtained in just one minute. It does not require too much much familiarity with load and performance testing concepts. No complex setup is required. It gets installed automatically with apache. It does not have all the features of more popular tools, but it is good for a start.
Environment for the test
If you do not know what A/B testing is about, take a quick look at the Wikipedia page on that subject. Long story short, the idea is to serve two different version of a page to your visitors. Apache Bench, or ‘ab’, is a very powerful, and yet simple to use command line utility for measuring the performance of your application under certain load. It is a freeware and bundled with Apache web server. Apache Bench also has the capability to measure following performance key metrics: Throughput; Response Time; No of concurrent users load.
If you do not know what A/B testing is about, take a quick look at the Wikipedia page on that subject. Long story short, the idea is to serve two different version of a page to your visitors and check which one is getting the most success. When you found which version is better, you can definitely switch to it. AB is Apache’s HTTP service testing tool, which can test the performance of your HTTP server, especially the number of requests processed per second. AB can not only do stress tests on Apache servers, but also on other types of servers. For example, nginx, Tomcat, IIS, etc. Load testing your API by using just ab is not enough. However, I think it's a great tool to give you a basic idea how your site is performant. If you want to use the ab command in to test multiple API endpoints, with different data, all at the same time in background, you need to use 'nohup' command.
Here is the setup I used:
OS: Ubuntu server 12.04.1 LTS (LTS stands for Long term support)
AWS details: Micro instance in california
Site software: WordPress 3.5.1 with w3 total cache installed (using page cache in memcache)
Web server: Apache 2.2.2 (prefork)
Running ApacheBench locally on web server machine
Run it on same server as your webserver using this command:
This will run it for 500 requests in total with 100 current requests. Here are some points to note: Surface go 2 remote desktop.
You can increase the total requests. It should always be more than number of concurrent requests.
You can also add -H 'Accept-Encoding: gzip,deflate' to more closely emulate real requests. But as we are on same server and there is no network overhead, it will not matter too much.
For such high number of request the test should be done locally or on same LAN (Local Area Network). Otherwise you may get bad results due to network latency and you may think its your server problem. In reality all you concurrent users won’t come from one machine.
This tests does not emulate the real environment fully. But it is good enough to help you find out most of the major problems in your site.
Testing outcome from ApacheBench
Here is the outcome for above command on my server:
Analysis of the ApacheBench load testing output
Here are my observation about the outcome
Total data transferred is 12305000 bytes for 500 requests. Close to 20K per page (un-compressed). Which is inline with my home page size.
Test completed in 8.978. No failed requests. Very good number I think.
Requests per seconds: 55.69. Pretty good number.
Time per request: 1795.684 milli-seconds (for 100 concurrent requests). So across all requests it is 1795.684ms/100 = 17.957ms
Transfer rate: 1338.39 [Kbytes/sec] received. Since we ran the test on same machine, this number was expected to be high and can be ignored.
In connection time stats, you can see many requests had to wait for few seconds. This may be due to apache putting requests in wait queue.
Overall test results are good. This test does not really tested the network latency. But it primarily tested if 100 concurrent requests reached to the web server, how does it perform.
Plotting the outcome of ApacheBench
I generated the graph data for plotting using this command: Skype for business.
And then plotted it using gnuplot. Here is the outcome.
Suggested posts:
Apache bench (also called Apache benchmark) is a useful 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.
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
CentOS/Redhat/Fedora
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.
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.
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
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.
Apache Ab Install
After Apache bench runs the tests, it will produce an output like the following.
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.
Apache Ab Test
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.
Hopefully, this article will help you set up and run load testing for Apache web server. Ubiq makes it easy to visualize data, and monitor them in real-time dashboards. Try Ubiq for free.