Load testing a website with Siege

~ 5 min read

I use to use Apache Bench (ab) for http load testing and benchmarking a website, but I more recently started to use Siege. The transition was driven by wanting to adopt a tool which could load test more than a single URL at one time, this is where Siege wins over Apache bench currently.

Siege also supports basic authentication, custom headers, cookies, HTTP, HTTPS and FTP protocols.

Siege has been compiled and run on AIX 4.x, GNU/Linux 2.2.x, HP-UX 11.x, and Solaris 2.x. Siege relies on UNIX-centric functionality. Due to this fact, it will not run natively on Microsoft Windows, but you can run it under cygwin. The latest version of siege is available via anonymous ftp from http://www.joedog.org/pub/siege.

If your on a Mac/OS X just use Homebrew to install Siege.

brew install siege

Benchmarking your websites performance

To get a feel for website through put we want to run Siege with option -b (benchmark). This sets the delay between user requests to zero. If you don't specify the -b option, Siege adds a one second delay between each request for each simulated user.

To avoid running the test forever we need to specify a time period, this is done using the -t option immediately followed by a time period of integer + letter H(our), S(econd) or M(minute). e.g.

  • -t10S (10 seconds)
  • -t15M (15 minutes)
  • -t1H (1 hour)

Putting it all together we have:

siege -b -t20S https://www.mydomain.com

Which if www.mydomain.com was real (ie. substitute your own in) we’d end up with test output like the following at the end.

** SIEGE 3.1.0
** Preparing 15 concurrent users for battle.
The server is now under siege...
...
Lifting the server siege...      done.
Transactions:             5290 hits
Availability:           <span style="color: #008000;">100.00</span> %
Elapsed time:            59.48 secs
Data transferred:        19.22 MB
Response time:            <span style="color: #008000;">0.17</span> secs
Transaction rate:        <span style="color: #008000;">88.94</span> trans/sec
Throughput:               0.32 MB/sec
Concurrency:             14.96
Successful transactions:  5290
Failed transactions:         0
Longest transaction:      0.59
Shortest transaction:     0.09

Which shows the test had 100% availability, and achieved an average of 88.94 requests per second with an average response time per request of 170ms.

Load testing your website with multiple URLs

Siege combined with New Relic (of which I'm a huge fan) can rapidly identify what parts of your application are taking all the time, and hence where you need to concentrate your efforts to improve performance.

So how does this change the command line options? We now want a more realistic delay between requests for this we can use -dinteger and also specify the concurrency (simultaneous user requests) we’re after with -cinteger. Bringing it all together the following:-

siege -d10 -c50 -t5M https://www.mydomain.com

Load tests, 50 concurrent requests, with random delays between requests of up to 10 seconds, over 5 minutes against the www.mydomain.com which will again produce output like the above after 5 minutes.

But we’re still testing only one URL which seems unrealistic, this is where siege comes into it’s own, if you create a text file of different URL’s one per line (option -f), you can get siege to randomly pick URL’s from it ( option -i) during a load test.

siege -d10 -c50 -t5M -i -f urls.txt

It’s a pretty nifty tool, it’s worth exploring it’s full option set

SIEGE 3.1.0
Usage: siege [options]
       siege [options] URL
       siege -g URL
Options:
  -V, --version             VERSION, prints the version number.
  -h, --help                HELP, prints this section.
  -C, --config              CONFIGURATION, show the current config.
  -v, --verbose             VERBOSE, prints notification to screen.
  -q, --quiet               QUIET turns verbose off and suppresses output.
  -g, --get                 GET, pull down HTTP headers and display the
                            transaction. Great for application debugging.
  -c, --concurrent=NUM      CONCURRENT users, default is 10
  -i, --internet            INTERNET user simulation, hits URLs randomly.
  -b, --benchmark           BENCHMARK: no delays between requests.
  -t, --time=NUMm           TIMED testing where "m" is modifier S, M, or H
                            ex: --time=1H, one hour test.
  -r, --reps=NUM            REPS, number of times to run the test.
  -f, --file=FILE           FILE, select a specific URLS FILE.
  -R, --rc=FILE             RC, specify an siegerc file
  -l, --log[=FILE]          LOG to FILE. If FILE is not specified, the
                            default is used: PREFIX/var/siege.log
  -m, --mark="text"         MARK, mark the log file with a string.
  -d, --delay=NUM           Time DELAY, random delay before each requst
                            between .001 and NUM. (NOT COUNTED IN STATS)
  -H, --header="text"       Add a header to request (can be many)
  -A, --user-agent="text"   Sets User-Agent in request
  -T, --content-type="text" Sets Content-Type in request

all posts →