ThorneLabs

Using siege to Load Test Your Website and API

• Updated May 5, 2020


ab, Apache Bench, is often used to load test websites, but I didn’t find it extensible enough for my needs.

Unless an unofficial patch is applied, ab cannot simulate a real person by going to random URLs over a specified period of time. This is where siege comes in.

Install siege

siege should be available in most popular package management systems and is an apt-get install, yum install, or brew install away.

Once siege is installed, get familiar with its features by running siege --help or by reading the man page.

Load Testing Your Website

Gather all the URLs an enduser might go to on your website and put those URLs into a text file.

For example, create a file called urls.txt with the following content:

http://example.com/this-is-example-one.html
http://example.com/this-is-example-two.html
http://example.com/this-is-example-three.html
http://example.com/this-is-example-four.html
http://example.com/this-is-example-five.html
http://example.com/this-is-example-six.html

With the text file created containing all your URLs, it’s time to run siege.

The following command will create 50 concurrent connections (scale up the concurrent connections if needed), the --internet command line switch will attempt to simulate a real person for each of those connections by randomly going to URLs in the text file you created above, and the text file is specified with the --file command line switch.

siege --concurrent=50 --internet --file urls.txt

You can stop the command at any time and it will output a report. Alternatively, specify a time to run the test with the --time command line switch.

Load Testing Your API

siege can also be used to load test your API.

Instead of gathering a bunch of URLsĀ and having siege randomly access them, you will likely be hitting a single URL endpoint and POSTing data to it.

The following command will create 50 concurrent connections and POST plain text data - plain-text-content-here - to the URL specified:

siege --concurrent=50 --content-type="text/plain" 'http://example.com/api POST plain-text-content-here'

If your API accepts JSON instead of plain text, use the following command instead:

siege --concurrent=50 --content-type="application/json" 'http://example.com/api POST {"key1":"value1","key2":"value2"}'

Additionally, you can POST JSON data from a file:

siege --concurrent=50 --content-type="application/json" 'http://example.com/api POST < /path/to/json-file.txt'

Once again, you can stop the command at any time and it will output a report. Alternatively, specify a time to run the test with the --time command line switch.

References

If you found this post useful and would like to help support this site - and get something for yourself - sign up for any of the services listed below through the provided affiliate links. I will receive a referral payment from any of the services you sign-up for.

Get faster shipping and more with Amazon Prime: About to order something from Amazon but want to get more value out of the money you would normally pay for shipping? Sign-up for a free 30-day trial of Amazon Prime to get free two-day shipping, access to thousands of movies and TV shows, and more.

Thanks for reading and take care.