levo4ka
levo4ka

Reputation: 2298

How to implement specific counts of thread in Gatling

Is there any possibility to setup Gatling scenario to run in specific counts of thread? For instance, I want to execute 1M requests during 1hour in 2500 threads.

And also, does each scenario (in setUp(scn.inject())) will be running in different thread? What does "thread" means in Gatling-definition - is it the same as in Java?

I found a topic, but it's not exactly what I need (in case of topic-started he needed only 3 threads, but for me - counts much bigger).

I have

val scn = scenario("Test")
    .exec(mine)
}

setUp(
    scn.inject(
        rampUsers(1000000) over (3600)
     )
).assertions(global.successfulRequests.percent.greaterThan(95))

Upvotes: 4

Views: 5417

Answers (1)

Teliatko
Teliatko

Reputation: 1541

As stated in the topic you've cited, number of threads that Gatling will use to fire the requests against your target system under test is not number of concurrent users. It is implementation detail.

Gatling uses Akka under the hood and issues the requests asynchronously. This asynchronous nature means that Gatling is using a few threads to fire all the requests. If you want to know more see gatling-akka-defaults.conf. It uses Akka Default Dispatcher which uses fork-join pool with aprox. number of CPU cores * 2 threads (not certain at 100%, see doc).

As was already mentioned in cited topic, question is What do you mean by "user"?.

As I understood it, your goal is to have a load 2500 concurrent users against your system. It does not matter if the Gatling will uses 2 or 1000 threads to achieve this.

So if you want 2500 concurrent users (per second) it is easy to write just:

setUp(
  scn.inject( constantUsersPerSec(2500) during(3600) )
)...

If you on other hand want a 2500 distinct populations (which is IMO not desired) you can achieve this too, by:

// `scn` have to be function, while scenarios should havce distinct name
def scn(name: String) = scenario(name)
  .exec(
    http("root").get("/")
  )

setUp(
  (for {
    i <- 0 until 2500 // desired 2500
   } yield {
    scn(s"Test $i").inject(
      rampUsers(1) over (3600)
    )
  }).toList // setUp can accept List[PopulationBuilder]
)

Populations should be used to inject different scenarios or different type of users at the same time with its own rate and duration. For example see Advanced Tutorial, Step 2. They are not intended to simulate concurrent users. You can see that directly from the code that syntactically the solution is possible but cumbersome.

Upvotes: 2

Related Questions