


import scala.util.Random

The structure DSL provides a feed method.






You can also feed multiple records all at once. If so, attribute names, will be suffixed. For example, if the columns are name “foo” and “bar” and you’re feeding 2 records at once, you’ll get “foo1”, “bar1”, “foo2” and “bar2” session attributes.

feed(feeder, 2)


Gatling provides multiple strategies for the built-in feeders:

.random // randomly pick an entry in the sequence
.shuffle // shuffle entries, then behave like queue


When using the default queue strategy, make sure that your dataset contains enough records. If your feeder runs out of record, behavior is undefined and Gatling will forcefully shut down.



val feeder = Array(

File Based Feeders

Gatling provides various file based feeders.





Do NOT rely on having an exploded gradle/maven/sbt project structure. Typically, don’t use strategy #2 and paths such as src/main/resources/data/file.csv. The exploded structure might no longer be there at runtime, all the more when deploying with FrontLine. Use strategy #1 and classpath paths such as data/file.csv.

CSV feeders


Our parser honors the RFC4180 specification.



Loading mode



val csvFeeder = csv("foo.csv").eager.random



When in batch mode, random and shuffle can’t of course operate on the full stock, and only operate on an internal buffer of records. The default size of this buffer is 2,000 and can be changed.

val csvFeeder = csv("foo.csv").batch.random


Zipped files


val csvFeeder = csv("foo.csv.zip").unzip


Distributed files (FrontLine only)


shard is only effective when running with FrontLine, otherwise it’s just a noop.

val csvFeeder = csv("foo.csv.zip").shard

JSON feeders


val jsonFileFeeder = jsonFile("foo.json")

For example, the following JSON:


will be turned into:



JDBC feeder

Gatling also provide a builtin that reads from a JDBC connection.

// beware: you need to import the jdbc module
import io.gatling.jdbc.Predef._



  • sql is the query that will get the values needed.



Do not forget to add the required JDBC driver jar in the classpath (lib folder in the bundle)

Sitemap Feeder

Gatling supports a feeder that reads data from a Sitemap file.

// beware: you need to import the http module
import io.gatling.http.Predef._


The following Sitemap file:




will be turned into:

record1: Map(
           "changefreq" -> "monthly",
           "priority" -> "0.8")

record2: Map(
           "changefreq" -> "weekly")

record3: Map(
           "changefreq" -> "weekly")

Redis feeder

This feature was originally contributed by Krishnen Chedambarum.


  • LPOP - remove and return the first element of the list
  • SPOP - remove and return a random element from the set
  • SRANDMEMBER - return a random element from the set

By default RedisFeeder uses LPOP command:

import com.redis._
import io.gatling.redis.Predef._

val redisPool = new RedisClientPool("localhost", 6379)

val feeder = redisFeeder(redisPool, "foo")

You can then override the desired Redis command:




import java.io.{ File, PrintWriter }
import io.gatling.redis.util.RedisHelper._

def generateOneMillionUrls(): Unit = {
  try {
    for (i <- 0 to 1000000) {
      val url = "test?id=" + i
      // note the list name "URLS" here
  } finally {


`cat /tmp/loadtest.txt | redis-cli --pipe`





  • and whose output is Any, whatever you want

For example:

csv("myFile.csv").convert {
  case ("attributeThatShouldBeAnInt", string) => string.toInt

Grabbing Records





Beware that each readRecords call will read the underlying source, eg parse the CSV file.

Non Shared Data



val records = csv("foo.csv").readRecords

foreach(records, "record") {

User Dependent Data





In userProject.csv:

user, project
bob, aProject
sue, bProject

In projectIssue.csv:



import io.gatling.core.feeder._
import java.util.concurrent.ThreadLocalRandom

// index records by project
  csv("projectIssue.csv").readRecords.groupBy { record => record("project").toString }

  recordsByProject.mapValues { records => records.map { record => record("issue") } }

// inject project

  .exec { session =>
    // fetch project from  session

      // fetch project's issues
      val issues = issuesByProject(project)

      // randomly select an issue
      val selectedIssue = issues(ThreadLocalRandom.current.nextInt(issues.length))

      // inject the issue in the session
      session.set("issue", selectedIssue)