When you think about performance testing your application, you may think about the below picture and a tool to test.
One open source tool that comes to mind is JMeter. For very simple tests, I tend use apache benchmarking. But there are other tools like Grinder, LoadRunner, NeoLoad, Tsung, and SoapUI for web services testing. Then there is Caliper and jmh for micro benchmarking, which target use cases.
So what makes Gatling different from other tools is:
- Usability – GUI vs Script (Code)
- Integration with other tools like Maven, Jenkins
- Underlying Technologies
Usability – GUI vs Script (Code)
Using the GUI to do performance tests is difficult and unintuitive.
Gatling provides an elegant DSL written in Scala to describe your test scenarios of your app. DSL scripts are intuitive and simple to create. Using the recorder (like JMeter) it can generate scripts that will look similar to a hand written one. Your can then tweak the generated scripts anyway you want.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
I created the above script, which load tests the twitter.com site. You can checkout the full source code here, which is a cloned maven project from gatling-maven-plugin. Take a look at the TwitterSimulation.scala file that I added to the project.
Once downloaded, execute with the following maven command with your tweeter username and password:
Note: Keep the concurrent user count between 2 and 5. If you add more load twitter they will display the CAPTCHA login page instead. This is to avoid a DoS attack. In other words the login test may fail intermittently based on how many times you run the test.
This script gets you to twitter.com and posts with username, password and authenticity token that is get generated when you request twitter.com.
You can extract values from the HTTP response like this:
With the response from the HTTP post, it verifies the http status code and the content of the body using bodyString()and regex() utility methods. It also logs-out from the site.
Real users usually reads the pages and clicks through the links. To get this real user simulation, there is a pause() method that can be used for this purpose. There are other structural elements available.
The project has two more tests – basic and advanced simulation. Take a look at and run them in the same way as twitter one.
Gatling automatically handles http headers and cookies. It also auto redirects based on headers, which makes testing sessions and OAuth based applications easier.
Testing a RESTful service layer is mush easier with a script than using the GUI. Here is nice blog post on how Gatling is used to test the Neo4j REST interface.
To test the SOAP interface, I may use SoapUI, which handles most of the SOAP plumbing. You can use Gatling to load test SOAP as well, however you will have to write the SOAP headers and xml body yourself.
Note: Gatling 2.x undertook major API refactoring and is not compatible with Gatling 1.x. You may want to watch out for this. I am using version 2.0.0-M3 in all my examples.
There are other tools that support scripting like Beanshell, Python, Clojure and Erlang. But they are not simple to use and learn like Gatling.
A script is always easier to modify as a project evolves than maintaining a GUI based load test file. A script also fits very well into your daily workflow as it integrates very well with developer tools like maven, jenkins and your favorite IDE.
Gatling generates nice and easy to understand static reports with metrics, which easily can be shared with anyone on your team. The reports are static and can be run with the daily build or when you release your application. You can then compare the results between each release to monitor how the app is performing. You can also send the simulation data to Graphite which gives you live statistics.
Integration with other tools and IDEs
Gatling integrates with other tools of your choice (which supports scala) like maven and eclipse (or Intelli J) to integrate with your daily workflow. Thus, you don’t have to use another tool to load test your app. There is also a Jenkins plugin available.
Gatling is built on Akka actors to handle large-scale tests and Scala’s DSL capability to build clean and simple scripts. It also uses asynchronous http client and non-blocking IO libraries (Netty, Grizzly).
Thanks to @whittierta for proofreading and suggestions.