Tuesday 16 January 2007 1:33:00 pm
Siege is useful for checking the performance of a web application in an environment similar to what visitors encounter. While most tools find the maximum number of pages served per second, siege can also simulate random wait intervals, thus mimicking real user interactions where requests are not generated at regular intervals.
You can set up a script of different URLs to be benchmarked. Siege even supports GET and POST as well as cookies, so you can create sessions that emulate logged-in users.
The most basic siege test is specifying the concurrency level and the number of times to repeat the test. The command below shows how you can run siege with a concurrency level of 4 and repeat the test 10 times for the given URL.
# siege -b -c 4 -r 10 -u http://192.168.0.3/base/lots_of_content/parturient_id Transactions: 40 hits Availability: 100.00 % Elapsed time: 1.04 secs Data transferred: 1196640 bytes Response time: 0.10 secs Transaction rate: 38.46 trans/sec Throughput: 1150615.43 bytes/sec Concurrency: 3.78 Successful transactions: 40 Failed transactions: 0 Longest transaction: 0.11 Shortest transaction: 0.08
For benchmarking, always use the -b or -benchmark parameter. If this is not specified, siege will insert a random delay to simulate actual user traffic.
You can also test for a given time period by using the -t parameter instead of -r (repeats). This specifies that the testing should be done for x number of seconds, minutes or hours (S, M, H).
For example, you can run the same test above but for 10 seconds:
# siege -b -c 4 -t 10S -u http://192.168.0.3/base/lots_of_content/parturint_id Transactions: 411 hits Availability: 100.00 % Elapsed time: 10.18 secs Data transferred: 12295476 bytes Response time: 0.10 secs Transaction rate: 40.37 trans/sec Throughput: 1207807.04 bytes/sec Concurrency: 3.96 Successful transactions: 411 Failed transactions: 0 Longest transaction: 0.11 Shortest transaction: 0.08
For more realistic tests of webserver traffic, use the urls.txt file, which can, for example, be stored in the root of your home folder. This file is a collection of URLs that will be used for testing. To create a test where you fetch 10 different URLs, you can use the urls.txt file as shown below. (Note that the first line is not part of the contents of the file.)
# cat urls.txt http://192.168.0.4/base/lots_of_content/venenatis_cras http://192.168.0.4/base/lots_of_content/egestas_commodo http://192.168.0.4/base/lots_of_content/parturient_id http://192.168.0.4/base/lots_of_content/curae http://192.168.0.4/base/lots_of_content/ut http://192.168.0.4/base/lots_of_content/mattis_facilisis http://192.168.0.4/base/lots_of_content/torquent_ante http://192.168.0.4/base/lots_of_content/quam_urna http://192.168.0.4/base/lots_of_content/parturient_aptent http://192.168.0.4/base/lots_of_content/quis
siege can then be run as follows:
siege -b -r 10 -c 4 Transactions: 40 hits Availability: 100.00 % Elapsed time: 1.45 secs Data transferred: 1555332 bytes Response time: 0.14 secs Transaction rate: 27.59 trans/sec Throughput: 1072642.72 bytes/sec Concurrency: 3.83 Successful transactions: 40 Failed transactions: 0 Longest transaction: 0.15 Shortest transaction: 0.11
Sproxy is a handy utility that harvests a list of URLs that can be used for benchmarking. It includes all files sent from the server, including images and CSS files.
After installing and starting sproxy, it will start a listening proxy on port 9001 on your computer. In your web browser, choose localhost and port 9001 for your proxy settings. Sproxy will then log all your web activity in the file urls.txt in your home folder.
The output of sproxy looks like this:
$ /usr/local/bin/sproxy SPROXY v1.01 listening on port 9001 ...appending HTTP requests to: /Users/bf/urls.txt ...default connection timeout: 120 seconds
The recorded values in urls.txt might look something like this:
http://10.0.2.83/base/forums/small_talk http://10.0.2.83/design/base/images/sticky-16x16-icon.gif http://10.0.2.83/base/user/login http://10.0.2.83/base/user/login POST Login=admin&Password=publish&LoginButton=Login&RedirectURI=
Then you can simply run siege as normal, using this newly generated URLs file.