How to maintain a persistent HTTP connection per user with closed injection model

Hello,

I’m trying to simulate 5 nodes that will contact my API. And all 5 of these nodes will maintain a long lived TCP connection to send their HTTP (actually HTTPS) requests, in order to avoid the overhead of doing a new TCP and TLS handshake on each request.

Here is Gatling code I’m currently using:

package projectabc

`
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._

class BasicSimulation extends Simulation {

val feeder = csv(“search.csv”).random

val httpProtocol = http
.baseUrl(“http://localhost:8090/api/item”)
.acceptHeader(“application/json”)
.acceptLanguageHeader(“en-US,en;q=0.5”)
.connectionHeader(“keep-alive”)

val scn = scenario(“BasicSimulation”)
.feed(feeder)
.exec(
http(“request_1”)
.get("/${id}")
.check(status.in(200,201,404))
)

setUp(
scn.inject(
constantConcurrentUsers(5) during (5 seconds))
).protocols(httpProtocol)
}
`

Unfortunately, it doesn’t work as intended: the keep-alive header is sent but a new TCP connection is opened on each HTTP request. I’m using Gatling 3.1.2. Is there anything wrong with my config?

Thank you for your help.
Chaouki

I guess I misunderstood how Gatling work with close injection model. each virtual user will send only one GET request before getting it gets terminated. Then constantConcurrentUsers makes sure that the number of active virtual users stay constant (by creating new ones as old ones are terminated).