O'Reilly logo

Web Performance Tuning, 2nd Edition by Patrick Killelea

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing Your Own Load Testing Tools

If you just want to give your server 100 hits, a simple way to do it is with the following shell script. Then take the difference between the start and end times output by the script and divide 100 by that time to get the number of hits per second you delivered to the web server. This script forks a new Lynx browser process for each hit, so the script is not efficient and the total running time is not very accurate, but you can see how easy it is to write a simple load generation tool in a Unix shell language.

#!/bin/bash
CNT=0
date
while [ "100" -ne "$CNT" ]
do
    lynx -source http://patrick.net/ > /dev/null &
    CNT=`expr $CNT + 1`
done
date

You could also write a similar tool in Java or Perl and get a more accurate reading and heavier generated load by eliminating Lynx startup time.

Here is a simple single-threaded load test script in Perl that hits a page and then sleeps 1/80th of a second, hits it again, sleeps another 1/80th of a second, etc., 100 times. If the page were infinitely fast, this should achieve a result of 80 hits in one second. Then the script does the same thing for 1/79th of a second, and so on, down to one second delays between attempts to get the page. In theory, we should be able to plot a nice load curve for any particular page like this, rising linearly at first, then flattening out as we approach the server’s performance limit for serial hits.

#!/usr/local/bin/perl -w use LWP::UserAgent; use Time::HiRes 'time','sleep'; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required