Git Product home page Git Product logo

Comments (11)

AntyaDev avatar AntyaDev commented on May 25, 2024
var scenario = Scenario.Create("MultiThread", async scenectx =>
        {
            var callIndex = scenectx.InvocationNumber;

            scenectx.Logger.Warning($"INSTANCE NUMBER {callIndex}");

            return Response.Ok();
        })
        .WithoutWarmUp()
        .WithLoadSimulations(
            Simulation.IterationsForConstant(copies: 4, iterations: 4)
        );

from nbomber.

CDboyOne avatar CDboyOne commented on May 25, 2024
var scenario = Scenario.Create("MultiThread", async scenectx =>
        {
            var callIndex = scenectx.InvocationNumber;

            scenectx.Logger.Warning($"INSTANCE NUMBER {callIndex}");

            return Response.Ok();
        })
        .WithoutWarmUp()
        .WithLoadSimulations(
            Simulation.IterationsForConstant(copies: 4, iterations: 4)
        );

Thanks for your response. I ran your code and got the following log:

2024-04-12 23:06:37.263 +08:00 [WRN] [ThreadId:7] INSTANCE NUMBER 1
2024-04-12 23:06:37.265 +08:00 [WRN] [ThreadId:7] INSTANCE NUMBER 2
2024-04-12 23:06:37.265 +08:00 [WRN] [ThreadId:7] INSTANCE NUMBER 3
2024-04-12 23:06:37.265 +08:00 [WRN] [ThreadId:7] INSTANCE NUMBER 4

The ThreadId is same (7), but what I want is 4 different ThreadId. How can I get copies running on different threads?

from nbomber.

AntyaDev avatar AntyaDev commented on May 25, 2024

It's because of the scheduling. NBomber is using TPL (Task library) for multithreading. Please try to introduce some await like task.Delay() inside your scenario. And also run more iterations.

from nbomber.

AntyaDev avatar AntyaDev commented on May 25, 2024

Since your load test does nothing the scheduler is quite smart to optimise it. Try to introduce some pause or send HTTP request for example.

from nbomber.

CDboyOne avatar CDboyOne commented on May 25, 2024

Since your load test does nothing the scheduler is quite smart to optimise it. Try to introduce some pause or send HTTP request for example.

Thanks! I used the following code to print the invocation count of each instance:

using NBomber.CSharp;

int NCOPY = 4;
int[] counts = new int[NCOPY];
counts.AsSpan().Fill(0);

var scenario = Scenario.Create("MultiThread", async scenectx =>
{
    int threadIndex = scenectx.ScenarioInfo.InstanceNumber;
    lock (counts)
    {
        counts[threadIndex]++;
    }

    await Task.Delay(5);
    
    return Response.Ok();
})
.WithoutWarmUp()
.WithLoadSimulations(
    Simulation.IterationsForConstant(copies: 4, iterations: 100)
);

NBomberRunner.RegisterScenarios(scenario).Run();

for (int i = 0; i < counts.Length; i++)
    Console.WriteLine($"Instance {i} called {counts[i]} times.");

When I use await Task.Delay(5); I got:

Instance 0 called 3 times.
Instance 1 called 51 times.
Instance 2 called 0 times.
Instance 3 called 46 times.

When I use await Task.Delay(500); I got:

Instance 0 called 25 times.
Instance 1 called 26 times.
Instance 2 called 24 times.
Instance 3 called 25 times.

I want to mock the situation that 4 threads are calling my method at the same time, so I need to get invocations distributed on each scenario instance equally. But it seems impossible when my method is fast. How can I reach my purpose?

from nbomber.

AntyaDev avatar AntyaDev commented on May 25, 2024

For benchmarking, I suggest you to look at https://benchmarkdotnet.org/

from nbomber.

CDboyOne avatar CDboyOne commented on May 25, 2024

For benchmarking, I suggest you to look at https://benchmarkdotnet.org/

Actually I need to do load test with a set of different test cases, and measure the average time and other statistics on the set. But BenchmarkDotNet will do benchmarking on each case separately, which cannot satisfy my need.

from nbomber.

AntyaDev avatar AntyaDev commented on May 25, 2024

btw you dont need lock here, NBomber will run each scenario on dedicated Task/Thread

lock (counts)
{
    counts[threadIndex]++;
}

from nbomber.

AntyaDev avatar AntyaDev commented on May 25, 2024

Try to use Iterations for Inject.

from nbomber.

AntyaDev avatar AntyaDev commented on May 25, 2024

Ah sorry, I am wrong about your usage of lock. You need to use it.
If you work with primitive number I suggest you consider Interlocked.Increment

from nbomber.

CDboyOne avatar CDboyOne commented on May 25, 2024

@AntyaDev Thank you for your advice. I am trying KeepConstant simulation now. This seems to be a good choice.

from nbomber.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.