Does Gatling reset CSV feeder state between repeated simulation runs?
0 reputation · 14 Apr 2021, 18:58 UTC
0 reputation · 14 Apr 2021, 18:58 UTC
Execute the same Gatling 3.x simulation repeatedly inside one Maven, SBT, or Gradle session without restarting the build tool, while keeping CSV feeder records available on every run.
Gatling feeders behave as iterators: each record is consumed once per feeder instance and is not automatically restored when the simulation runs again. If the build tool retains the simulation object, later executions may see an exhausted feeder. This assumption applies to Gatling 3.x; Gatling 2.x semantics may differ.
Does Gatling reset feeder state between repeated simulation runs in the same build-tool session? Is a circular feeder required for repeatable local runs, or must the feeder instance be recreated before each invocation?
34275 reputation · 15 Apr 2021, 05:40 UTC
No. Gatling 3.x does not reset CSV feeder state between repeated simulation runs executed in the same JVM (i.e., without forking). The feeder is a stateful iterator; its position is retained after the first run completes, so subsequent runs start where the previous one left off — often yielding zero records.
Iterator[Map[String, Any]] instances.val in a singleton object or top-level object), the iterator is already at its end for the second run.val feeder = csv("users.csv").circular
After the last record, the iterator loops back to the first. Caution: the simulation must have a stopping condition (maxDuration, fixed user count, exitHereIfFailed, etc.) or it will run indefinitely.
// Define as a def so a fresh iterator is produced each time
def freshFeeder = csv("users.csv")
class MySimulation extends Simulation {
val scn = scenario("Test").feed(freshFeeder).exec(...)
setUp(scn.inject(atOnceUsers(10)))
}
Placing the feeder creation inside a def, a before {} block, or the simulation body ensures a new iterator for every execution.
users.csv)..circular().mvn gatling:test twice in the same Maven session (no forkMode). Observe that the second run produces no requests..circular() or switch to a def feeder and repeat; both runs should now consume all three records.If you prefer not to change feeder code, configure the build tool to fork a new JVM per run:
<forkMode>always</forkMode> in gatling-maven-plugin.fork := true in Gatling config.forkEvery = 1 on the gatling task.Each fork starts a fresh JVM, so feeder state is naturally reset. This is heavier than feeder recreation but requires zero code changes.
Are you running simulations in parallel (multiple scenarios or multiple setUp blocks concurrently) while sharing the same feeder instance? If yes, you must use separate feeder instances per simulation to avoid race conditions on the iterator — .circular() alone does not solve concurrent access.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.