Polls

Topics

Howto: Performance Benchmarks a Web server

Posted by Vivek on Friday June 9, 06 @1:13 pm

You can benchmark Apache, IIS and other web server with apache benchmarking tool called ab. Recently I was asked to performance benchmarks for different web servers.

It is true that benchmarking a web server is not an easy task. From how to benchmark a web server, "First, benchmarking a web server is not an easy thing. To benchmark a web server the time it will take to give a page is not important: you don't care if a user can have his page in 0.1 ms or in 0.05 ms as nobody can have such delays on the Internet.

What is important is the average time it will take when you have a maximum number of users on your site simultaneously. Another important thing is how much more time it will take when there are 2 times more users: a server that take 2 times more for 2 times more users is better than another that take 4 times more for the same amount of users."

Here are few tips to carry out procedure along with an example:

Procedures

Example:

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 202.54.200.1) in /var/www/html (or use your own webroot):

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

Login to Linux/bsd desktop computer and type following command:
$ ab -n 1000 -c 5 http://202.54.200.1/snkpage.html
Where,

For example if you want to send 10 request, type following command:
$ ab -n 10 -c 2 http://www.somewhere.com/

Output:

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) 1998-2002 The Apache Software Foundation, http://www.apache.org/

Benchmarking www.cyberciti.biz (be patient).....done

Server Software:
Server Hostname:        www.somewhere.com
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 http://202.54.200.1/snkpage.html

c) Plot graph using Spredsheet 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 http://202.54.200.1/snkpage.html

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 http://202.54.200.1/snkpage.html

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 http://202.54.200.1/snkpage.html

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 http://202.54.200.1/snkpage.html

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

Sample test.php file

<html>
<head><title>Php test with phpinfo()</title></head>
<body>
<?
phpinfo();
?>
</body>
</html>

Run ab command as follows:

$ ab -n 500 -c 5 http://202.54.200.1/test.php

Sample test.pl (perl) file

#!/usr/bin/perl
$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 http://202.54.200.1/cgi-bin/test.pl

Sample psql.php (php+mysql) file

<html>
<head><title>Php+MySQL</title></head>
<body>
<?php
   $link = mysql_connect("localhost", "USERNAME", "PASSWORD");
   mysql_select_db("DATABASE");

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

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

    mysql_close($link);
?>
</body>
</html>

Run ab command as follows:
$ ab -n 1000 -c 5 http://202.54.200.1/psql.php

Do you use any other tool for same purpose? Let me know...

Want to stay up to date with the latest Linux tips, news and announcements? Subscribe to our free e-mail newsletter or full RSS feed to get all updates. You can Email this page to a friend.

You may also be interested in...

Discussion on This Article:

  1. Better Programmer Says:

    1689ms per page view? That’s 1.7 secords, and an appalling figure for a production website… Doctor, heal theyself

    You really need to spend some time profiling your web app. Repeat after me:

    It ‘just works’ is not enough — it must work well!

  2. nixcraft Says:

    Better Programmer,

    LOL the above output is not from a real box. It is just includes so that readers can understand the output.

  3. Sean Says:

    Thanks for the look at “ab”. I agree the more important metric is the average response time under production load.

    Based on some scripts I use myself, I wrote a tutorial on how to monitor the response time of a real world load (though there’s nothing saying it couldn’t be used alongside ab or siege)

    http://www.ibm.com/developerworks/edu/dw-esdd-webperfrrd-i.html

    I’ve also got an article going up on the same site in the near future that uses truss/strace to profile Apache and the configuration, in case you’re really concerned about performance.

  4. nixcraft Says:

    Sean,

    Thanks for sharing information and tutorial.

    There is lot of discussion going on about Sun Solaris dtrace http://www.sun.com/bigadmin/content/dtrace/

    Unfortunately, it is not available for Linux :(

  5. Zydoon Says:

    Hello,

    for better monitoring of the webserver behavior, you can take a look at ganglia, it’s more accurate than ps, top or uptaime (even if it is better used for clusters)

    I suggest you httperf, I find it better than ab, just because I can play scenarii for testing.

    And finally, thank you for this introduction of ab, I’m giving it a try (I’m benchmarking a web cluster).
    Zydoon.

  6. nixcraft Says:

    Zydoon,

    Thanks for suggestion.

  7. juantomas Says:

    I wonder if you know about an script for gnuplot to process the information obtained with the g option.

    Thanks for the post good work!!

  8. Sakthi Says:

    Sir,
    Now i am using Apache ab to benchmark the search server in an websit. Now currently i can use n number of request and n of cuncurrency to search a same word.My problem is i want search n number of words with n number of request and cuncurrency, give me a solution.

    Thanks in advance
    M.Sakthi

  9. Kapil Krishnan CPK Says:

    Hi,

    I am getting different result for the same command
    ab -n 300 -c 2 http://203.168.1.15/KAPIL/queryTest.php
    and at different time. May I please know why it happends like this?

    Thanks & Regards

    Kapil Krishnan CPK

  10. vivek Says:

    Is it a production box?

  11. China Landscape Says:

    What is the ab command exactly ?

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , , , , , , ~ Last updated on: October 25, 2007

Copyright © 2004-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.