Gatling feeders and feeder strategies

Reading Time: 3 minutes

Hello everyone, in our previous post Accelerate performance with Gatling: POST HTTP REQUEST we have discussed:

  • What are the different ways to send an HTTP POST request with Gatling? 
  • How to play with the different types of request bodies using Gatling?

In this post, we will discuss:

  • How to send dynamic data in the request bodies with Gatling feeders? 
  • What are the Gatling feeder strategies?

Let’s assume that we are simulating a use case where 1000 concurrent users are trying to register to the app. Now there are two ways to do that: one is to write a random string method and use it in our simulation and the other is to separate the data from our simulation by defining a feeder.

Gatling Feeder

The feeder is a type alias for Iterator[Map[String, T]]. Gatling DSL provides an easy to use ‘feed’ method which takes the feeder as an argument and reads the data from the feeder and injects it into the simulation.

Gatling provided multiple feeders

Character separated file feeders

Gatling provides various ways to read the data from character-separated values files. Now there are multiple use cases where we use different separator characters in our data files like | ‘ : @ # $ <tab> etc.

 So we can use

  • val csvFeeder = csv(“userData.csv”) // use a comma separator
  • val tsvFeeder = tsv(“userData.tsv”) // use a tabulation separator
  • val ssvFeeder = ssv(“userData.ssv”) // use a semicolon separator
  • val customSeparatorFeeder = separatedValues(“hello.txt”, ‘#’) // use your own separator.

 If we have large data files then you can use zip file in Gatling feeder and ask Gatling to unzip the data at run time using following syntax

  • val csvFeeder = csv(“”). unzip 

JSON Feeders

Above we have seen how to send the data from the different files, but what if a user wants to use a JSON file as a feeder? Just like CSV feeder, Gatling has a JSON feeder that can inject the data from JSON file or a JSON URL with the following syntax:

JDBC Feeders

As the name said JDBC feeder provides the capability to read the data from JDBC connections. It means if a user wants to read the data from a database like MySQL or PostgreSQL they can use JDBC feeders that will take the connection URL, user credentials and query as an input and at run time it will connect with the database as per defined configuration and inject the data in the simulation.

  • jdbcFeeder(“databaseUrl”, “username”, “password”, “SELECT * FROM users”)

Gatling supports some other feeders as well, but those are dependent on the use case where if a user wants to read a sitemap file using sitemap feeders, to read data from Redis using Redis feeders and to define a custom feeder as per the use case.

Feeder Strategies

Till now, we have discussed how to inject data in our requests using feeders but in some scenarios, we have some conditions like I have data in a data file and I want to inject:

  • In a sequence 
  • Randomly
  • As a loop on a batch of data sets like I have only 10 records and want to share the same data between concurrent users.

Gatling DSL handles all these scenarios using different feeder strategies:

  • .queue // default behavior: use an Iterator on the underlying sequence
    When using the default queue strategy, make sure that your data set contains enough records. If your feeder runs out of the record, the behavior is undefined and Gatling will forcefully shut down.
  • .random // randomly pick an entry in the sequence
  • .shuffle // shuffle entries, then behave like queue
  • .circular // go back to the top of the sequence once the end is reached

So this is all about Gatling Feeders and feeder strategies, In next post, we will discuss How Gatling sessions API help to manage the data between concurrent users. Thank you.



Written by 

Gaurav is a Module Lead QA Consultant having experience of more than 4.5 years. He is well familiar with core QA concepts and well versed in designing automation frameworks in a microservice environment. He has good hands-on experience in automation tools like ReadyAPI, SoapUI,,,,, Selenium (Java & Scala) and others. He actively promotes shifting left in the development cycle and understands the project domain to work closely with the development team. He has a good understanding of different domains like Airline, health Care and Shipping and cruising domain.