API Load Testing Using Gatling 2

API Load Testing Using Gatling 2


Most of the Client-Server web applications use REST API that can be accessed using the URI. Gatling is one of the open source performance testing tool used to test the REST API’s performance. Gatling generates HTML reports from test execution that includes several graphs, breaking down the performance across different metrics, including global sessions and per-API request.

Use Case

Problem Definition

API performance measured manually leads to inaccuracy and erroneous results. Automation of such performance tests would resolve these issues. Gatling enables simulation of multiple concurrent users and API inputs. Testing the performance on a single user would be inadequate.


Gatling Test Plan for the Restful API

  • Add Simulation information Package name and Class name
  • Add Encoding format, HTTP Request Defaults, Sampler HTTP Request for REST
  • Add CSV file and configure the Feeders
  • Multi – Scenarios Simulation (User Simulations)
  • Simulation Setup with Injection for the Scenarios
  • Run the Simulation Script and view HTML Report

The following steps explain configuring Gatling and using it for Performance testing of Restful API:

Add Simulation information

As a first step, use the recorder batch file to create the simulation with the package name and the class name.


Set Encoding format

Encoding is used during compiling simulations and build requests. Configure the proper encoding in the gatling.conf file.


Add “HTTP Request Defaults” Config element

Create a Header.scala file in the following location:


In this file add the Domain name or IP address of the web server.


Creating\Adding CSV file and Configuring the Feeders

Gatling uses CSV test data dynamically. The various advantages of using CSV file are listed below:

  • Multiple data objects for multiple recursions can be stored in a single file
  • To update data values, .scala file need not be updated to alter the CSV file

This expected file should be placed in the data directory in Gatling distribution. This location can be overridden in the gatling.conf file.


REST API is added with the authid in the csv file.

The following sample illustrates how to save csv file with the name service.csv


The next step is to configure the Feeder in the simulation. Create the feeders.scala file in the following location:



Every time a virtual user reaches this step, it will pop a record out of the Feeder that will be injected into the user’s session resulting in a new session instance.

Create multiple User Scenarios

We create multiple scenarios in the given location with the extension .scala:


The screenshot below illustrates the scenario with the name “detailPage.scala”:


Simulation Setup with Injection for the Scenarios

Now, we will define the load to scenarios. These load scenarios will be injected in the server. Inject method is used to define the server load. This method takes sequence of injection steps as arguments that will be processed sequentially.


Run the Simulation Script and view HTML Report

Run the simulation with the help of gatling.bat file available in the gatling-charts-highcharts-2.0.1\bin folder. The execution results are available in the “gatling-charts-highcharts-2.0.1\results” folder.



  • API services can be simulated using Gatling with the load pretty close on every deployment in the production at ease
  • Nevertheless, we can also monitor the performance of the individual API services and group of services which helps to maintain the product’s performance
  • Reports generated by Gatling are simple and can be maintained easily


11045 Views 2 Views Today