Using Siege to Benchmark API endpoints

Siege is a really useful command line tool for *nix based systems that “is an http load testing and benchmarking utility”. While its not something your likely to use for mass performance testing it is good for quickly testing specific http endpoints.

While optimising some secured API enpoints recently it became very labourious trying to build out command line arguments that reflect normal browser requests.

It then occured to me that you can simply ‘right-click’ a resource in chrome and ‘Copy as cURL’.

Chrome - Copy As Curl

###Chrome cURL request

curl 'https://api.foobar.net/project/53353ea635d6b6500f0fbc48/minutes-worked' -H 'Pragma: no-cache' -H 'Origin: https://www.foobar.net' -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8' -H 'Authorization: Bearer 644264b6fa67564dddb3fb31d84909ea8e6988dd' -H 'Content-Type: application/json' -H 'Accept: application/json, text/plain, */*' -H 'Cache-Control: no-cache' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.65 Safari/537.36' -H 'Connection: keep-alive' -H 'Referer: https://www.foobar.net/' -H 'DNT: 1' --compressed

With a bit of simple modification the above request can be turned into a siege command.

###Modified for siege

siege -c 10 -r 10 -b -H 'Pragma: no-cache' -H 'Origin: https://www.foobar.net' -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8' -H 'Authorization: Bearer 0b4e405d37869c068ef26907b1ae9edb256407b0' -H 'Content-Type: application/json' -H 'Accept: application/json, text/plain, */*' -H 'Cache-Control: no-cache' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.65 Safari/537.36' -H 'Connection: keep-alive' -H 'Referer: https://www.foobar.net/' -H 'DNT: 1' https://api.foobar.net/project/53353ea635d6b6500f0fbc48/minutes-worked

If you look closely between the 2 snippets you’ll see that:

  • the request URL has been moved to the end
  • –compressed has been removed
  • curl has been replaced with siege -c 10 -r 10 -b

Pasting this into a command line window will run a simulation with 10 users (-c) for 10 repetitions (-r) for a total of 100 transactions, the output will look something like:

Siege request, 100 transactions

The output shows us (amongst other things) that all requests were a success, that the API was able to respond to 11.52 transactions per second and that we waited between 0.26 and 1.71 seconds per transaction.

Lovely Jubbly.

Ben Squire

Read more posts by this author.

Leicestershire, United Kingdom https://squired.co.uk