Search code examples
scalagatling

Multiple Gatling simulations in parallel with different rampUsers over different times


I have multiple Gatling simulations defined in this manner (imports removed).

class MySimulation1 extends Simulation {
    object SimulationObj1 {
        var feeder = ...
        var random = exec(...)
    }

    val httpProtocol = ...
    val myScenario = scenario("Scenario name").exec(SimulationObj1.random)
    setUp(myScenario.inject(
        rampUsers(10) over (180 seconds)
        )
    )
    .assert(...)
}

class MySimulation2 extends Simulation {
    object SimulationObj2 {
        var feeder = ...
        var random = exec(...)
    }

    val httpProtocol = ...
    val myScenario = scenario("Scenario name").exec(SimulationObj2.random)
    setUp(myScenario.inject(
        rampUsers(15) over (300 seconds)
        )
    )
    .assert(...)
}

And then there's another AllSimulations class that simply calls all the simulations so that the scenarios in them could be executed in parallel.

class AllSimulations extends Simulation {
    object AllSimulationsObj {
        var feeder = ...
        var random = exec(...)
    }

    val httpProtocol = ...
    val myScenario = scenario("All scenarios").exec(
        new MySimulation1().SimulationObj1.random,
        new MySimulation2().SimulationObj2.random)
    setUp(myScenario.inject(
        rampUsers(10) over (180 seconds)
        )
    )
    .assert(...)
}

The problem is that, in order to have different rampUsers count over different durations, I'm removing the setUp block from AllSimulations class, but that gives me an error "No scenario set up".

How do I possibly run all the simulation scenarios in parallel with the rampUsers and durations defined in the respective simulation classes?

EDIT: Here's what I tried, but I'm not sure if it makes sense.

    class AllSimulations extends Simulation {

        setUp(
            new MySimulation1().myScenario.inject(rampUsers(10) over (180 seconds)),
            new MySimulation2().myScenario.inject(rampUsers(15) over (300 seconds))
        )
        .assert(...)
    }

Solution

  • If u want to run two or more scenarios concurrently or simultaneously or parallelly then let's say u have two files (EXAMPLE1.scala and EXAMPLE2.scala). U have to make a separate file (Simulator.scala) like shown below.

    EXAMPLE1.SCALA (FILE-1)

    ...
    val Example1_scenario = scenario("EXAMPLE1").exec(RunningForAllTenants())
    ...
    

    EXAMPLE2.SCALA (FILE-2)

    ...
    val Example2_scenario = scenario("EXAMPLE2").exec(RunningForAllTenants())
    ...
    

    Simulator.scala

    class Simulator extends Simulation
    {
    
      setUp **(** new EXAMPLE1().Example1_scenario.inject(rampUsers(10) during (10) **)** .protocols(httpConf1),
    
      setUp **(** new EXAMPLE2().Example2_scenario.inject(rampUsers(30) during (20) **)** .protocols(httpConf1),
    
    }
    

    Run Simulator.scala which will automatically run EXAMPLE1.scala and EXAMPLE2.scala concurrently