User Drops in Scenario

Hi Team,

I am looking to execute performance testing with use case,

lets say I have Scenario with 5 Http request of chain and would like to execute first Request with 100% configured threads/Vusers then drop threads by 10% for second transitions and 3rd transition by 10%.

*do we have any function available in Gatling to configure such scenario?*

Ex.

 val scn = scenario("Login")
       .exec( .                    // 100%
     http("Request1")
       .get("Request-1")
       .check(status is 302)
       .disableFollowRedirect

   ).pause(2 seconds)

   .exec( .                          //90%
       http(**"****Request****"**)
         .post("**Request-2**")
         .body(StringBody(loginReqeustBody))
         .asJson
         .disableFollowRedirect
     ).pause(2 seconds)
       .exec(                      //80%
       http("**Request**")
         .get("**Request-3**")
         .check(status is 302)
     ).pause(5 seconds)
      . exec(
       http("**Request**")             //80%
         .post("**Request-4**")
.body(RawFileBody("tokenRequest.json")).asJSON

Create a random number between 0 to 100 and specif icy the condition which are the requests need to be included in that.
e.g val randomInt = ThreadLocalRandom.current.nextInt(100)

Have this in your journey/scenario setup.
.doIf(session => session(“randomInt”).as[Int] <=100){exec(Request-1)}

.doIf(session => session(“randomInt”).as[Int] <=90){exec(Request-2)}

.doIf(session => session(“randomInt”).as[Int] <=80){exec(**Request-3,****Request-4,**Request-5)}

In this case you, if you are requests are large enough the distribution is closer to expected.

Hi Mohana Reddy,

Thanks for the response.

how to ensure that Request-1 will execute 100% and the subsequent Request-2 will execute 90% and soo on**.** because here is a random number getting for each thread.

below is my script, I do have simulation setup for to run for 15min with 10 Vusers and 120 sec rampup. so these 10 threads will be active till 15min.

Ex. one thread start with Request1 will execute till Request5. and same thready will reiterate again till 15min. in this case i wanted to execute Request1 100% and Request2 90% of 100% and Request3 80% of 90%.

val scn = scenario("Login").during(15 minutes){
       .exec( .                    // 100%
     http("Request1")
       .get("Request-1")
       .check(status is 302)
       .disableFollowRedirect

   ).pause(2 seconds)

   .exec( .                          //90%
       http(**"****Request****"**)
         .post("**Request-2**")
         .body(StringBody(loginReqeustBody))
         .asJson
         .disableFollowRedirect
     ).pause(2 seconds)
       .exec(                      //80%
       http("**Request**")
         .get("**Request-3**")
         .check(status is 302)
     ).pause(5 seconds)
      . exec(
       http("**Request**")             //80%
         .post("**Request-4**")
.body(RawFileBody("tokenRequest.json")).asJSON

Hello All,
did any work on this kind scenario? where we need to drop vusers at every transaction in scenario?

Hi!

I can understand your use case from different perspectives.

1. Different user kinds

The quitters (the one that only perform the first request)
The early (both two first requests)
The long performers (all 3 requests)

So you should define 3 different scenarios (that can use common code, of course)

val quitterScn = scenario("Quitter")
  .exec(firstStep)

val earlyScn = scenario("Early")
  .exec(firstStep)
  .exec(secondStep)

val longPerformerScn = scenario("Long performer")
  .exec(firstStep)
  .exec(secondStep)
  .exec(thirdStep)

setUp(
  quitterScn.inject(???),
  earlyScn.inject(???),
  longPerformerScn.inject(???)
)

It’s flexible and you can control exactly the amount of users injected for each case.

2. Statically distributed

Close to what suggests @G_Madhana_Mohana_Red, you can use randomSwitch.

  val scn = scenario("Scenario")
    .exec(firstStep)
    .randomSwitch(
      90.0 -> exec(secondStep)
        .randomSwitch(90.0 -> exec(thirdStep))
    )

With the theory of large numbers, you should be close to the expected output.

3. Based on user rank

You can create a custom feeder to have a distinct number for each user.

  val myCountFeeder: Feeder[Int] = Iterator.from(1).map(num => Map("userNumber" -> num))

  val scn2 = scenario("Scenario")
    .feed(myCountFeeder)
    .exec(firstStep)
    .doIf(_("userNumber").as[Int] % 100 <= 90)(
      exec(secondStep).doIf(_("userNumber").as[Int] % 100 <= 80)(
        exec(thirdStep)
      )
    )

Which solution do you prefer?

Cheers!

Hi @sbrevet, I am really interested on your last suggestion: 3. Based on user rank
I tried this but the result was not exactly what I was expecting.

Let’s says the percentages are a little bit different like this:

val scn2 = scenario("Scenario")
    .feed(myCountFeeder)
    .exec(firstStep)
    .doIf(_("userNumber").as[Int] % 100 <= 20)(
      exec(secondStep).doIf(_("userNumber").as[Int] % 100 <= 10)(
        exec(thirdStep)
      )
    )

For example for a total of 300 users the number that reach secondStep was 63 and thirdStep was 33.
I was expecting 60 and 30 or at least that is what I am looking for.

Don’t you mind help me to understand better this.
Thanks in advance!

First, @sbrevet 's algorithm has an off-by-one error :wink:.

Counter starts at 1 and condition uses <= so for 300 users, (1 to 20) + (100 to 120) + (200 to 220) + (300) = 20 + 21 + 21 + 1 = 63 users will execute secondStep.
The counter must start at 0 and the condition use < so you get (0 to 19) + (100 to 119) + (200 to 219) = 60 users.

Then, there’s no need for this myCountFeeder if you’re using one single scenario as users have a builtin global counter.

val scn = scenario("Scenario")
    .exec(firstStep)
    .doIf(_.userId % 100 < 20) {
        exec(secondStep)
        .doIf(_.userId % 100 < 10) {
            exec(thirdStep)
        }
    }

@slandelle that make sense! Thank you!