From 3ce66786b533d1e887646cd7049e517510484b75 Mon Sep 17 00:00:00 2001 From: Mitrofanov Mikhail Date: Sat, 12 Jul 2025 21:28:37 +0300 Subject: [PATCH] Load test works, but very slow --- Example.Backend/LoadTestImp.cs | 3 ++- Example.Load/Program.cs | 41 +++++++++++++++++++--------------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/Example.Backend/LoadTestImp.cs b/Example.Backend/LoadTestImp.cs index 443d61a..9c6441b 100644 --- a/Example.Backend/LoadTestImp.cs +++ b/Example.Backend/LoadTestImp.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics; using System.Threading; using System.Threading.Tasks; using Example.Shared; @@ -10,8 +9,10 @@ namespace Example.Backend [SharedObjectSingleton] public class LoadTestImp : ILoadTest { + public static int N; public Task Next(int last) { + Console.WriteLine(++N); return Task.FromResult( last + 1); } diff --git a/Example.Load/Program.cs b/Example.Load/Program.cs index ccadfb2..273afc3 100644 --- a/Example.Load/Program.cs +++ b/Example.Load/Program.cs @@ -11,16 +11,16 @@ using mROA.Implementation.Backend; using mROA.Implementation.Frontend; -const int C = 6; +const int C = 100; var time = TimeSpan.FromSeconds(10); Console.WriteLine($"Starting bench for {time} from {C} connections"); var cts = new CancellationTokenSource(); new RemoteTypeBinder(); - +var eps = await GetLoadEndpoints(C); var tasks = new Task[C]; for (int i = 0; i < C; i++) { - tasks[i] = Requests(cts.Token, i); + tasks[i] = Requests(cts.Token, i, eps[i]); } cts.CancelAfter(time); @@ -33,11 +33,12 @@ var totalRequests = tasks.Sum(i => i.Result); Console.WriteLine($"Total requests: {totalRequests}"); Console.WriteLine($"Results: {totalRequests / time.TotalSeconds:N} RPS"); -async Task Requests(CancellationToken token, int id) + +async Task> GetLoadEndpoints(int count) { - try + var loads = new List(); + for (int i = 0; i < count; i++) { - Console.WriteLine($"{id} started"); var builder = Host.CreateApplicationBuilder(new HostApplicationBuilderSettings { DisableDefaults = true }); builder.Services.AddSingleton(); builder.Services.AddSingleton(); @@ -50,14 +51,14 @@ async Task Requests(CancellationToken token, int id) builder.Services.AddSingleton(); builder.Services.AddSingleton(); - builder.Services.AddSingleton(); + // builder.Services.AddSingleton(); builder.Services.AddSingleton(); var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 4567); builder.Services.AddSingleton(); builder.Services.AddOptions(); builder.Services.Configure(options => options.Endpoint = serverEndPoint); builder.Services.AddSingleton(); - builder.Services.AddSingleton(); + // builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(p => @@ -73,21 +74,24 @@ async Task Requests(CancellationToken token, int id) var frontendBridge = app.Services.GetService()!; await frontendBridge.Connect(); - _ = app.Services.GetService()!.StartExtraction(); - _ = app.Services.GetService().Start(serverEndPoint); + // _ = app.Services.GetService()!.StartExtraction(); + // _ = app.Services.GetService().Start(serverEndPoint); var context = app.Services.GetService(); - var factory = + var singletonObject = context.GetSingletonObject( app.Services.GetService()); + loads.Add(singletonObject); + } + return loads; +} + +async Task Requests(CancellationToken token, int id, ILoadTest load) +{ + try + { - bool needStop = false; - token.Register(() => - { - Console.WriteLine($"Stopping {id}"); - needStop = true; - }); int count = 0; while (true){ @@ -95,7 +99,8 @@ async Task Requests(CancellationToken token, int id) { break; } - await factory.Next(2); + + await load.Next(2); count++; }