Parameterization in Gatling Stress Test Tool

Parameterization in Gatling Stress Test Tool

Introduction

Gatling is a free and open source load testing tool to analyse and measure the performance of services that we use in web applications. Using Gatling, we can simulate the presence of over a 1000 users on a single machine with high concurrency scenarios. To describe simulation, we can use light weight Domain Specific Language (DSL) written in Scala. Simulations are for the load test. It is constituted of varied scenarios, each scenario representing specific user behavior.

Gatling Tree Diagram

The Gatling installation folder is organized according to the following tree diagram:

  • /results: contains the benchmark results in web format
  • /bin: contains the scripts for launching Gatling
  • /target: contains the files resulting from the compilation of our scenarios + cache
  • /conf: contains configuration files (log level)
  • /user-files: contains the .scala scenario definition files
  • /lib: Gatling jar

Features ensuring effective simulation in Gatling:

  • DSL for simulation written in Scala to treat performance as a code.
  • Support of HTTP(S) protocols & can also be used for JDBC & JMS load testing.
  • Produces higher load by using an asynchronous non-blocking approach.
  • Supports input files CSV, TSV, SSV to access random data for Data-Driven tests.
  • Generation of graphical reports using Graphite in an understandable manner.

Use Case

Let’s try to test the performance of the services by parameterizing input data taken from a CSV Datasource and run automatically defined scenarios with multiple numbers of simultaneous players.

What we need to do

  • Prerequisites
  • Create CSV Datasource input file in the /user-files/data folder.
  • Simulate 100 services, to enable execution of each of the services with their own credentials.

Solution

Prerequisites

Parameterize API service with Feeder

To Parameterize the API service with more input data using CSV Datasources, Feeder is used. Feeder is an Iterator [Map[String, T]] , which injects data into the session, every time it reaches the service Map[String, T] and  shares data with all the users.

Step 1: Create CSV Datasource

  • Data sources are normally Array[Map[String, T]] – Map keys are names of attributes.
  • Gatling provides support for CSV separated values file. The CSV ( filename: String ) method, can be used to parse the files.

Note:

  1. The created CSV Datasource should be in the following /user-files/data folder.
  2. First line of the source file must be the labels.

Sample: Create CSV Datasource as “token.csv”

Step 2: Generating Feeders from the Datasource

  • Gatling provides Built-ins for converting Data Source into Feeders.
  • We can use Random Strategy to avoid feeder starvation. In this strategy, a random record is taken out from the feeder and injected into the session.

Sample:

Step 3: Inject Datasource values into the User Session

  • Use the Feed method to inject user created CSV Datasources. Structure for the feed method is .feed (feeder_source).
  • Every time the user reaches this step, he takes record from the feeder and injects it into the user scenario to create a new session instance.

Sample:

Step 4: Load Scenarios for execution with multiple number of simultaneous players.

  • User data injection is done with the Inject method. This method takes an argument as a sequence of injection steps, that will be processed sequentially.

Sample:

Define Expected Results

Step 5: Creating Global Assertions

  • Assertions are used to verify if global statistics, like service response time or number of failed requests match expectations for a whole simulation.

Sample:

Step 6: Run the specific simulation file and get the pretty reports.

event_screen

Conclusion

One of the important advantages of Gatling is the generation of high quality graphic reports at the end of each simulation. It helps testers view reports immediately, without having to do any additional work.Feeders is another good feature of the Gatling tool which helps parsing of parameters in separate files.Overall, the Gatling DSL tool is designed for ease of use, high performance, enabling us handle complex scenarios in an efficient manner, along with maintainability.

Reference

  • Feeders in Gatling:

http://gatling.io/docs/2.0.0-RC2/session/feeder.html

  • Configuration of Virtual users:

http://gatling.io/docs/2.0.2/advanced_tutorial.html?highlight=configure%20virtual%20users

  • Reports in Gatling:

http://gatling.io/docs/2.0.2/general/reports.html?highlight=reports

10214 Views 7 Views Today
  • AJ MIC

    Can we get the test results per each parameters? Like, for example, if we have 10 parameters for a particular tests and only one is failing , is there any way to see that information ( of which parameter is taking more time? ). Currently the results shows the average of all the 10 parameters.

  • P Jayachandra Reddy

    val scn = scenario(“completesignup1″)
    .exec(http(“request_0″)
    .get(uri1 + “?isBeta=False”)
    .headers(headers_0))

    this request getting fail during exicution time , how can i pass this request?

  • Johnny Patel

    please how to do parameterization for login script like username and password….eg.way2sms.com

  • Johnny Patel

    .exec(http(“request_2″)
    .post(uri3 + “/QQxQmrAhjBy1REeAnaNwyQp4MpyU70djQhyRospJBZ8″)
    .headers(headers_2)
    .body(RawFileBody(“sms1_0002_request.txt”)))
    .pause(12)
    this request getting fail during exicution time , how can i pass this request?