API Benchmarking with Gatling
- Get link
- X
- Other Apps
What and Why Performance Measurement:
The downtime of a mission-critical application can be very costly in recent time. It can lead to customer loss or financial loss. In today's world most of the web applications are built using APIs. APIs should be functionally correct, as well as available, fast, secure and reliable. It is very important to gather the data about API performance periodically. This will give us information about health and hygiene of our application. It doesn’t matter how beautiful your front end applications are if the API data sources take several seconds to respond or even worse if API performance is not consistent. API Performance matters very much in a world of microservices, which means the source of what a client application shows is probably being aggregated from multiple APIs behind the scenes.
How to Measure API Performance:
There are many tools available for performance measurement. This page list open source tools for performance measurement.
https://github.com/denji/awesome-http-benchmark
In this article we will focus on Gatling. Gatling is designed for continuous load testing and integrates with your development pipeline. Gatling includes a web recorder and colorful reports. Gatling’s architecture is asynchronous, which means it is very easy to create thousands of virtual users rather than managing dedicated threads.
In this article, I am going to use following
1. Intellij Idea with JDK8
2. Test App with random delay in get endpoint. (https://github.com/amithimani/mycabdemo)
3. Test Project (not mandatory but good to have) (https://github.com/amithimani/gatling)
First Lets create Test project using maven archetype.
mvn archetype:generate
Then you will see prompt like below, enter latest version available and provide details like groupId, artifactId, version and package name.
Once done, We can open this project in IDE.
There are two ways to define the scenarios
1. Using Gatling UI
2. Using Gatling DSL: We will focus on Gatling DSL in this article.
We will create test scenario in src/test/scala folder as below scala class
package basic; import io.gatling.http.Predef._ import io.gatling.core.Predef._ class GatlingTest extends Simulation { val httpConf = http .baseUrl("http://localhost:8080/v1/drivers?onlineStatus=ONLINE") //Application URL .acceptLanguageHeader("en-US,en;q=0.5") .acceptEncodingHeader("gzip, deflate") .userAgentHeader("Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0") val scn = scenario("GetDriverList") .exec(http("Get Drivers Request") .get("")) .pause(1) setUp( scn.inject(atOnceUsers(100)) //Number of concurrent users ).protocols(httpConf) }
An interesting thing about Gatling is that you can create your tests using your favorite IDE environment as well as run the test using IDE or it can be part of Jenkins pipeline.
This test will generate beautiful html report. Here are some sample screenshot of report.
- Get link
- X
- Other Apps




