Search code examples
performance-testinggatlingscala-gatling

How to achieve constant concurrent active users in closed model using Gatling?


My question is somehow related to this and this , but somehow doesn't really answer my question.

My test case is pretty simple, I need to generate constant active concurrent users (e.g. 10 concurrent users) constantly over a period of time (e.g. 60 sec).

My codes look like this

val TestProtocolBuilder: HttpProtocolBuilder = http.baseUrl("https://computer-database.gatling.io")
object Test {

  val test =
    exec(http("Test_Only")
      .get("/computers")
      .check(status.in(200, 404))
    )
}

val TestOnly = scenario("Test Only").exec(Test.test)

setUp(
  TestOnly.inject(
    constantConcurrentUsers(10) during(60 seconds)
  ).protocols(TestProtocolBuilder)
)

This documentation says constantConcurrentUsers(nbUsers) during(duration) : Inject so that number of concurrent users in the system is constant

I am expecting to get 10 concurrent active users constantly hitting the API for 60 seconds. No more than 10 users and no less than 10 users at any time.

What I see in the HTML report is that the active users at any given time is much higher than 10 (almost double).

enter image description here

Learning from the documentation , it says

This chart displays the active users during the simulation : total and per scenario. “Active users” is neither “concurrent users” or “users arrival rate”. It’s a kind of mixed metric that serves for both open and closed workload models and that represents “users who were active on the system under load at a given second”.

It’s computed as: (number of alive users at previous second) + (number of users that were started during this second) - (number of users that were terminated during previous second)

Questions:

  1. Why Gatling keep terminating users and starting new users during the test period? What's the point?
  2. How can I get a constant 10 concurrent active users (no more, no less) keep hitting my API for the duration of the test, if constantConcurrentUsers(10) during(60 seconds) give me a much higher active users and keep fluctuating during the test period ? I need to stick to my test case and not over-loading the API.
  3. In the image above, at that given time the number of request = 7 and the active users = 20. Does it mean that at that given time, there are 7 active users sending out requests and there are 20 - 7 = 13 active users sitting idle waiting for the responses to come back from the API ?

Thanks.


Solution

  • Why Gatling keep terminating users and starting new users during the test period? What's the point?

    Virtual users' lifespan is driven by your scenario. Injection profiles only drive when they are injected/started. If you want to have your users not terminate after just one requests, add a loop in your scenario.

    How can I get a constant 10 concurrent active users

    Nonsensical. As you quoted yourself concurrent != active. I guarantee you have a constant number of concurrent users, meaning exactly 10 users alive at the same time. The thing is that as your scenario only has 1 single request, users terminate right after and are replaced with a new one.

    Does it mean that at that given time, there are 7 active users sending out requests and there are 20 - 7 = 13 active users sitting idle waiting for the responses to come back from the API ?

    It means virtual users lifespan overlapped between 2 seconds so they were seen alive in 2 different second buckets.