Performance Testing with Gatling — I
Performance testing of is one of the very important aspects of a web application testing.
Performance testing is nothing but checking of how the Application under test would perform under different conditions. Performance test could be used to determine:
- Response of the application at a certain load(users/number of requests)— Load
- How many users the application can cater to, at the same time — Scalability
- How will the application behave if suddenly an unexpected amount of requests come through the application — Spike
- How long can my application continuously cater to certain amount of load, without crashing — Stability(Soak)
- What happens to the application if the Load or the requests increase in the application abnormally — Stress
- How fast is my application with the amount of data it has — Volume
While the types are not limited to what I have mentioned above, the reason to do to performance testing is largely to ‘determine and improve’ user experience and to ‘determine the resources’ required to successfully cater the user requests. And sometimes to make sure the errors are elegantly handled even if the system fails.
There are multiple tools to carry out Performance testing. One such tool is Gatling.
Gatling is Scala based open-source performance testing framework. Gatling scripts are to be written using Scala DSL.
Gatling also has a GUI to record the requests & generate a simulation scripts which can be used to run the simulations.
Advantages of Gatling
- With Gatling it is easy to write or generate a maintainable script. Though the scripting has to be done using Scala, the DSL speeds up the learning curve & also improves code readability
- Highly performant — Usage of Akka toolkit and advanced architecture makes Gatling performance better than the other tools in the market. Hundreds of thousands of requests can be simulated with lesser resources
- Reports — Gatling generates an exhaustive and beautiful report by default.
- Integration with CI tools
- Comprehensive documentation and community support — Gatling has a very detailed documentation and there is a great community support because of millions of users already using the tool. There are so many example projects and plugins to refer to
- Open source — Free to use and contribute to the tool’
- Recording support — If you are a beginner and looking for some faster way to get started, the Gatling recorder comes handy. Having said that to be able to run it repeatedly and maintain in for a longer time, there would be some script enhancements required like in any other record and playback tools.
System requirements
Java — Gatling requires JDK8 and up.Install JDK either by downloading from here. But I would recommend using a package installer like brew for mac and chocolatey for windows.
brew cask install java
Scala — Gatling(3.0.0+) works with Scala 2.12 only. It doesn’t work with Scala 2.13 as well.
Setting up Gatling Project
Gatling bundle installer can be downloaded and unzipped from Gatling Open Source page & will be ready to use.
Gatling framework can be set up easily with build tools. Gatling has official plugins with Maven & sbt.
In the set up we would be using gatling-maven-plugin to create an example performance testing project.
Steps to set up:
- Install Maven
brew install maven
2. Generate Maven archetype for Gatling
You can either refer to this video or follow the step by step section below the video .
mvn archetype:generate
Filter by gatling
provide Gatling version, groupID, archetypeID, version and package & hit ENTER
I have highlighted the user inputs in orange box in the above screenshots.
After the above steps you should have a folder created with the archetypeId you gave above consisting of a pom.xml & src
3. Opening the project in an IDE
Open IntelliJ and click import project, select your project folder(consisting of pom.xml and src) in which you generated your project in step 2
Then chose option Import project from external model>Maven and Click Finish.
After the project open and imported you will see a folder structure something like in the below screenshot.
Let us look at writing and running a simulation in Gatling in the next part.