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 | ‘ : @ # $  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(“userData.csv.zip”).** 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.

#scala #gatling feeder #json feeders

Gatling feeders and feeder strategies
46.60 GEEK