andThen() block is not executed

Gatling version: 3.13.1
Gatling flavor: java kotlin scala javascript typescript
Gatling build tool: maven gradle sbt bundle npm

Hi,

As part of a single Simulation, I want to run:

  1. Warm Up scenario, which starts from 0 RPS, gradually increases up to $target RPS, and holds the #target RPS for several seconds
  2. After the Warm Up is finished, I’d like to run real load tests, that jump right away to $target RPS, and hold the traffic for some time

The setup is presented below:

import io.gatling.javaapi.core.CoreDsl.*
import io.gatling.javaapi.core.OpenInjectionStep.atOnceUsers
import io.gatling.javaapi.core.Simulation
import io.gatling.javaapi.http.HttpDsl.http
import java.time.Duration

class ComputerDatabaseSimulation : Simulation() {

    private val warmUp = scenario("WarmUp")
        .forever()
        .on(exec(http("[WarmUp] GET /computer-database.gatling.io").get("https://computer-database.gatling.io/computers")))

    private val testScn = scenario("TestScn")
        .forever()
        .on(exec(http("[TestScn] GET /computer-database.gatling.io").get("https://computer-database.gatling.io/computers")))

    init {
        setUp(
            warmUp
                .injectOpen(atOnceUsers(5))
                .throttle(
                    reachRps(2).during(Duration.ofSeconds(5)),
                    holdFor(Duration.ofSeconds(10))
                )
                .andThen(
                    testScn
                        .injectOpen(atOnceUsers(5))
                        .throttle(
                            jumpToRps(2),
                            holdFor(Duration.ofSeconds(10))
                        )
                )
        )
    }

}

Unfortunately, only “WarmUp” scenario is executed, the “TestScn” is totally skipped:

gradle gatlingRun --simulation=ComputerDatabaseSimulation

> Task :load-tests:gatlingRun
Simulation ComputerDatabaseSimulation started...

================================================================================
2024-11-17 15:33:13 GMT                                       5s elapsed
---- Requests ------------------------------------------------------------------
> Global                                                   (OK=4      KO=0     )
> [WarmUp] GET /computer-database.gatling.io               (OK=4      KO=0     )

---- WarmUp --------------------------------------------------------------------
[--------------------------------------------------------------------------]  0%
          waiting: 0      / active: 5      / done: 0     
---- TestScn -------------------------------------------------------------------
[                                                                          ]  0%
          waiting: 5      / active: 0      / done: 0     
================================================================================


================================================================================
2024-11-17 15:33:18 GMT                                      10s elapsed
---- Requests ------------------------------------------------------------------
> Global                                                   (OK=14     KO=0     )
> [WarmUp] GET /computer-database.gatling.io               (OK=14     KO=0     )

---- WarmUp --------------------------------------------------------------------
[--------------------------------------------------------------------------]  0%
          waiting: 0      / active: 5      / done: 0     
---- TestScn -------------------------------------------------------------------
[                                                                          ]  0%
          waiting: 5      / active: 0      / done: 0     
================================================================================


================================================================================
2024-11-17 15:33:18 GMT                                      10s elapsed
---- Requests ------------------------------------------------------------------
> Global                                                   (OK=14     KO=0     )
> [WarmUp] GET /computer-database.gatling.io               (OK=14     KO=0     )

---- WarmUp --------------------------------------------------------------------
[--------------------------------------------------------------------------]  0%
          waiting: 0      / active: 5      / done: 0     
---- TestScn -------------------------------------------------------------------
[                                                                          ]  0%
          waiting: 5      / active: 0      / done: 0     
================================================================================

Parsing log file(s)...
Parsing log file(s) done in 0s.
Generating reports...

================================================================================
---- Global Information --------------------------------------------------------
> request count                                         14 (OK=14     KO=0     )
> min response time                                    118 (OK=118    KO=-     )
> max response time                                    428 (OK=428    KO=-     )
> mean response time                                   215 (OK=215    KO=-     )
> std deviation                                        121 (OK=121    KO=-     )
> response time 50th percentile                        130 (OK=130    KO=-     )
> response time 75th percentile                        360 (OK=360    KO=-     )
> response time 95th percentile                        428 (OK=428    KO=-     )
> response time 99th percentile                        428 (OK=428    KO=-     )
> mean requests/sec                                    1.4 (OK=1.4    KO=-     )
---- Response Time Distribution ------------------------------------------------
> t < 800 ms                                            14 (   100%)
> 800 ms <= t < 1200 ms                                  0 (     0%)
> t >= 1200 ms                                           0 (     0%)
> failed                                                 0 (     0%)
================================================================================

