繁体   English   中英

即使我们指定副本,nBomber 也会运行数百次:1

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

我刚刚遇到这个非常好的 .NET 负载测试工具,我写了我的第一个代码:

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();

但是,当我运行它时,我看到Step was executed了数百次。 我指定copies: 1, during: TimeSpan.FromSeconds(10)所以根据我的理解,它应该只在 10 秒内运行一次。 为什么它运行了很多次

为什么它运行了很多次

根据此Load Simulations Intro示例, KeepConstant运行固定数量的场景副本(线程)并在指定的时间内执行尽可能多的迭代。”


目前还不清楚您想要的场景是什么。

  • 你想让它只运行一次,但需要 10 秒吗? 如果是这样,您可以在连接步骤后向场景添加一个休眠 10 秒的步骤,并从场景中删除.WithLoadSimulations

  • 您是否希望场景运行多次,但每 10 秒只运行一次? 如果是这样,您可以在连接步骤后向场景添加一个休眠 10 秒的步骤,然后向负载模拟添加更长的持续时间:

例如:

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)));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM