What is the correct way of telling Gatling to play scenario for N users but only run M concurrent users at the same time?
Just to be clear - I want to run a “setup” scenario before running the main one. That setup scenario is supposed to register and configure users that the main scenario will be using later.
(This is all done with a sequence of RESTful calls so it felt like a good idea to use Gatling there).
I created an unbounded feeder (an Iterator that generates usernames like user-123, passwords etc) and just need to run that scenario with some degree of parallelism.
I do not want to limit number of requests per second (with constantUsersPerSec) - if server is fast with its responses - there is no need to artificially delay the next request. However I would like to run only a fixed number of requests in parallel to avoid killing the server.
You can use close model for injecting exact amount of concurrent users, something like this:
val usersAmount = M
val repeatAmount = N / usersAmount
val scn = scenario(“foo”).repeat(repeatAmount) {
chain
}
setUp(scn.inject(atOnceUsers(usersAmount)))
Regarding “setup” scenario - you can chain it in single simulation, but in this case it will run with the same amount of concurrent users
If you need different one - e.g setup - 1 concurrent user, main scenario - M users you have to write setup as another simulation because at the moment Gatling won’t allow you inject sequential scenarios with different amount of users.
Hi. Thanks for the help.
My setup is already another simulation as I would like to control these two separately.
The approach you are suggesting does not seem to work well with feeders. In my setup phase, feeder provides a list of all the users that needs to be configured so it needs to be read in full. However with this approach:
val test =
exec(http("test-${username}").get("/")
)
val userFeeder = Iterator.from(1) map ((i) => Map(
"username" -> ("test-" + i)
))
val scn = scenario("Test")
.feed(userFeeder)
.repeat(10) { test }
setUp(
scn.inject(
atOnceUsers(10)
)
).protocols(httpProtocol)
I can see that Gatling logs the same users multiple times so it does not consume from feeder fully. When I remove “repeat” and change atOnceUsers to 100, I get every user ID only once. (But I obviously flood the server as well)
I am probably not understanting Gatling philosophy yet but that seem to me like a very basic functionality of a load generator (to play only a certain number of user session at a single time but being able to play a scenario for more users than that limit) so I am really surprised it is not available out of the box.
Well,
It happenns because of your feeder attached to the scenario.
In this case Gatling will inject one record per user and repeat same record with given amount.
If you want to use unique value per each request your feeder should be declared in exec step:
val scn = scenario(“Test”).repeat(10) {
feed(feeder)
.exec { test }
}