Hi @trinp,
I also faced similar situations not long ago, so maybe my findings will be helpful.
This behavior can be achieved in different ways — each with its own pros and cons.
ClosedModel
/// Pros: Assign specified users to a specific flow
/// Cons: RPS for specific requests drops if response time > 1s
static long duration = 60;
private static final ScenarioBuilder scenarioA = scenario("demo")
.doSwitchOrElse(session -> session.userId()).on(
onCase(1).then(during(duration).on(pace(1).exec(dummy("requestA","#{randomInt(500,1500)}")))),
onCase(2).then(during(duration).on(pace(2).exec(dummy("requestB","#{randomInt(500,1500)}"))))
).orElse(
dummy("otherFancyStuff","#{randomInt(500,800)}"),
pause(1)
);
{
setUp(scenarioA.injectClosed(constantConcurrentUsers(5).during(duration)));
}
OpenModel - FizzBuzz style
/// Pros: Double rates can be used (e.g., 0.5, 0.7)
/// Cons: RPS for specific requests drops if response time > 1s
static long duration = 60;
static double rate = 1;
private static final ScenarioBuilder scenarioB = scenario("demo").exec(
/// 1/1 rate
dummy("requestA", "#{randomInt(300,500)}"),
/// 1/2 rate
doIf(session -> session.userId() % 2 == 0).then(
dummy("requestB", "#{randomInt(300,500)}")
),
/// 1/3 rate
doIf(session -> session.userId() % 3 == 0).then(
dummy("requestC", "#{randomInt(300,500)}")
)
);
{
setUp(scenarioB.injectOpen(constantUsersPerSec(rate).during(duration)));
}
OpenModel (This is the most optimal approach if you need to hold strict RPS)
/// Pros:
// - Double rates can be used (e.g., 0.5, 0.7)
// - Response time does not affect RPS for specific requests
/// Cons: uniq name for scenario =(
static long duration = 60;
static double rate = 1;
private static final ScenarioBuilder scenarioA = scenario("demo1").exec(
dummy("requestA", "#{randomInt(300,500)}")
);
private static final ScenarioBuilder scenarioB = scenario("demo2").exec(
dummy("requestB", "#{randomInt(300,500)}")
);
{
setUp(
scenarioA.injectOpen(constantUsersPerSec(rate).during(duration)),
scenarioB.injectOpen(constantUsersPerSec(rate / 2 ).during(duration))
);
}