BUILD SUCCESSFUL in 15s
4 actionable tasks: 4 executed

What am I doing wrong?

Cheers!

The issue is with your forever loop in your warmUp scenario.
As expected, it make the virtual users of this scenario to loop forever, so they never complete and Gatling doesn’t proceed with the next scenario.

Maybe you’re expecting your throttle to stop all the virtual users of this scenario to stop after 15 seconds but that’s not how throttle works: the limit is lifted after 15s.

Hi,
thanks for the reply @slandelle!
As a matter of fact, I’ve already tried removing forever loop, but it doesn’t work the way I want: testScn is executed after warmUp, but we run only 5 requests per scenario.

Code sample:

import io.gatling.javaapi.core.CoreDsl.*
import io.gatling.javaapi.core.OpenInjectionStep.atOnceUsers
import io.gatling.javaapi.core.Simulation
import io.gatling.javaapi.http.HttpDsl.http
import java.time.Duration

class ComputerDatabaseSimulation : Simulation() {

    private val warmUp = scenario("WarmUp")
        .exec(http("[WarmUp] GET /computer-database.gatling.io").get("https://computer-database.gatling.io/computers"))

    private val testScn = scenario("TestScn")
        .exec(http("[TestScn] GET /computer-database.gatling.io").get("https://computer-database.gatling.io/computers"))

    init {
        setUp(
            warmUp
                .injectOpen(atOnceUsers(5))
                .throttle(
                    reachRps(2).during(Duration.ofSeconds(5)),
                    holdFor(Duration.ofSeconds(10))
                )
                .andThen(
                    testScn
                        .injectOpen(atOnceUsers(5))
                        .throttle(
                            jumpToRps(2),
                            holdFor(Duration.ofSeconds(10))
                        )
                )
        )
    }

}

Execution log:

gradle gatlingRun --simulation=ComputerDatabaseSimulation

> Task :load-tests:gatlingRun
Simulation ComputerDatabaseSimulation started...

================================================================================
2024-11-18 07:08:29 GMT                                       5s elapsed
---- Requests ------------------------------------------------------------------
> Global                                                   (OK=4      KO=0     )
> [WarmUp] GET /computer-database.gatling.io               (OK=4      KO=0     )

