Any alternative to randomSwitch() to distribute requests amongst multiple scenarios/chainbuilders?

Hello Folks,

I am trying to identify an alternative to randomSwitch for distributing load amongst different chainbuilders based on percentage.
The problem that I see with randomSwitch is it doesn’t exactly follow the weights defined example 5 and 95 split. Sometimes i’ll get 3% and 97% others i’ll get 1% and 99% and so on… but doesn’t guarantee 5% and 95%.

I tried something like this (sudo code) but it didn’t even put the groups in report:

ScenarioBuilder fixedFlow = scenario ("Scenario for Fixed Flow")
    .exec(mb.generateTraceId)
            .group("Fixed").on(exec(session -> {
                int nextCount = 0;
                nextCount++;
                if (nextCount % 100 < 2) {
                    group("Users with large fixed")
                            .on(feed(mfixedFeeder.circular()))
                            .exec(new LDSimulation().getMLDJourney());
                } else {
                    group("Users with Less fixed")
                            .on(feed(ldFeeder.circular()))
                            .exec(new LDSimulation().getMLDJourney());
                }
                return session;
            }))

When I write this, I see that it gets executed (may be as if I put print statements inside if else, they are getting printed and hence I am thinking execs are also getting executed) but it does not appear int he report.

Hence could someone please suggest an alternative to randomSwitch which guarantees weights or could someone help me correct my code so that the chainbuilders getting executed inside exec inside session gets included inthe report. Thanks for your help in advance.

Hi @Raghvendra,

The code you provide cannot work. As stated in the first alert box of the documentation: Gatling - Concepts

The components of this DSL are mere definitions of the desired effect. They don’t generate the desired effect where you invoke them in your own code. Only when chained with other components so they are ultimately passed to the setUp, can the Gatling engine interpret them and produce the desired effect.

My feelings about your use case is that they are different category of users, so they should be described by different scenario.

ScenarioBuilder createFixedFlow(String scnName, Feeder feeder) {
  return scenario ("Scenario for " + scnName + " Fixed Flow")
    .exec(mb.generateTraceId)
            .group("Fixed").on(
                    group("Users with " + scnName + " fixed")
                            .on(feed(feeder))
                            .exec(new LDSimulation().getMLDJourney());
            );
}

ScenarioBuilder mfixedScn = createFixedFlow("large",  mfixedFeeder.circular());
ScenarioBuilder ldFixedScn = createFixedFlow("Less",  ldFeeder.circular());

Then you can inject the amount of user you want in the setUp call.

Does that help?

Cheers!

That being said, you can achieve the desired algorithm:

  • use a global atomic counter for nextCount
  • compute the distribution condition in an exec(function) block
  • use doSwitch based on this condition

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