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.rbget '/pages', to: 'pages#index'# pages_controller.rbdef indexrender json: { hello: :world }end
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 hitsAvailability: 100.00 %Elapsed time: 252.99 secsData transferred: 0.03 MBResponse time: 6.25 secsTransaction rate: 7.91 trans/secThroughput: 0.00 MB/secConcurrency: 49.41Successful transactions: 2000Failed transactions: 0Longest transaction: 7.33Shortest 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/bashREPS=40CONCURRENCY=50CONTENT_TYPE='application/json'URL='http://localhost:3000/pages'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.