Sunday, November 25, 2012

Howto: Performance Benchmarks a Webserver

Apache Benchmark Procedures

You need to use same hardware configuration and kernel (OS) for all tests
You need to use same network configuration. For example, use 100Mbps port for all tests
First record server load using top or uptime command
Take at least 3-5 readings and use the best result
After each test reboot the server and carry out test on next configuration (web server)
Again record server load using top or uptime command
Carry on test using static html/php files and dynamic pages
It also important to carry out test using the Non-KeepAlive and KeepAlive (the Keep-Alive extension to provide long-lived HTTP sessions, which allow multiple requests to be sent over the same TCP connection) features
Also don't forget to carry out test using fast-cgi and/or perl tests
Webserver Benchmark Examples:

Let us see how to benchmark a Apache 2.2 and lighttpd 1.4.xx web server.

Static Non-KeepAlive test for Apache web server
i) Note down server load using uptime command
$ uptime

ii) Create a static (small) html page as follows (snkpage.html) (assuming that server IP is in /var/www/html (or use your own webroot):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<title>Webserver test</title>
This is a webserver test page.

Login to Linux/bsd desktop computer and type following command:
$ ab -n 1000 -c 5


-n 1000: ab will send 1000 number of requests to server in order to perform for the benchmarking session
-c 5 : 5 is concurrency number i.e. ab will send 5 number of multiple requests to perform at a time to server
For example if you want to send 10 request, type following command:
$ ab -n 10 -c 2


This is ApacheBench, Version 2.0.41-dev <$Revision: 1.141 $> apache-2.0
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd,
Copyright (c) 1998-2002 The Apache Software Foundation,
Benchmarking (be patient).....done
Server Software:
Server Hostname:
Server Port:            80
Document Path:          /
Document Length:        16289 bytes
Concurrency Level:      1
Time taken for tests:   16.885975 seconds
Complete requests:      10
Failed requests:        0
Write errors:           0
Total transferred:      166570 bytes
HTML transferred:       162890 bytes
Requests per second:    0.59 [#/sec] (mean)
Time per request:       1688.597 [ms] (mean)
Time per request:       1688.597 [ms] (mean, across all concurrent requests)
Transfer rate:          9.59 [Kbytes/sec] received
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:      353  375  16.1    386     391
Processing:  1240 1312  52.1   1339    1369
Waiting:      449  472  16.2    476     499
Total:       1593 1687  67.7   1730    1756
Percentage of the requests served within a certain time (ms)
  50%   1730
  66%   1733
  75%   1741
  80%   1753
  90%   1756
  95%   1756
  98%   1756
  99%   1756
 100%   1756 (longest request)
Repeat above command 3-5 times and save the best reading.

Static Non-KeepAlive test for lighttpd web server
First, reboot the server:
# reboot

Stop Apache web server. Now configure lighttpd and copy /var/www/html/snkpage.html to lighttpd webroot and run the command (from other linux/bsd system):
$ ab -n 1000 -c 5

c) Plot graph using Spreadsheet or gnuplot.

How do I carry out Web server Static KeepAlive test?

Use -k option that enables the HTTP KeepAlive feature using ab test tool. For example:
$ ab -k -n 1000 -c 5

Use the above procedure to create php, fast-cgi and dynmic pages to benchmarking the web server.

Please note that 1000 request is a small number you need to send bigger (i.e. the hits you want to test) requests, for example following command will send 50000 requests :
$ ab -k -n 50000 -c 2

How do I save result as a Comma separated value?

Use -e option that allows to write a comma separated value (CSV) file which contains for each percentage (from 1% to 100%) the time (in milliseconds) it took to serve that percentage of the requests:
$ ab -k -n 50000 -c 2 -e apache2r1.cvs

How do I import result into excel or gnuplot programs so that I can create graphs?

Use above command or -g option as follows:
$ ab -k -n 50000 -c 2 -g apache2r3.txt

Put following files in your webroot (/var/www/html or /var/www/cgi-bin) directory. Use ab command.

Sample test.php file

$command=`perl -v`;
$title = "Perl Version";

print "Content-type: text/html\n\n";
print "<html><head><title>$title</title></head>\n<body>\n\n";

print "<h1>$title</h1>\n";
print $command;

print "\n\n</body></html>";

Run ab command as follows:
$ ab -n 3000 -c 5

Sample psql.php (php+mysql) file

   $link = mysql_connect("localhost", "USERNAME", "PASSWORD");

   $query = "SELECT * FROM TABLENAME";
   $result = mysql_query($query);

   while ($line = mysql_fetch_array($result))
      foreach ($line as $value)
         print "$value\n";


Run ab command as follows:
$ ab -n 1000 -c 5

1 comment:

Anonymous said...

What's up it's me, I am also visiting this web site on a regular basis, this website is really fastidious and the visitors are actually sharing pleasant thoughts.
Feel free to surf my webpage : The Truth Teller show