Skip to content

Commit 83023e3

Browse files
committed
added ManualCluster Example
1 parent c0c85b6 commit 83023e3

File tree

9 files changed

+127
-22
lines changed

9 files changed

+127
-22
lines changed
Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using NBomber.CSharp;
1+
using NBomber.Contracts;
2+
using NBomber.CSharp;
23
using NBomber.Http;
34
using NBomber.Http.CSharp;
45
using NBomber.Plugins.Network.Ping;
@@ -8,31 +9,40 @@ namespace Demo.Cluster.AutoCluster;
89
public class AutoClusterExample
910
{
1011
public void Run()
12+
{
13+
var scenario = BuildScenario();
14+
StartNode(scenario);
15+
}
16+
17+
private void StartNode(ScenarioProps scenario)
18+
{
19+
NBomberRunner
20+
.RegisterScenarios(scenario)
21+
.WithWorkerPlugins(
22+
new PingPlugin(PingPluginConfig.CreateDefault("nbomber.com")),
23+
new HttpMetricsPlugin(new [] { HttpVersion.Version1 })
24+
)
25+
.LoadConfig("Cluster/AutoCluster/autocluster-config.json") // you can use: --config=Cluster/ManualCluster/manual-cluster-config.json
26+
.EnableLocalDevCluster(true) // you can use: --cluster-local-dev=true
27+
.Run(); // more info about available CLI args: https://nbomber.com/docs/getting-started/cli/
28+
}
29+
30+
private ScenarioProps BuildScenario()
1131
{
1232
using var httpClient = new HttpClient();
1333

14-
var scenario = Scenario.Create("http_scenario", async context =>
34+
return Scenario.Create("http_scenario", async context =>
1535
{
1636
var request =
1737
Http.CreateRequest("GET", "https://nbomber.com")
1838
.WithHeader("Content-Type", "application/json");
19-
// .WithBody(new StringContent("{ some JSON }", Encoding.UTF8, "application/json"));
39+
// .WithBody(new StringContent("{ some JSON }", Encoding.UTF8, "application/json"));
2040

2141
var response = await Http.Send(httpClient, request);
2242

2343
return response;
2444
})
2545
.WithoutWarmUp()
2646
.WithLoadSimulations(Simulation.Inject(rate: 10, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromSeconds(30)));
27-
28-
NBomberRunner
29-
.RegisterScenarios(scenario)
30-
.WithWorkerPlugins(
31-
new PingPlugin(PingPluginConfig.CreateDefault("nbomber.com")),
32-
new HttpMetricsPlugin(new [] { HttpVersion.Version1 })
33-
)
34-
.LoadConfig("Cluster/AutoCluster/autocluster-config.json")
35-
.EnableLocalDevCluster(true)
36-
.Run();
3747
}
3848
}

examples/Demo/Cluster/AutoCluster/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ In order to run that demo you should spin-up NATS message broker via docker-comp
1313
docker compose up
1414
```
1515

16-
After this you need start 2 instances of NBomber.
17-
1816
Useful links:
1917
- [Cluster overview](https://nbomber.com/docs/cluster/overview)
2018
- [How to run cluster](https://nbomber.com/docs/cluster/run-cluster)

examples/Demo/Cluster/AutoCluster/docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
services:
33

44
nats:
5-
image: "nats:2.9.6"
5+
image: "nats:2.9.9"
66
command: --js
77
ports:
88
- "8222:8222"
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using NBomber.Contracts;
2+
using NBomber.Contracts.Stats;
3+
using NBomber.CSharp;
4+
using NBomber.Http;
5+
using NBomber.Http.CSharp;
6+
using NBomber.Plugins.Network.Ping;
7+
8+
namespace Demo.Cluster.ManualCluster;
9+
10+
public class ManualClusterExample
11+
{
12+
public void Run(string[] args)
13+
{
14+
var scenario = BuildScenario();
15+
StartNode(scenario, args);
16+
}
17+
18+
private void StartNode(ScenarioProps scenario, string[] args)
19+
{
20+
NBomberRunner
21+
.RegisterScenarios(scenario)
22+
.WithWorkerPlugins(
23+
new PingPlugin(PingPluginConfig.CreateDefault("nbomber.com")),
24+
new HttpMetricsPlugin(new [] { HttpVersion.Version1 })
25+
)
26+
.LoadConfig("Cluster/ManualCluster/manual-cluster-config.json") // you can use: --config=Cluster/ManualCluster/manual-cluster-config.json
27+
.EnableLocalDevCluster(true) // you can use: --cluster-local-dev=true
28+
.Run(args); // more info about available CLI args: https://nbomber.com/docs/getting-started/cli/
29+
}
30+
31+
private ScenarioProps BuildScenario()
32+
{
33+
using var httpClient = new HttpClient();
34+
35+
return Scenario.Create("http_scenario", async context =>
36+
{
37+
var request =
38+
Http.CreateRequest("GET", "https://nbomber.com")
39+
.WithHeader("Content-Type", "application/json");
40+
// .WithBody(new StringContent("{ some JSON }", Encoding.UTF8, "application/json"));
41+
42+
var response = await Http.Send(httpClient, request);
43+
44+
return response;
45+
})
46+
.WithoutWarmUp()
47+
.WithLoadSimulations(Simulation.Inject(rate: 10, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromSeconds(30)));
48+
}
49+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: "3.4"
2+
services:
3+
4+
nats:
5+
image: "nats:2.9.9"
6+
command: --js
7+
ports:
8+
- "8222:8222"
9+
- "4222:4222"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"TestSuite": "my test suite",
3+
"TestName": "my test",
4+
5+
"ClusterSettings": {
6+
7+
"ManualCluster": {
8+
"ClusterId": "test_cluster",
9+
"NATSServerURL": "nats://localhost",
10+
11+
"Coordinator": {
12+
"TargetScenarios": ["http_scenario"]
13+
},
14+
15+
"Agent": {
16+
"AgentGroups": [{"AgentGroup": "1", "TargetScenarios": ["http_scenario"]}],
17+
"AgentsCount": 1
18+
}
19+
20+
}
21+
22+
}
23+
}

examples/Demo/Demo.csproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212
<None Update="Cluster\AutoCluster\autocluster-config.json">
1313
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
1414
</None>
15-
<None Update="Features\RealtimeReporting\InfluxDB\influx_v2\infra-config.json">
15+
<None Update="Cluster\ManualCluster\manual-cluster-config.json">
1616
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
1717
</None>
18+
<None Update="Features\RealtimeReporting\InfluxDB\influx_v2\infra-config.json">
19+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
20+
</None>
1821
</ItemGroup>
1922

2023
<ItemGroup>
@@ -34,7 +37,7 @@
3437
<PackageReference Include="Bogus" Version="34.0.2" />
3538
<PackageReference Include="Dapper.Contrib" Version="2.0.78" />
3639
<PackageReference Include="LiteDB" Version="5.0.15" />
37-
<PackageReference Include="NBomber" Version="5.2.2" />
40+
<PackageReference Include="NBomber" Version="5.3.0" />
3841
<PackageReference Include="NBomber.Data" Version="5.0.0" />
3942
<PackageReference Include="NBomber.Http" Version="5.0.0" />
4043
<PackageReference Include="NBomber.Sinks.InfluxDB" Version="5.0.1" />

examples/Demo/HelloWorld/HelloWorldExample.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@ public void Run()
1111
// you can define and execute any logic here,
1212
// for example: send http request, SQL query etc
1313
// NBomber will measure how much time it takes to execute your logic
14-
await Task.Delay(1000);
14+
await Task.Delay(500);
1515

1616
return Response.Ok();
1717
})
1818
.WithoutWarmUp()
1919
.WithLoadSimulations(
20-
Simulation.RampingInject(rate: 150, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromMinutes(1)), // rump-up to rate 150
21-
Simulation.Inject(rate: 150, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromSeconds(30)), // keep injecting with rate 150
22-
Simulation.RampingInject(rate: 0, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromMinutes(1)) // rump-down to rate 0
20+
Simulation.Inject(rate: 1, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromSeconds(30)) // keep injecting with rate 150
2321
);
2422

2523
NBomberRunner

examples/Demo/Program.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Demo.Cluster.AutoCluster;
2+
using Demo.Cluster.ManualCluster;
23
using Demo.DB.LiteDB;
34
using Demo.DB.Redis;
45
using Demo.DB.SQLiteDB;
@@ -78,5 +79,19 @@
7879
// ---------------------
7980
// ----- Cluster -------
8081
// ---------------------
82+
83+
// ----- Auto Cluster -------
84+
// in order to run this example you should start 2 instances of NBomber,
85+
// for this, you need to run this NBomber application twice
86+
87+
// new AutoClusterExample().Run();
8188
// new AutoClusterExample().Run();
8289

90+
// ----- Manual Cluster -------
91+
// in order to run this example you should start 2 instances of NBomber,
92+
// - first instance will act as Coordinator
93+
// - second instance will act as Agent
94+
95+
// new ManualClusterExample().Run(args: new [] { "--cluster-node-type=coordinator" });
96+
// new ManualClusterExample().Run(args: new [] { "--cluster-node-type=agent", "--cluster-agent-group=1" });
97+

0 commit comments

Comments
 (0)