diff --git a/examples/Demo/Cluster/AutoCluster/AutoClusterExample.cs b/examples/Demo/Cluster/AutoCluster/AutoClusterExample.cs index 9f09b48c..4a305b40 100644 --- a/examples/Demo/Cluster/AutoCluster/AutoClusterExample.cs +++ b/examples/Demo/Cluster/AutoCluster/AutoClusterExample.cs @@ -1,4 +1,5 @@ -using NBomber.CSharp; +using NBomber.Contracts; +using NBomber.CSharp; using NBomber.Http; using NBomber.Http.CSharp; using NBomber.Plugins.Network.Ping; @@ -8,15 +9,34 @@ namespace Demo.Cluster.AutoCluster; public class AutoClusterExample { public void Run() + { + var scenario = BuildScenario(); + StartNode(scenario); + } + + private void StartNode(ScenarioProps scenario) + { + NBomberRunner + .RegisterScenarios(scenario) + .WithWorkerPlugins( + new PingPlugin(PingPluginConfig.CreateDefault("nbomber.com")), + new HttpMetricsPlugin(new [] { HttpVersion.Version1 }) + ) + .LoadConfig("Cluster/AutoCluster/autocluster-config.json") // you can use: --config=Cluster/ManualCluster/manual-cluster-config.json + .EnableLocalDevCluster(true) // you can use: --cluster-local-dev=true + .Run(); // more info about available CLI args: https://nbomber.com/docs/getting-started/cli/ + } + + private ScenarioProps BuildScenario() { using var httpClient = new HttpClient(); - var scenario = Scenario.Create("http_scenario", async context => + return Scenario.Create("http_scenario", async context => { var request = Http.CreateRequest("GET", "https://nbomber.com") .WithHeader("Content-Type", "application/json"); - // .WithBody(new StringContent("{ some JSON }", Encoding.UTF8, "application/json")); + // .WithBody(new StringContent("{ some JSON }", Encoding.UTF8, "application/json")); var response = await Http.Send(httpClient, request); @@ -24,15 +44,5 @@ public void Run() }) .WithoutWarmUp() .WithLoadSimulations(Simulation.Inject(rate: 10, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromSeconds(30))); - - NBomberRunner - .RegisterScenarios(scenario) - .WithWorkerPlugins( - new PingPlugin(PingPluginConfig.CreateDefault("nbomber.com")), - new HttpMetricsPlugin(new [] { HttpVersion.Version1 }) - ) - .LoadConfig("Cluster/AutoCluster/autocluster-config.json") - .EnableLocalDevCluster(true) - .Run(); } } diff --git a/examples/Demo/Cluster/AutoCluster/README.md b/examples/Demo/Cluster/AutoCluster/README.md index 77ad83ac..d1b45969 100644 --- a/examples/Demo/Cluster/AutoCluster/README.md +++ b/examples/Demo/Cluster/AutoCluster/README.md @@ -13,8 +13,6 @@ In order to run that demo you should spin-up NATS message broker via docker-comp docker compose up ``` -After this you need start 2 instances of NBomber. - Useful links: - [Cluster overview](https://nbomber.com/docs/cluster/overview) - [How to run cluster](https://nbomber.com/docs/cluster/run-cluster) diff --git a/examples/Demo/Cluster/AutoCluster/docker-compose.yaml b/examples/Demo/Cluster/AutoCluster/docker-compose.yaml index 805c4375..b7750fc7 100644 --- a/examples/Demo/Cluster/AutoCluster/docker-compose.yaml +++ b/examples/Demo/Cluster/AutoCluster/docker-compose.yaml @@ -2,7 +2,7 @@ services: nats: - image: "nats:2.9.6" + image: "nats:2.9.9" command: --js ports: - "8222:8222" diff --git a/examples/Demo/Cluster/ManualCluster/ManualClusterExample.cs b/examples/Demo/Cluster/ManualCluster/ManualClusterExample.cs new file mode 100644 index 00000000..abf51626 --- /dev/null +++ b/examples/Demo/Cluster/ManualCluster/ManualClusterExample.cs @@ -0,0 +1,49 @@ +using NBomber.Contracts; +using NBomber.Contracts.Stats; +using NBomber.CSharp; +using NBomber.Http; +using NBomber.Http.CSharp; +using NBomber.Plugins.Network.Ping; + +namespace Demo.Cluster.ManualCluster; + +public class ManualClusterExample +{ + public void Run(string[] args) + { + var scenario = BuildScenario(); + StartNode(scenario, args); + } + + private void StartNode(ScenarioProps scenario, string[] args) + { + NBomberRunner + .RegisterScenarios(scenario) + .WithWorkerPlugins( + new PingPlugin(PingPluginConfig.CreateDefault("nbomber.com")), + new HttpMetricsPlugin(new [] { HttpVersion.Version1 }) + ) + .LoadConfig("Cluster/ManualCluster/manual-cluster-config.json") // you can use: --config=Cluster/ManualCluster/manual-cluster-config.json + .EnableLocalDevCluster(true) // you can use: --cluster-local-dev=true + .Run(args); // more info about available CLI args: https://nbomber.com/docs/getting-started/cli/ + } + + private ScenarioProps BuildScenario() + { + using var httpClient = new HttpClient(); + + return Scenario.Create("http_scenario", async context => + { + var request = + Http.CreateRequest("GET", "https://nbomber.com") + .WithHeader("Content-Type", "application/json"); + // .WithBody(new StringContent("{ some JSON }", Encoding.UTF8, "application/json")); + + var response = await Http.Send(httpClient, request); + + return response; + }) + .WithoutWarmUp() + .WithLoadSimulations(Simulation.Inject(rate: 10, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromSeconds(30))); + } +} diff --git a/examples/Demo/Cluster/ManualCluster/docker-compose.yaml b/examples/Demo/Cluster/ManualCluster/docker-compose.yaml new file mode 100644 index 00000000..b7750fc7 --- /dev/null +++ b/examples/Demo/Cluster/ManualCluster/docker-compose.yaml @@ -0,0 +1,9 @@ +version: "3.4" +services: + + nats: + image: "nats:2.9.9" + command: --js + ports: + - "8222:8222" + - "4222:4222" diff --git a/examples/Demo/Cluster/ManualCluster/manual-cluster-config.json b/examples/Demo/Cluster/ManualCluster/manual-cluster-config.json new file mode 100644 index 00000000..f02287ef --- /dev/null +++ b/examples/Demo/Cluster/ManualCluster/manual-cluster-config.json @@ -0,0 +1,23 @@ +{ + "TestSuite": "my test suite", + "TestName": "my test", + + "ClusterSettings": { + + "ManualCluster": { + "ClusterId": "test_cluster", + "NATSServerURL": "nats://localhost", + + "Coordinator": { + "TargetScenarios": ["http_scenario"] + }, + + "Agent": { + "AgentGroups": [{"AgentGroup": "1", "TargetScenarios": ["http_scenario"]}], + "AgentsCount": 1 + } + + } + + } +} diff --git a/examples/Demo/Demo.csproj b/examples/Demo/Demo.csproj index 1e013c27..501a6cef 100644 --- a/examples/Demo/Demo.csproj +++ b/examples/Demo/Demo.csproj @@ -12,9 +12,12 @@ PreserveNewest - + PreserveNewest + + PreserveNewest + @@ -34,7 +37,7 @@ - + diff --git a/examples/Demo/HelloWorld/HelloWorldExample.cs b/examples/Demo/HelloWorld/HelloWorldExample.cs index 699e85b2..8aa088b9 100644 --- a/examples/Demo/HelloWorld/HelloWorldExample.cs +++ b/examples/Demo/HelloWorld/HelloWorldExample.cs @@ -11,15 +11,13 @@ public void Run() // you can define and execute any logic here, // for example: send http request, SQL query etc // NBomber will measure how much time it takes to execute your logic - await Task.Delay(1000); + await Task.Delay(500); return Response.Ok(); }) .WithoutWarmUp() .WithLoadSimulations( - Simulation.RampingInject(rate: 150, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromMinutes(1)), // rump-up to rate 150 - Simulation.Inject(rate: 150, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromSeconds(30)), // keep injecting with rate 150 - Simulation.RampingInject(rate: 0, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromMinutes(1)) // rump-down to rate 0 + Simulation.Inject(rate: 1, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromSeconds(30)) // keep injecting with rate 150 ); NBomberRunner diff --git a/examples/Demo/Program.cs b/examples/Demo/Program.cs index f3a53d81..2a23fa9a 100644 --- a/examples/Demo/Program.cs +++ b/examples/Demo/Program.cs @@ -1,4 +1,5 @@ using Demo.Cluster.AutoCluster; +using Demo.Cluster.ManualCluster; using Demo.DB.LiteDB; using Demo.DB.Redis; using Demo.DB.SQLiteDB; @@ -78,5 +79,19 @@ // --------------------- // ----- Cluster ------- // --------------------- + +// ----- Auto Cluster ------- +// in order to run this example you should start 2 instances of NBomber, +// for this, you need to run this NBomber application twice + +// new AutoClusterExample().Run(); // new AutoClusterExample().Run(); +// ----- Manual Cluster ------- +// in order to run this example you should start 2 instances of NBomber, +// - first instance will act as Coordinator +// - second instance will act as Agent + +// new ManualClusterExample().Run(args: new [] { "--cluster-node-type=coordinator" }); +// new ManualClusterExample().Run(args: new [] { "--cluster-node-type=agent", "--cluster-agent-group=1" }); +