Comments (11)
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.
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.
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.
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.
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.
For benchmarking, I suggest you to look at https://benchmarkdotnet.org/
from nbomber.
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.
btw you dont need lock here, NBomber will run each scenario on dedicated Task/Thread
lock (counts)
{
counts[threadIndex]++;
}
from nbomber.
Try to use Iterations for Inject.
from nbomber.
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.
@AntyaDev Thank you for your advice. I am trying KeepConstant simulation now. This seems to be a good choice.
from nbomber.
Related Issues (20)
- Implement Step.RunHidden to not show a step in the report HOT 14
- Show Standard Deviation in Report HOT 1
- Add Bytes extensions API
- Problem with license validation HOT 6
- Feature Request: Provide a way for a scenario to detect that the scenario is ending.
- Add hint if Warmup is None
- Reporting maxes out at about 12 minutes HOT 3
- Provide list of license servers
- Add ability to start measuring stats after some period of time.
- Improve license validation
- Backwards compatibility issues with NATS Client
- Add a Hidden Step support HOT 1
- Add ReportFinalizer handler to allow manipulation of final data for report generation
- ClientPool - extending pool / add new clients dynamically HOT 4
- Client Pool - clean client before it can be reused HOT 1
- AutoCluster - NBomber generated reports duplicating step data information
- Unhandled exception: MetricsStatsActor failed HOT 3
- Add CLI argument to set SessionId
- AutoCluster - Grafana dashboard isn't displaying Status Codes
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nbomber.