Gatling Load Testing #1
Gatling is an open-source load- and performance-testing framework based on Scala, Akka and Netty. The first stable release was published on January 13, 2012. In 2015, Gatling’s founder, Stéphane Landelle, created a company dedicated to the development of the open-source project.
The software is designed to be used as a load testing tool for analyzing and measuring the performance of a variety of services, with a focus on web applications.
Wikipedia
Intro
The goal here is to introduce Gatling, to develop and show the process of how to loadtest this blog with Gatling.
There is at least three steps to start testing with Gatling. First is create and develop a testing script. Second, we launch Gatling and finally, we analyse the results.
Recorder
To create our first script, we need to install Gatling on a desktop computer.
I personally use Ubuntu. So here is the method I used to install it :
wget https://repo1.maven.org/maven2/io/gatling/highcharts/gatling-charts-highcharts-bundle/3.3.1/gatling-charts-highcharts-bundle-3.3.1-bundle.zip
unzip gatling-charts-highcharts-bundle-3.3.1-bundle.zip
sudo apt-get install default-jdk
cd gatling-charts-highcharts-bundle-3.3.1
Here the link for the latest version
I personally prefer the HAR method to start building our scenario. To do so with a browser, in my case with Firefox open network analysis (f12) check preserve log.
Now you can browse the website:
And save the HAR:
Once you’ve done that, open the recorder
/bin/bash bin/record.sh
- Switch from HTTP proxy to HAR converter
- Select the HAR location we saved before
- Paquage is like a folder in your project
- Class Name
- Chose a location for the scenario file usaly in the gatling project
- I expressly authorizing
.*blog\.prioli\.xyz.*
the goal is to exclude from our test the URLs of other websites in order to not being annoying and cause collateral damage. - Click on “No statics resources” button
a. Add .*\.svg
svg is not added by default the goal is to not polute the .scala file with statics files Gatling can automatically download following the HTML source code.
b. Add .*www\.google-analytics\.com.*
*I use google analytics on this website and .*blog\.prioli\.xyz.*
is unfortunately included in URLs like
.get(uri2 + "/r/collect?v=1&_v=j83&a=632110362&t=pageview&_s=1&dl=https%3A%2F%2Fblog.prioli.xyz%2F&ul=en-us&de=UTF-8&dt=Prioli.xyz&sd=24-bit&sr=1920x1080&vp=1844x574&je=0&_u=AACAAEAB~&jid=2080570898&gjid=1144507653&cid=1420700399.1596818544&tid=UA-71799904-1&_gid=306531910.1597349169&_r=1&z=1916348748")
So I needed to expressly exclude it
You can now clik on START !
Gatling
Now that we have our .scala scenario file generated, we can start to configure it and tune to match our needs.
The .scala file looks like this:
It’s still a good idea to version that in a git repository like here
We need to delete our blacklist in order to make gatling able to download statics files :
.inferHtmlResources(WhiteList(""".*blog\.prioli\.xyz.*"""), BlackList(""".*\.js""", """.*\.css""", """.*\.gif""", """.*\.jpeg""", """.*\.jpg""", """.*\.ico""", """.*\.woff""", """.*\.woff2""", """.*\.(t|o)tf""", """.*\.png""", """.*detectportal\.firefox\.com.*""", """.*\.svg""", """.*www\.google-analytics\.com.*"""))
-->
.inferHtmlResources(WhiteList(""".*blog\.prioli\.xyz.*"""))
What I like to do is changing the fix pause time to a random pause windows in order to better simulate a human browsing:
.pause(3)
-->
.pause(3 seconds, 5 seconds)
Then we have to define a politic of injection based on what we want to experience.
(test, performance, breaking point…)
setUp(scn.inject(rampUsersPerSec(1) to 10 during (10 minutes) randomized).protocols (httpProtocol))
Here the exhaustive list of all the actions available.
https://gatling.io/docs/current/general/simulation_setup/
Finally we can launch gatling.sh
/bin/bash bin/gatling.sh
Analysis
At the end of the test gatling generate a HTML report from logs.
It’s store in the results folder :
/home/ubuntu/gatling/gatling/results/blogpriolixyz-20200828000216099/index.html
python3 -m http.server 8000
The result looks like this:
Here we can see the website was still able to respond and it went up to 200 users simultaneously.
So I decide to test a litte bit more… violent !
setUp(scn.inject(rampUsersPerSec(1) to 30 during (10 minutes) randomized).protocols (httpProtocol))
Well now we can see some errors appearing. To be totally honest, we just reached the maximum power of the Raspberry Pi where I’m shooting the test from.
So I can affirm my Raspberry can hold simultaneous ~1700 users.
Conclusion
Gatling is a powerful and small tool to easily shoot test performances.
Obviously the serveur you use to shoot the test must be powerful and have a large bandwith.
In the next article of Gatling, I’m gonna explain how to shoot from many servers and develop more complex scenario.
Stay tuned !