When your run a webserver, which could be Apache, Nginx or Lighttpd, you may want to know how it is performing.
Actually usually any web server can handle a normal day of work, but what happens when the server under your administration gets, stumbled, or appears in Slashdot, or digg front pages, now a days even twitter may drive a lot of traffic to a webpage.
If that event occurs your server will be under real stress, and it is in that day when you want it to perform well, and survive the “attack”.
It is usually not possible to know how it will do that day, until the D. day arrives, but you can figure out how it will be.
We will use ab, which is a tool that comes with Apache is the Apache Benchmarking tool.
First let’s see what we need.
- The server you want to test with some different files
- Simple html file
- Simple php file
- Simple image file
- Another computer with Apache installed (The one which will run the ab test) Be sure to have a good Bandwidth between the two of them, you can use iperf to check the network connection before
Lets create the files we are going to use for testing.
The .html file
<html>
<title>Simple HTML file for testing server</title>
<h1>Heading number 1</h1>
<p>With this file I will test an Apache server</p>
<p><a href="http://www.go2linux.org">Linux Operating System</p>
</html>
The .php file
<html>
<Title>PHP info</title>
<?php
// Show all information, defaults to INFO_ALL
phpinfo();
// Show just the module information.
// phpinfo(8) yields identical results.
phpinfo(INFO_MODULES);
?>
</html>
The image file
The image file is a .jpg file of 72252 bytes
Now go with the tests
It is assumed that you have put those files in the server you want to test, I have put myself in /tmp/ directory under the root directory of my server.
ab -kc 1000 -n 10000 http://www.some-site.cc/tmp/index.html
This will send 1000 concurrent connections 10.000 times, the results are shown like this.
This is ApacheBench, Version 2.0.41-dev <$Revision: 1.141 $> apache-2.0
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 2006 The Apache Software Foundation, http://www.apache.org/
Benchmarking www.some-site.cc (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Finished 10000 requests
Server Software: Apache/2.2.9
Server Hostname: www.some-site.cc
Server Port: 80
Document Path: /tmp/index.html
Document Length: 207 bytes
Concurrency Level: 1000
Time taken for tests: 6.571282 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Keep-Alive requests: 9923
Total transferred: 5744865 bytes
HTML transferred: 2083869 bytes
Requests per second: 1521.77 [#/sec] (mean)
Time per request: 657.128 [ms] (mean)
Time per request: 0.657 [ms] (mean, across all concurrent requests)
Transfer rate: 853.71 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 3 26.1 0 225
Processing: 1 69 482.3 12 5947
Waiting: 0 68 482.3 12 5946
Total: 1 72 504.3 12 6143
Percentage of the requests served within a certain time (ms)
50% 12
66% 17
75% 21
80% 21
90% 37
95% 39
98% 130
99% 2647
100% 6143 (longest request)
Now run it with the php file.
ab -kc 1000 -n 10000 http://www.some-site.cc/tmp/index.php
The results are:
This is ApacheBench, Version 2.0.41-dev <$Revision: 1.141 $> apache-2.0
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 2006 The Apache Software Foundation, http://www.apache.org/
Benchmarking www.some-site.cc (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Finished 10000 requests
Server Software: Apache/2.2.9
Server Hostname: www.some-site.cc
Server Port: 80
Document Path: /tmp/index.php
Document Length: 62446 bytes
Concurrency Level: 1000
Time taken for tests: 157.530617 seconds
Complete requests: 10000
Failed requests: 21
(Connect: 0, Length: 21, Exceptions: 0)
Write errors: 0
Keep-Alive requests: 0
Total transferred: 628658346 bytes
HTML transferred: 626254006 bytes
Requests per second: 63.48 [#/sec] (mean)
Time per request: 15753.062 [ms] (mean)
Time per request: 15.753 [ms] (mean, across all concurrent requests)
Transfer rate: 3897.17 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 3898 9601.3 132 93114
Processing: 711 4816 9077.5 2852 151641
Waiting: 96 4079 8403.1 2434 147921
Total: 964 8715 13258.0 4959 152406
Percentage of the requests served within a certain time (ms)
50% 4959
66% 6265
75% 8895
80% 11189
90% 19319
95% 25519
98% 50649
99% 69027
100% 152406 (longest request)
And finally go for the image file, the results are:
This is ApacheBench, Version 2.0.41-dev <$Revision: 1.141 $> apache-2.0
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 2006 The Apache Software Foundation, http://www.apache.org/
Benchmarking www.some-site.cc (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Finished 10000 requests
Server Software: Apache/2.2.9
Server Hostname: www.some-site.cc
Server Port: 80
Document Path: /tmp/38_TaylorSwift.jpg
Document Length: 72252 bytes
Concurrency Level: 1000
Time taken for tests: 30.131674 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Keep-Alive requests: 10000
Total transferred: 730617980 bytes
HTML transferred: 726894150 bytes
Requests per second: 331.88 [#/sec] (mean)
Time per request: 3013.167 [ms] (mean)
Time per request: 3.013 [ms] (mean, across all concurrent requests)
Transfer rate: 23679.20 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 5 49.6 0 552
Processing: 311 440 153.4 422 5346
Waiting: 7 190 172.0 201 4912
Total: 311 446 184.0 422 5898
Percentage of the requests served within a certain time (ms)
50% 422
66% 433
75% 455
80% 460
90% 474
95% 496
98% 566
99% 820
100% 5898 (longest request)
Now let’s have the output explained, the most of it is self explaining, but let’s go to some of the most important points you may care about.
For the html file
- Requests per second: 1521.77 [#/sec] (mean)
- Time per request: 657.128 [ms] (mean)
For the php file
- Requests per second: 63.48 [#/sec] (mean)
- Time per request: 15753.062 [ms] (mean)
For the image file
- Requests per second: 331.88 [#/sec] (mean)
- Time per request: 3013.167 [ms] (mean)
As you can see, for a single .html file the server can serve 1521 requests per second, for the image size it can 331 requests per second, mostly because of the size of the image, but for the .php it can only attend 63 requests per second, because it involves too much CPU work, If MySQL would be involved, we might see an even poorer performance, the time per request is also another good parameter to look at, as it lets you see the time the server needs to send the page to the user.
would be a good idea to also run htop while running the “traffic generator” test over the web server.
That way, you will also see how your CPU is managing the load, here is an example of how this small vmware on Debian server is doing its job.
Ref: https://www.garron.me/en/go2linux/how-benchmark-stress-your-apache-nginx-or-iis-server.html