ABS
ABS

Reputation: 61

Gatling: loop through all the entries in a feeder

I have a CSV file which has around 10K entries (request payloads for my session). I am using the built-in CSV feeder to loop through all of them in my request. But only the number of requests corresponding to number of users in the test is executed. I would like that the whole feed be executed.

For example if I have 10 users, then only the first 10 records of my CSV are fetched during runtime.

This is my code:

  val rqstFeeder = csv("rqst.csv")
  val user = ConfigFactory.load().getInt("app.loadVariables.user")
  var URL: String = ConfigFactory.load().getString("app.loadVariables.URL")

  val httpProtocol = http
    .header(HttpHeaderNames.Accept, HttpHeaderValues.ApplicationJson)
    .inferHtmlResources()

  object GSLBRequest {
    val getData =
      exec(
        http("Get GSLB Data")
          .post(URL)
          .body(StringBody(ConfigFactory.load().getString("app.loadVariables.body"))).asJSON
          .check(status.is(200))
      )
  }

  val customInject = constantUsersPerSec(user) during (5 seconds)
  val source = scenario("GSLB Endpoint")
    .feed(rqstFeeder)
    .forever(exec(GSLBRequest.getData)).inject(customInject);
  )

  setUp(source)
    .protocols(httpProtocol).maxDuration(30 seconds)

Upvotes: 4

Views: 7817

Answers (1)

Mateusz Gruszczynski
Mateusz Gruszczynski

Reputation: 1500

This is how feeders works. Each time you call feed(feeder) you will get one full set of values saved as attributes - in case of CSV one line. Since you call it once per user then only 10 rows are used. Put feeder inside your loop, then values will be fetched in every iteration.

You will also need to set feeder mode to circular or random fe.:

val rqstFeeder = csv("rqst.csv").circular

Without that default mode will be used and it only allow to fetch every record once, after that simulation will fail due to "empty feeder". Circular mode will feed data from all over again if encountered end of list, random will of course do it randomly so list size is not an issue for it. You must remember that this will not give you guarantee that each row will be used exactly once. If simulation is to short it wont use all records, if it is too long it will need to use some records multiple times. If you would need to run each row exactly once then it would be better to run simulation with 10k users or keep 10 users but replace forever with repeat(1000) loop.

Upvotes: 4

Related Questions