Category Archives: Stress Testing

Apachebench Tutorial ab testing Tool Example in Ubuntu/Linux

Official Apache Page

Is there a time when you are thinking how to do a server load testing to evaluate your PHP web application performance? This is where you will be using the Apachebench or “ab” testing tool. This is a very useful open source tool not only to PHP developers but to the entire users of the Apache server. This tool is used to evaluate the execution times of your PHP web application or the response time of your website under “stressing” conditions. This condition means how your PHP web application will perform under conditions similar to what exactly will be happening on a real web server not just on your local host environment (such as XAMPP). For example in actual website deployment in a production server; it will be subjected to two stressing conditions:

a.) Number of connections to that application – these are the number of visitors to your website which are connected to that application. The higher the number of visitors to that application, the higher also the number of connections. This is a stressing condition because sometimes if your PHP web application in your website is poorly written, it will result to a very poor performance in actual deployment which can slowed down if there are a lot of users in your website.

b.) Number of concurrent users – these are the actual number of users that are using the application at exactly the same time. Of course in a very low traffic website, the concurrent users is almost zero because the probability that two users will exactly hit the application and do the same request is very small. This can be an issue with high traffic websites; it is because the number of concurrent users can slowed down the application and put a signficant load on the web server. Some web host even limits the number of concurrent users (typically those that are originating from a free web hosting scheme).

The good thing with Apachebench is that you measure the performance of a certain web application or website given a stress conditions. The stressing conditions required by Apache bench are two above. What is expected to happen is that a poorly written PHP web application will perform poorly under stressing conditions. This is why performance benchmarks of CMS, PHP frameworks, etc are using ab testing to evaluate the quality of the application.

How to Get Started with AB testing tool in Linux/Ubuntu:

Below are the steps :

1.) In Ubuntu, Apachebench can be installed using the Apache 2 utils. Go to Applications – Accessories – Terminal, at the command prompt type:

sudo apt-get install apache2-utils

2.) After installation, you are now ready to use Apachebench. Lets have an example. Supposing you will need to know how wordpress.org performs when there are 300 connections and 3 concurrent users. First, this is the syntax of ab:

ab -n [number of connections] -c [number of concurrent users] [url]

3.) Using the syntax above for ab test, below is the final command to type in the shell prompt:

ab -n 300 -c 3 https://wordpress.org/

4.) Below are the results, you should see in your terminal:

This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, https://www.zeustech.net/
Licensed to The Apache Software Foundation, https://www.apache.org/

Benchmarking wordpress.org (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Finished 300 requests


Server Software:        nginx
Server Hostname:        wordpress.org
Server Port:            80

Document Path:          /
Document Length:        9172 bytes

Concurrency Level:      3
Time taken for tests:   72.917 seconds
Complete requests:      300
Failed requests:        296
   (Connect: 0, Receive: 0, Length: 296, Exceptions: 0)
Write errors:           0
Total transferred:      2789682 bytes
HTML transferred:       2743782 bytes
Requests per second:    4.11 [#/sec] (mean)
Time per request:       729.172 [ms] (mean)
Time per request:       243.057 [ms] (mean, across all concurrent requests)
Transfer rate:          37.36 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:      214  225   6.8    224     253
Processing:   448  502 177.6    486    3481
Waiting:      221  252 175.9    237    3232
Total:        670  728 179.0    710    3722

Percentage of the requests served within a certain time (ms)
  50%    710
  66%    721
  75%    728
  80%    735
  90%    751
  95%    771
  98%    818
  99%    931
 100%   3722 (longest request)

Very important interpretation of results:

1.) It means it takes 3722ms for wordpress.org to serve longest request under a stressing conditions of 300 connections and 3 concurrent users. This is the longest response time.

2.) But on the “average” it will only take wordpress.org to respond within 728ms +- tolerance of 179 ms.

A more powerful and faster website can respond to faster times even with more stressing conditions. If you are using Windows, you can read this Apachebench tutorial using Windows OS.

Warning: Do not use Apachebench excessively to make enormous request to a web server that you do not own. This is a form of denial of service attack and can put you to jail: https://www.pcworld.com/businesscenter/article/181127/ex_ceo_charged_in_denial_of_service_attack.html