user3817378
user3817378

Reputation: 131

Running multiple Gatling Scenario randomly with constant rate

I defined 5 scenarios as below:

ScenarioBuilder s1 = scenario("S1").exec(getAuthenticationChain()).exec(createProduct(150, "S1"))
ScenarioBuilder s2 = scenario("S2").exec(getAuthenticationChain()).exec(createProduct(10, "S2"))
ScenarioBuilder s3 = scenario("S3").exec(getAuthenticationChain()).exec(createProduct(30, "S3"))
ScenarioBuilder s4 = scenario("S4").exec(getAuthenticationChain()).exec(createProduct(60, "S4"))
ScenarioBuilder s5 = scenario("S5").exec(getAuthenticationChain()).exec(createProduct(80, "S5"))

Now one of the requirement is:

Of all the users or requests , 
s1 should be executed 50% of total request , 
s2 10% of total request , 
s3 20% of total request , 
s4-> 15% , 
s5-> 5% .

Lets say I am running the simulation for 900 secs, the no of users/requests executed by every scenarious are:

s1: 900*50/100 = 450
s2: 900*10/100 = 90
s3: 900*20/100 = 180
s4: 900*15/100 = 135
s5: 900*5/100 = 45

I have written the Gatling simulation like this:

{
    setUp(
     s1.injectOpen(constantUsersPerSec(0.50).during(900)).protocols(getSignInHeaders()),
     s2.injectOpen(constantUsersPerSec(0.10).during(900)).protocols(getSignInHeaders()),
     s3.injectOpen(constantUsersPerSec(0.20).during(900)).protocols(getSignInHeaders()),
     s4.injectOpen(constantUsersPerSec(0.15).during(900)).protocols(getSignInHeaders()),
     s5.injectOpen(constantUsersPerSec(0.05).during(900)).protocols(getSignInHeaders())
    )
}

I am able to run the test , but the problem is all these scenario are running in parallel, I want to execute every request of every scenario in random order and with constant rate of 1 user/request per sec.

lets say s1: will execute 450 requests, s1r1.......s1r450
s2: s2r1.........s2r90
s3: s3r1.........s3r180
s4: s4r1.........s4r135
s5: s5r1......s5r45

Ask: How can i write a scenario to execute all these requests in random order and with constant rate of 1 user/request per sec.?

Failed Attempts tried:

I tried executing them in sequence:

{
    setUp(
     s1.injectOpen(constantUsersPerSec(0.50).during(900)).andThen(
            s2.injectOpen(constantUsersPerSec(0.10).during(900)).andThen(
                s3.injectOpen(constantUsersPerSec(0.20).during(900)).andThen(
                    s4.injectOpen(constantUsersPerSec(0.15).during(900)).andThen(
                        s5.injectOpen(constantUsersPerSec(0.05).during(900))
                    )

                )

            )
     ).protocols(getSignInHeaders());
}

this executed all the requests of s1 first and then all the request of s2 and then all the request of s3 and so on.

But I want all the requests of all scenario to be executed with constant rate and in random order. Please help me. Thanks.

Note : I am using Gatling Maven plugin version 4.5.0 and Gatling DSL to write the code.

<plugin>
  <groupId>io.gatling</groupId>
  <artifactId>gatling-maven-plugin</artifactId>
  <version>4.5.0</version>
</plugin>

Upvotes: 0

Views: 264

Answers (1)

Amerousful
Amerousful

Reputation: 2545

It's a wrong strategy to use multiple scenarios for this case. Because, in general, you have the same scenario. In other words, your chain of actions(requests) doesn't change.
For your case, Gatling has the method randomSwitch, documentation.
With this method, you can specify a percentage for a particular request.

scenario("Scenario")
  .exec(getAuthenticationChain())
  .randomSwitch( // beware: use parentheses, not curly braces!
     50.0 -> exec(createProduct(150, "S1")),
     10.0 -> exec(createProduct(10, "S2")),
     ... and so on ...
)

Upvotes: 1

Related Questions