Rewrite load test for Microsoft DI
This commit is contained in:
@@ -22,7 +22,7 @@ class Program
|
|||||||
{
|
{
|
||||||
new RemoteTypeBinder();
|
new RemoteTypeBinder();
|
||||||
|
|
||||||
var builder = Host.CreateApplicationBuilder();
|
var builder = Host.CreateApplicationBuilder(new HostApplicationBuilderSettings { DisableDefaults = true });
|
||||||
builder.Services.AddSingleton<IContextualSerializationToolKit, CborSerializationToolkit>();
|
builder.Services.AddSingleton<IContextualSerializationToolKit, CborSerializationToolkit>();
|
||||||
builder.Services.AddSingleton<IEndPointContext, EndPointContext>();
|
builder.Services.AddSingleton<IEndPointContext, EndPointContext>();
|
||||||
builder.Services.AddSingleton<IRealStoreInstanceRepository, InstanceRepository>(provider =>
|
builder.Services.AddSingleton<IRealStoreInstanceRepository, InstanceRepository>(provider =>
|
||||||
|
|||||||
+64
-30
@@ -1,14 +1,17 @@
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using Example.Shared;
|
using Example.Shared;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
using mROA.Abstract;
|
using mROA.Abstract;
|
||||||
using mROA.Cbor;
|
using mROA.Cbor;
|
||||||
using mROA.Codegen;
|
using mROA.Codegen;
|
||||||
using mROA.Implementation;
|
using mROA.Implementation;
|
||||||
using mROA.Implementation.Backend;
|
using mROA.Implementation.Backend;
|
||||||
using mROA.Implementation.Bootstrap;
|
|
||||||
using mROA.Implementation.Frontend;
|
using mROA.Implementation.Frontend;
|
||||||
|
|
||||||
const int C = 100;
|
|
||||||
|
const int C = 6;
|
||||||
var time = TimeSpan.FromSeconds(10);
|
var time = TimeSpan.FromSeconds(10);
|
||||||
Console.WriteLine($"Starting bench for {time} from {C} connections");
|
Console.WriteLine($"Starting bench for {time} from {C} connections");
|
||||||
var cts = new CancellationTokenSource();
|
var cts = new CancellationTokenSource();
|
||||||
@@ -17,10 +20,11 @@ new RemoteTypeBinder();
|
|||||||
var tasks = new Task<int>[C];
|
var tasks = new Task<int>[C];
|
||||||
for (int i = 0; i < C; i++)
|
for (int i = 0; i < C; i++)
|
||||||
{
|
{
|
||||||
tasks[i] = Requests(cts.Token);
|
tasks[i] = Requests(cts.Token, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
cts.CancelAfter(time);
|
cts.CancelAfter(time);
|
||||||
|
Console.WriteLine($"Test end at {DateTime.Now.Add(time)}");
|
||||||
Console.WriteLine("Start waiting");
|
Console.WriteLine("Start waiting");
|
||||||
await Task.WhenAll(tasks);
|
await Task.WhenAll(tasks);
|
||||||
Console.WriteLine("End waiting");
|
Console.WriteLine("End waiting");
|
||||||
@@ -29,48 +33,78 @@ var totalRequests = tasks.Sum(i => i.Result);
|
|||||||
Console.WriteLine($"Total requests: {totalRequests}");
|
Console.WriteLine($"Total requests: {totalRequests}");
|
||||||
Console.WriteLine($"Results: {totalRequests / time.TotalSeconds:N} RPS");
|
Console.WriteLine($"Results: {totalRequests / time.TotalSeconds:N} RPS");
|
||||||
|
|
||||||
async Task<int> Requests(CancellationToken token)
|
async Task<int> Requests(CancellationToken token, int id)
|
||||||
{
|
{
|
||||||
var builder = new FullMixBuilder();
|
try
|
||||||
|
{
|
||||||
|
Console.WriteLine($"{id} started");
|
||||||
|
var builder = Host.CreateApplicationBuilder(new HostApplicationBuilderSettings { DisableDefaults = true });
|
||||||
|
builder.Services.AddSingleton<IContextualSerializationToolKit, CborSerializationToolkit>();
|
||||||
|
builder.Services.AddSingleton<IEndPointContext, EndPointContext>();
|
||||||
|
builder.Services.AddSingleton<IRealStoreInstanceRepository, InstanceRepository>(provider =>
|
||||||
|
{
|
||||||
|
var repo = new InstanceRepository(provider.GetService<IRepresentationModuleProducer>());
|
||||||
|
repo.FillSingletons(typeof(Program).Assembly);
|
||||||
|
return repo;
|
||||||
|
});
|
||||||
|
|
||||||
builder.Modules.Add(new CborSerializationToolkit());
|
builder.Services.AddSingleton<IInstanceRepository, RemoteInstanceRepository>();
|
||||||
builder.Modules.Add(new EndPointContext());
|
builder.Services.AddSingleton<IChannelInteractionModule, ChannelInteractionModule>();
|
||||||
builder.Modules.Add(new RemoteInstanceRepository());
|
builder.Services.AddSingleton<IUntrustedInteractionModule, UdpUntrustedInteraction>();
|
||||||
builder.Modules.Add(new ChannelInteractionModule());
|
builder.Services.AddSingleton<IRepresentationModule, RepresentationModule>();
|
||||||
// builder.Modules.Add(new UdpUntrustedInteraction());
|
|
||||||
builder.Modules.Add(new RepresentationModule());
|
|
||||||
var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 4567);
|
var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 4567);
|
||||||
builder.Modules.Add(new NetworkFrontendBridge(serverEndPoint));
|
builder.Services.AddSingleton<IFrontendBridge, NetworkFrontendBridge>();
|
||||||
builder.Modules.Add(new StaticRepresentationModuleProducer());
|
builder.Services.AddOptions();
|
||||||
// builder.Modules.Add(new RequestExtractor());
|
builder.Services.Configure<GatewayOptions>(options => options.Endpoint = serverEndPoint);
|
||||||
builder.Modules.Add(new BasicExecutionModule());
|
builder.Services.AddSingleton<IRepresentationModuleProducer, StaticRepresentationModuleProducer>();
|
||||||
|
builder.Services.AddSingleton<IRequestExtractor, RequestExtractor>();
|
||||||
|
builder.Services.AddSingleton<IExecuteModule, BasicExecutionModule>();
|
||||||
|
|
||||||
|
builder.Services.AddSingleton<IMethodRepository, CollectableMethodRepository>(p =>
|
||||||
|
{
|
||||||
var methodRepo = new CollectableMethodRepository();
|
var methodRepo = new CollectableMethodRepository();
|
||||||
methodRepo.AppendInvokers(new GeneratedInvokersCollection());
|
methodRepo.AppendInvokers(new GeneratedInvokersCollection());
|
||||||
builder.Modules.Add(methodRepo);
|
return methodRepo;
|
||||||
builder.Modules.Add(new GeneratedCallIndexProvider());
|
});
|
||||||
builder.UseCollectableContextRepository();
|
builder.Services.AddSingleton<ICallIndexProvider, GeneratedCallIndexProvider>();
|
||||||
builder.Modules.Add(new CancellationRepository());
|
builder.Services.AddSingleton<ICancellationRepository, CancellationRepository>();
|
||||||
|
|
||||||
builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
var frontendBridge = builder.GetModule<IFrontendBridge>()!;
|
var frontendBridge = app.Services.GetService<IFrontendBridge>()!;
|
||||||
await frontendBridge.Connect();
|
await frontendBridge.Connect();
|
||||||
// _ = builder.GetModule<RequestExtractor>()!.StartExtraction();
|
_ = app.Services.GetService<IRequestExtractor>()!.StartExtraction();
|
||||||
// _ = builder.GetModule<UdpUntrustedInteraction>().Start(serverEndPoint);
|
_ = app.Services.GetService<IUntrustedInteractionModule>().Start(serverEndPoint);
|
||||||
var context = builder.GetModule<RemoteInstanceRepository>();
|
var context = app.Services.GetService<IInstanceRepository>();
|
||||||
|
|
||||||
|
|
||||||
var factory =
|
var factory =
|
||||||
context.GetSingletonObject<ILoadTest>(
|
context.GetSingletonObject<ILoadTest>(
|
||||||
builder.GetModule<IEndPointContext>());
|
app.Services.GetService<IEndPointContext>());
|
||||||
|
|
||||||
|
bool needStop = false;
|
||||||
|
token.Register(() =>
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Stopping {id}");
|
||||||
|
needStop = true;
|
||||||
|
});
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int a;
|
while (true){
|
||||||
do
|
if (token.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
a = await factory.Next(2);
|
break;
|
||||||
|
}
|
||||||
|
await factory.Next(2);
|
||||||
count++;
|
count++;
|
||||||
} while (!token.IsCancellationRequested);
|
}
|
||||||
|
|
||||||
Console.WriteLine(a);
|
Console.WriteLine(id);
|
||||||
return count;
|
return count;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine(e);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace mROA.Test;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
public class FunctionalityTest
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -27,6 +27,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mROA.CodegenTools", "mROA.C
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example.Load", "Example.Load\Example.Load.csproj", "{930B236B-BDAA-4B8C-8054-5B992BAE6622}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example.Load", "Example.Load\Example.Load.csproj", "{930B236B-BDAA-4B8C-8054-5B992BAE6622}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Functionality.Shared", "Functionality.Shared\Functionality.Shared.csproj", "{D9D28596-E10C-4A98-A2AA-573219467506}"
|
||||||
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Test", "Test", "{8C20901F-B416-4ABC-8AA4-9059646B081B}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -73,6 +77,10 @@ Global
|
|||||||
{930B236B-BDAA-4B8C-8054-5B992BAE6622}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{930B236B-BDAA-4B8C-8054-5B992BAE6622}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{930B236B-BDAA-4B8C-8054-5B992BAE6622}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{930B236B-BDAA-4B8C-8054-5B992BAE6622}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{930B236B-BDAA-4B8C-8054-5B992BAE6622}.Release|Any CPU.Build.0 = Release|Any CPU
|
{930B236B-BDAA-4B8C-8054-5B992BAE6622}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{D9D28596-E10C-4A98-A2AA-573219467506}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{D9D28596-E10C-4A98-A2AA-573219467506}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{D9D28596-E10C-4A98-A2AA-573219467506}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{D9D28596-E10C-4A98-A2AA-573219467506}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
@@ -83,5 +91,7 @@ Global
|
|||||||
{9BD25A13-3165-47C0-9EAA-5C59EC490E32} = {FC4FA752-10A7-4D78-A7C2-9BCD8A81FB5E}
|
{9BD25A13-3165-47C0-9EAA-5C59EC490E32} = {FC4FA752-10A7-4D78-A7C2-9BCD8A81FB5E}
|
||||||
{E7703F5B-F2A6-4A88-AA57-EBB1E38D533E} = {FC4FA752-10A7-4D78-A7C2-9BCD8A81FB5E}
|
{E7703F5B-F2A6-4A88-AA57-EBB1E38D533E} = {FC4FA752-10A7-4D78-A7C2-9BCD8A81FB5E}
|
||||||
{930B236B-BDAA-4B8C-8054-5B992BAE6622} = {FC4FA752-10A7-4D78-A7C2-9BCD8A81FB5E}
|
{930B236B-BDAA-4B8C-8054-5B992BAE6622} = {FC4FA752-10A7-4D78-A7C2-9BCD8A81FB5E}
|
||||||
|
{8C20901F-B416-4ABC-8AA4-9059646B081B} = {EAE92F5A-664C-41AB-8811-5885524B5347}
|
||||||
|
{D9D28596-E10C-4A98-A2AA-573219467506} = {8C20901F-B416-4ABC-8AA4-9059646B081B}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|||||||
Reference in New Issue
Block a user