Load Testing and Benchmarking with Siege

Posted on Thu Sep 10 2020

Siege is a great open-source tool to analyze loads in HTTP requests and benchmark server performance.

What is load testing?

Load testing is a form of non-functional testing, which will give you helpful insights about at what point your website will crash.

There's a lot of tools that you can use to perform load and stress testing. We are going to focus on Siege.

Siege allows you to hit a web server with a configurable number of concurrent simulated users.

To demonstrate, I have a simple Rails application, with just one route and one controller.

# routes.rb
get '/pages', to: 'pages#index'
# pages_controller.rb
def index
render json: { hello: :world }

First, install Siege in your system, start the rails server, then run this command:

siege -b --content-type 'application/json' -c 50 -r 40 'http://localhost:3000/pages'

This command will simulate 50 users hitting http://localhost:3000/pages URL, for 40 times repetition for every user.

Siege will take a few seconds to run the simulation and will generate this report:

** SIEGE 4.0.4
** Preparing 50 concurrent users for battle.
The server is now under siege...
Transactions: 2000 hits
Availability: 100.00 %
Elapsed time: 252.99 secs
Data transferred: 0.03 MB
Response time: 6.25 secs
Transaction rate: 7.91 trans/sec
Throughput: 0.00 MB/sec
Concurrency: 49.41
Successful transactions: 2000
Failed transactions: 0
Longest transaction: 7.33
Shortest transaction: 0.38

You will notice that Siege runs 2000 hits on your server, which is the number of 50 users hitting the sever each for 40 times.

Check Siege documentation for more more description on the generated statistics.

If you found yourself running this command frequently, you can create a the script inside the bin folder to automate this task.

#! /bin/bash
siege -b --content-type $CONTENT_TYPE -c $CONCURRENCY -r $REPS $URL

Now, you can run this script by just typing bin/siege.sh in your terminal.


© 2020 Muhammad Ebeid. This site is powered by Netlify