Injection Profiles: Controlling Gatling Virtual User Load
Configure open and closed injection profiles in Gatling: ramp users, constant rates, stress peaks, capacity stairs, sequential scenarios, and sharding.
Use this file to discover all available pages before exploring further.
An injection profile defines when and how fast virtual users are introduced into a scenario. Gatling supports two fundamentally different models: the open model, where you control the arrival rate of users, and the closed model, where you control the number of concurrent users at any given moment. Choosing the correct model is critical for producing meaningful results — see Workload Models for a deeper explanation.The injection profile is defined by calling injectOpen or injectClosed (just inject in Scala) on a ScenarioBuilder, then passing one or more injection steps that are processed sequentially.
separatedByRampsLasting and startingFrom are both optional. Without a ramp the test jumps directly between levels; without startingFrom it begins at 0 users/sec.
setUp( scn.injectClosed( constantConcurrentUsers(10).during(10), // 1. hold 10 concurrent users for 10 seconds rampConcurrentUsers(10).to(20).during(10) // 2. ramp from 10 to 20 concurrent users over 10s ));
Ramping down the number of concurrent users does not forcefully interrupt running virtual users. Users terminate only when they complete their scenario. Plan your scenario length accordingly.
For a single scenario you can pass a sequence of injection steps. All steps must belong to the same model (open or closed). The next step begins once all virtual users from the current step have started.
Java
JavaScript / TypeScript
// open model: ramp to 100 users/sec then hold steadysetUp( scn.injectOpen( rampUsersPerSec(0).to(100).during(Duration.ofMinutes(1)), constantUsersPerSec(100).during(Duration.ofMinutes(10)) ));// closed model: ramp to 100 concurrent users then hold steadysetUp( scn.injectClosed( rampConcurrentUsers(0).to(100).during(Duration.ofMinutes(1)), constantConcurrentUsers(100).during(Duration.ofMinutes(10)) ));
Use andThen to chain scenarios so that child scenarios start only after all users from the parent scenario have completed.
Java
JavaScript / TypeScript
setUp( parent.injectClosed(injectionProfile) // child1 and child2 start together when the last parent user finishes .andThen( child1.injectClosed(injectionProfile) // grandChild starts when the last child1 user finishes .andThen(grandChild.injectClosed(injectionProfile)), child2.injectClosed(injectionProfile) ).andThen( // child3 starts when the last grandChild and child2 users finish child3.injectClosed(injectionProfile) ));
Sequential scenarios are the recommended approach when you need to perform Gatling SDK actions (e.g., fetching an auth token) before the main load begins — something that cannot be done in lifecycle hooks.
By default, Gatling Enterprise Edition distributes your injection profile evenly across all load generator nodes. Use noShard to disable this — all nodes will run the full injection and throttle profiles as defined. This is typically used when a pre-scenario (e.g., token retrieval) should run on every node rather than just one.
Java
JavaScript / TypeScript
setUp( // parent load is NOT sharded — runs on every node parent.injectOpen(atOnceUsers(1)).noShard() .andThen( // child load IS sharded across nodes child1.injectClosed(injectionProfile) ));