nBomber runs hundreds of times even if we specify copies:1

427 Views Asked by At

I just came across this very nice load testing tool for .NET and I wrote my first code:

var connectStep = Step.Create("ConnectReceive", async context =>
{
    Console.WriteLine("Step was executed.");

    return Response.Ok();
});

var scenario = ScenarioBuilder.CreateScenario("LotsOfConnections", connectStep)
    .WithLoadSimulations(Simulation.KeepConstant(copies: 1, during: TimeSpan.FromSeconds(10)));

NBomberRunner.RegisterScenarios(scenario).Run();

However when I run this I see Step was executed hundreds of times in my console screen. I specified copies: 1, during: TimeSpan.FromSeconds(10) so based on my understanding it should only run once within a period of 10 seconds. why is it running numerous times

1

There are 1 best solutions below

0
Rufus L On

why is it running numerous times

According to this Load Simulations Intro sample, "KeepConstant runs a fixed number of scenario copies (threads) and executes as many iterations as possible for a specified amount of time."


It's not exactly clear what the scenario is that you want.

  • Do you want it to just run once, but take 10 seconds? If so, you could add a step to the scenario that sleeps for 10 seconds after the connect step, and remove the .WithLoadSimulations from the scenario.

  • Do you want the scenario to run many times, but only once every 10 seconds? If so, you could add a step to the scenario that sleeps for 10 seconds after the connect step, and then add a longer duration to the load simulation:

For example:

var connectStep = Step.Create("ConnectReceive", async context =>
{
    Console.WriteLine("Step was executed.");    
    return Response.Ok();
});

var sleepStep = Step.Create("Sleep", async context =>
{
    await Task.Delay(TimeSpan.FromSeconds(10));
    return Response.Ok();
});

// Connect to our system once every 10 seconds for a minute
var scenario = ScenarioBuilder
    .CreateScenario("ManyConnections", connectStep, sleepStep);
    .WithLoadSimulations(Simulation.KeepConstant(copies: 1, 
        during: TimeSpan.FromMinutes(1)));