There are many tools for load testing your application. Some of these are free, open source solutions, while a few have commercial licenses. Siege is an open source utility, which can be used to stress test a server. It has been created by Jeff Fulmer and can be downloaded from http://www.joedog.org/siege-home.
Given a URL or a set of URLs, Siege can simulate the provided number of users to load test these locations. The utility generates metrics for the elapsed time, the total data transferred, the server response time, its transaction rate, its throughput, and its concurrency. Basically, the tool is aimed at generating server behavior when there is a traffic spike.
The latest version of Siege can be downloaded from http://download.joedog.org/siege/siege-latest.tar.gz. The .tar.gz
can then be extracted to build and install the latest version of the utility. At the time of writing the book, version 3.0.9 is the latest one:
$ wget http://download.joedog.org/siege/siege-latest.tar.gz $ tar -xvf siege-latest.tar.gz $ cd siege-3.0.9/ $ ./configure
The ./configure
command generates a configuration for Siege. The process checks for all required libraries. The command provides loads of options; use the -h
flag to list them. There are a few useful parameters that can be used to customize Siege. They are as follows:
prefix
: This installs Siege to the specified path and configures the default configuration files. If not specified, Siege is installed at /usr/local
.bindir
: This installs the binary in the specified directory.mandir
: This installs the man pages in the specified directory.with-ssl
: This lets Siege run for the HTTP protocol by default. If you want to use it for HTTPS, then OpenSSL is required. Siege tries to pick OpenSSL if it is available on the system; otherwise, one can be specified using this option.without-ssl
: This specifies that SSL support is not to be built in Siege.Post the ./configure
command, the tool can be installed by the following commands:
$ make $ sudo make install
The make
command generates the binary for the specified configuration, and make install
installs it to the system path. The process lists down the location where the installation has happened.
Post installation, Siege may not be available on your path if it is installed to an alternative location, such as /etc/siege
. In order to add it to the path, use the update-alternatives
command, as shown here:
$ sudo update-alternatives --install /usr/bin/siege siege /etc/siege/bin/siege1
Check Siege by running the following command:
$ siege -V
It should print the version as shown in the following output:
SIEGE 3.0.9 Copyright (C) 2014 by Jeffrey Fulmer, et al. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
The siege
command can be executed on the terminal. The command lists all kinds of parameters that are available. You could run the command on the page deployed in the previous chapter, as follows:
$ siege http://192.168.2.100/hello/
By default, Siege keeps running for quite a while and prints a lot of logging information. You will be required to press Ctrl + C to close the program. The program executes the default load and prints the performance results, as shown in the following code:
Transactions: 4443 hits Availability: 100.00 % Elapsed time: 149.94 secs Data transferred: 15.56 MB Response time: 0.00 secs Transaction rate: 29.63 trans/sec Throughput: 0.10 MB/sec Concurrency: 0.05 Successful transactions: 4443 Failed transactions 0 Longest transaction: 0.01 Shortest transaction: 0.00
In the preceding command, Siege executed the default configuration. Use the -C
or --config
options to find out your default configuration:
$ siege -C
A few interesting default parameters to look at are the following:
Since the default configuration does not specify the time to run or repetitions, the tool keeps executing until it finds the specified number of failures. You should edit the configuration file specified by the resource file and modify the defaults as per your requirements.
Alternatively, you could pass the parameters from the command line using the available options, for example:
$ siege -c 15 -r 10 -q http://192.168.2.100/
The preceding command puts a load of 15
users for about 10
iterations. The -q
option makes sure that Siege prints only the results and errors (if any).
There are certain parameters that cannot be controlled from the command-line options. The connection timeout is one such parameter. Set the timeout parameter value in the default configuration file located at /etc/siegerc
. Since the web server is on the local network, keep the value of the timeout quite low, for example, 5 or 10 seconds. After saving the file, run siege with the -C
option to list the configuration. It should list the timeout as follows:
CURRENT SIEGE CONFIGURATION Mozilla/5.0 (unknown-x86_64-linux-gnu) Siege/3.0.9 Edit the resource file to change the settings. ---------------------------------------------- version: 3.0.9 socket timeout: 10
The siege
command also defines a behavior for the test's execution. The following are the modes in which Siege can be executed:
-b
option to enable this mode of execution; optionally, set the benchmark property to true
.Before we start analyzing results, we need to make sure that the server is working at its peak. In order to do so, run Siege in benchmark mode with a large user count and with a moderate number of iterations. Alternatively, you could also use the -t
option to specify the time frame for which Siege should run. The test should be performed a couple of times, and the results should be averaged to create the metrics.
In order to determine the error rate and the throughput, make sure that we set a value for the timeout. After this, execute Siege with numbers until we start getting an error rate. Also, you need to make sure that Siege does not abort execution due to a large number of errors. If this causes an issue, increase the number of failures to a reasonable number to then arrive at a result. The following code shows this:
$ siege -b -c 790 -r 50 -q http://192.168.2.100/hello
The preceding code gives the following output:
[error] socket: read error Connection reset by peer sock.c:479: Connection reset by peer done. Transactions: 37164 hits Availability: 94.09 % Elapsed time: 14.29 secs Data transferred: 130.14 MB Response time: 0.19 secs Transaction rate: 2600.70 trans/sec Throughput: 9.11 MB/sec Concurrency: 492.12 Successful transactions: 37164 Failed transactions: 2336 Longest transaction: 5.02 Shortest transaction: 0.00
In order to determine the response time, run the same test but after removing the timeout set in Siege. The test will execute all transactions without any errors but will have a larger response time. Optionally, we could increase the users a little more and then determine the response time.
The results from Siege can be evaluated to form the metrics as follows:
3.136.17.12