---- WarmUp --------------------------------------------------------------------
[###########################################################---------------] 80%
          waiting: 0      / active: 1      / done: 4     
---- TestScn -------------------------------------------------------------------
[                                                                          ]  0%
          waiting: 5      / active: 0      / done: 0     
================================================================================


================================================================================
2024-11-18 07:08:32 GMT                                       8s elapsed
---- Requests ------------------------------------------------------------------
> Global                                                   (OK=10     KO=0     )
> [WarmUp] GET /computer-database.gatling.io               (OK=5      KO=0     )
> [TestScn] GET /computer-database.gatling.io              (OK=5      KO=0     )

---- WarmUp --------------------------------------------------------------------
[##########################################################################]100%
          waiting: 0      / active: 0      / done: 5     
---- TestScn -------------------------------------------------------------------
[##########################################################################]100%
          waiting: 0      / active: 0      / done: 5     
================================================================================

Parsing log file(s)...
Parsing log file(s) done in 0s.
Generating reports...

================================================================================
---- Global Information --------------------------------------------------------
> request count                                         10 (OK=10     KO=0     )
> min response time                                    372 (OK=372    KO=-     )
> max response time                                    478 (OK=478    KO=-     )
> mean response time                                   390 (OK=390    KO=-     )
> std deviation                                         30 (OK=30     KO=-     )
> response time 50th percentile                        381 (OK=381    KO=-     )
> response time 75th percentile                        391 (OK=391    KO=-     )
> response time 95th percentile                        478 (OK=478    KO=-     )
> response time 99th percentile                        478 (OK=478    KO=-     )
> mean requests/sec                                   1.11 (OK=1.11   KO=-     )
---- Response Time Distribution ------------------------------------------------
> t < 800 ms                                            10 (   100%)
> 800 ms <= t < 1200 ms                                  0 (     0%)
> t >= 1200 ms                                           0 (     0%)
> failed                                                 0 (     0%)
================================================================================

BUILD SUCCESSFUL in 11s
4 actionable tasks: 3 executed, 1 up-to-date

The fix seems easy right now: don’t use atOnceUsers(5), use sth like constantUsersPerSec(2.0).during(Duration.ofSeconds(15)).

Code sample:

import io.gatling.javaapi.core.CoreDsl.*
import io.gatling.javaapi.core.Simulation
import io.gatling.javaapi.http.HttpDsl.http
import java.time.Duration

class ComputerDatabaseSimulation : Simulation() {

    private val warmUp = scenario("WarmUp")
        .exec(http("[WarmUp] GET /computer-database.gatling.io").get("https://computer-database.gatling.io/computers"))

    private val testScn = scenario("TestScn")
        .exec(http("[TestScn] GET /computer-database.gatling.io").get("https://computer-database.gatling.io/computers"))

    init {
        setUp(
            warmUp
                .injectOpen(constantUsersPerSec(2.0).during(Duration.ofSeconds(15)))
                .throttle(
                    reachRps(2).during(Duration.ofSeconds(5)),
                    holdFor(Duration.ofSeconds(10))
                )
                .andThen(
                    testScn
                        .injectOpen(constantUsersPerSec(2.0).during(Duration.ofSeconds(10)))
                        .throttle(
                            jumpToRps(2),
                            holdFor(Duration.ofSeconds(10))
                        )
                )
        )
    }

}

Unfortunately, testScn is not executed:

gradle gatlingRun --simulation=ComputerDatabaseSimulation

> Task :load-tests:gatlingRun
Simulation ComputerDatabaseSimulation started...

================================================================================
2024-11-18 07:17:21 GMT                                       5s elapsed
---- Requests ------------------------------------------------------------------
> Global                                                   (OK=4      KO=0     )
> [WarmUp] GET /computer-database.gatling.io               (OK=4      KO=0     )

---- WarmUp --------------------------------------------------------------------
[#########---------------                                                  ] 13%
          waiting: 20     / active: 6      / done: 4     
---- TestScn -------------------------------------------------------------------
[                                                                          ]  0%
          waiting: 20     / active: 0      / done: 0     
================================================================================


================================================================================
2024-11-18 07:17:26 GMT                                      10s elapsed
---- Requests ------------------------------------------------------------------
> Global                                                   (OK=14     KO=0     )
> [WarmUp] GET /computer-database.gatling.io               (OK=14     KO=0     )

---- WarmUp --------------------------------------------------------------------
[##################################---------------                         ] 46%
          waiting: 10     / active: 6      / done: 14    
---- TestScn -------------------------------------------------------------------
[                                                                          ]  0%
          waiting: 20     / active: 0      / done: 0     
================================================================================


================================================================================
2024-11-18 07:17:26 GMT                                      10s elapsed
---- Requests ------------------------------------------------------------------
> Global                                                   (OK=14     KO=0     )
> [WarmUp] GET /computer-database.gatling.io               (OK=14     KO=0     )

---- WarmUp --------------------------------------------------------------------
[##################################---------------                         ] 46%
          waiting: 10     / active: 6      / done: 14    
---- TestScn -------------------------------------------------------------------
[                                                                          ]  0%
          waiting: 20     / active: 0      / done: 0     
================================================================================

Parsing log file(s)...
Parsing log file(s) done in 0s.
Generating reports...

================================================================================
---- Global Information --------------------------------------------------------
> request count                                         14 (OK=14     KO=0     )
> min response time                                    353 (OK=353    KO=-     )
> max response time                                    458 (OK=458    KO=-     )
> mean response time                                   377 (OK=377    KO=-     )
> std deviation                                         23 (OK=23     KO=-     )
> response time 50th percentile                        374 (OK=374    KO=-     )
> response time 75th percentile                        376 (OK=376    KO=-     )
> response time 95th percentile                        458 (OK=458    KO=-     )
> response time 99th percentile                        458 (OK=458    KO=-     )
> mean requests/sec                                    1.4 (OK=1.4    KO=-     )
---- Response Time Distribution ------------------------------------------------
> t < 800 ms                                            14 (   100%)
> 800 ms <= t < 1200 ms                                  0 (     0%)
> t >= 1200 ms                                           0 (     0%)
> failed                                                 0 (     0%)
================================================================================

BUILD SUCCESSFUL in 13s
4 actionable tasks: 3 executed, 1 up-to-date

Can you please help me fix the above example? Much appreciated, thanks

That’s a bad interaction between:

  • sequential scenarios
  • and the behavior of throttle
  • Gatling will automatically interrupt your test at the end of the throttle, just like it does with maxDuration.

It looks pretty complicated to change this, don’t expect a solution any time soon.

I recommend that you go with another solution than throttle and design you scenario and your injection profile in a proper way to generate your expected traffic.

init {
  setUp(
        warmUp
            .injectOpen(
                rampUsersPerSec(0.0).to(2.0).during(5),
                constantUsersPerSec(2.0).during(10)
            )
            .andThen(
                testScn
                    .injectOpen(
                        constantUsersPerSec(2.0).during(10)
                    )
            )
    )
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.