Gatling parallel requests from one session

I haven’t found the answer in previous topic, also the question is quite popular. I have http client that create some application session and request resources during it.

val scn = scenario(“App session”)
.exec(
http(“Authorize”)
.get("/authorize")
.queryParam(“token”, token)
.queryParam(“version”, version)
.check(bodyString.saveAs(“key”))
).exec {

val array = csv(“entities.csv”).records.flatMap(r => r.seq.values)
foreach(array, “record”) {
exec {
http(“Get ${record}”)
.get("/dump?key=${key}")
.queryParam(“model”, “${record}”)
}
}
}

setUp(scn.inject(
rampUsers(3) over(30 seconds)
)).protocols(conf)

As you can see in second exec client iterate some entities and request them sequentially.
I should emulate client does 4 requests in parallel. Client asks and waits answers, If it finishes with one request move to the next, another 3 would be waiting. And so on.
Does anybody know the recipe?

Hi,

What exactly do you need?
I see collision here - “client does 4 requests in parallel” and “it finishes with one request move to the next, another 3 would be waiting”

Thanks,
Alex.

Sorry, I might be not clear.
Given for example 100 urls to request client has 4 connections.

Ok I see,
If you want 4 users each with 100 urls (400 urls total) your code should be OK, just put atOnceUsers(4) or ramp to 4 users in setUp method
If you want 4 users with total 100 urls you have to provide correct repeat value for each user, for example:

val users = 4
val records = csv(“entities.csv”).records.count - 1

val scn = scenario(“App session”)
.exec(
http(“Authorize”)
.get("/authorize")
.queryParam(“token”, token)
.queryParam(“version”, version)
.check(bodyString.saveAs(“key”))
)
.repeat (records / users) {
feed(csv(“entities.csv”))
.exec {
http(“Get ${record}”)

.get("/dump?key=${key}")
.queryParam(“model”, “${record}”)
}
}
}

setUp(scn.inject(atOnceUsers(users)))

Thanks,
Alex.

Actually you didn’t get the idea.
We have clients = N and parallelConnections = M.

val parallelCount = M

val dumps = scenario(“Dumps”)
.repeat(array.length / parallelCount) {
feed(csv(“entities.csv”))
.exec {
http(“Dump ${entity}”)
.get("/dump?key=${syncKey}")
.queryParam(“model”, “${entity}”)
}
}

val scn = scenario(“App session”)
.exec(
http(“Authorize”)
.get("/authorize")
.queryParam(“token”, token)
.queryParam(“version”, version)
.check(bodyString.saveAs(“key”))

).exec(

dumps.inject(atOnceUsers(parallelCount)).scenarioBuilder

)

setUp(scn.inject(
rampUsers(N) over(10 seconds)
)).protocols(conf)

Something like this. This code compile, but doesn’t do parallel http("Dump ${entity}") for M.

You are trying to “exec( scenario )” - you can’t do that. Re-think what you are doing and follow the patterns in the documentation.

John, I investigated the documentation and think that

  1. Gatling doesn’t have such functionality from the box
  2. My application creates and manages specific applicationSession, and it’s difficult scenario that isn’t covered by Gatling.

Gatling can not call one scenario from within another scenario, but it can call a CHAIN from within another chain.

It looks like what you are really trying to do is have the first virtual user get a token, and all subsequent users use the same token. Is that how the application would be used in the real world? Multiple clients all using the same token? Or would each client have its own token?