Direct to exe mode works faster, but has restrictions
This commit is contained in:
@@ -9,12 +9,14 @@ using mROA.Implementation;
|
|||||||
using mROA.Implementation.Backend;
|
using mROA.Implementation.Backend;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
var builder = Host.CreateApplicationBuilder();
|
var builder = Host.CreateApplicationBuilder();
|
||||||
|
builder.Services.AddLogging(l => l.AddConsole());
|
||||||
builder.Services.AddSingleton<IContextualSerializationToolKit, CborSerializationToolkit>();
|
builder.Services.AddSingleton<IContextualSerializationToolKit, CborSerializationToolkit>();
|
||||||
builder.Services.AddSingleton<IIdentityGenerator, BackendIdentityGenerator>();
|
builder.Services.AddSingleton<IIdentityGenerator, BackendIdentityGenerator>();
|
||||||
builder.Services.AddSingleton<IGatewayModule, NetworkGatewayModule>();
|
builder.Services.AddSingleton<IGatewayModule, NetworkGatewayModule>();
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ using Example.Frontend;
|
|||||||
using Example.Shared;
|
using Example.Shared;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using mROA.Abstract;
|
using mROA.Abstract;
|
||||||
using mROA.Cbor;
|
using mROA.Cbor;
|
||||||
using mROA.Codegen;
|
using mROA.Codegen;
|
||||||
@@ -23,6 +24,8 @@ class Program
|
|||||||
new RemoteTypeBinder();
|
new RemoteTypeBinder();
|
||||||
|
|
||||||
var builder = Host.CreateApplicationBuilder(new HostApplicationBuilderSettings { DisableDefaults = true });
|
var builder = Host.CreateApplicationBuilder(new HostApplicationBuilderSettings { DisableDefaults = true });
|
||||||
|
builder.Services.AddLogging(l => l.SetMinimumLevel(LogLevel.Trace).AddConsole());
|
||||||
|
|
||||||
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 =>
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ Console.WriteLine("End waiting");
|
|||||||
var totalRequests = tasks.Sum(i => i.Result);
|
var totalRequests = tasks.Sum(i => i.Result);
|
||||||
Console.WriteLine($"Total requests: {totalRequests:N0}");
|
Console.WriteLine($"Total requests: {totalRequests:N0}");
|
||||||
Console.WriteLine($"Results: {totalRequests / time.TotalSeconds:N} RPS");
|
Console.WriteLine($"Results: {totalRequests / time.TotalSeconds:N} RPS");
|
||||||
|
File.AppendAllText("results.txt", $"[DIRECT TO EXE] {totalRequests}\r\n");
|
||||||
|
|
||||||
async Task<List<ILoadTest>> GetLoadEndpoints(int count)
|
async Task<List<ILoadTest>> GetLoadEndpoints(int count)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using mROA.Abstract;
|
using mROA.Abstract;
|
||||||
using mROA.Implementation.CommandExecution;
|
using mROA.Implementation.CommandExecution;
|
||||||
|
|
||||||
@@ -10,17 +11,20 @@ namespace mROA.Implementation.Backend
|
|||||||
private readonly ICancellationRepository _cancellationRepo;
|
private readonly ICancellationRepository _cancellationRepo;
|
||||||
private readonly IMethodRepository _methodRepo;
|
private readonly IMethodRepository _methodRepo;
|
||||||
private readonly IContextualSerializationToolKit _serialization;
|
private readonly IContextualSerializationToolKit _serialization;
|
||||||
|
private readonly ILogger<BasicExecutionModule> _logger;
|
||||||
|
|
||||||
public BasicExecutionModule(ICancellationRepository cancellationRepo, IMethodRepository methodRepo, IContextualSerializationToolKit serialization)
|
public BasicExecutionModule(ICancellationRepository cancellationRepo, IMethodRepository methodRepo, IContextualSerializationToolKit serialization, ILogger<BasicExecutionModule> logger)
|
||||||
{
|
{
|
||||||
_cancellationRepo = cancellationRepo;
|
_cancellationRepo = cancellationRepo;
|
||||||
_methodRepo = methodRepo;
|
_methodRepo = methodRepo;
|
||||||
_serialization = serialization;
|
_serialization = serialization;
|
||||||
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICommandExecution Execute(ICallRequest command, IInstanceRepository instanceRepository,
|
public ICommandExecution Execute(ICallRequest command, IInstanceRepository instanceRepository,
|
||||||
IRepresentationModule representationModule, IEndPointContext endPointContext)
|
IRepresentationModule representationModule, IEndPointContext endPointContext)
|
||||||
{
|
{
|
||||||
|
// _logger.LogInformation("Executing {0}", command.Id);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (command is CancelRequest)
|
if (command is CancelRequest)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.Net;
|
|||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using mROA.Abstract;
|
using mROA.Abstract;
|
||||||
|
|
||||||
@@ -14,6 +15,7 @@ namespace mROA.Implementation.Backend
|
|||||||
private readonly TcpListener _tcpListener;
|
private readonly TcpListener _tcpListener;
|
||||||
private readonly IConnectionHub _hub;
|
private readonly IConnectionHub _hub;
|
||||||
private readonly HubRequestExtractor _hre;
|
private readonly HubRequestExtractor _hre;
|
||||||
|
private readonly ILogger _logger;
|
||||||
private readonly DistributionOptions _distribution;
|
private readonly DistributionOptions _distribution;
|
||||||
private readonly IContextualSerializationToolKit _serialization;
|
private readonly IContextualSerializationToolKit _serialization;
|
||||||
private readonly Dictionary<int, CancellationTokenSource> _extractorsTokenSources = new();
|
private readonly Dictionary<int, CancellationTokenSource> _extractorsTokenSources = new();
|
||||||
@@ -22,7 +24,7 @@ namespace mROA.Implementation.Backend
|
|||||||
|
|
||||||
public NetworkGatewayModule(IOptions<GatewayOptions> options, IIdentityGenerator identityGenerator,
|
public NetworkGatewayModule(IOptions<GatewayOptions> options, IIdentityGenerator identityGenerator,
|
||||||
IContextualSerializationToolKit serialization, ICallIndexProvider callIndexProvider, IConnectionHub hub,
|
IContextualSerializationToolKit serialization, ICallIndexProvider callIndexProvider, IConnectionHub hub,
|
||||||
IOptions<DistributionOptions> distribution, HubRequestExtractor hre)
|
IOptions<DistributionOptions> distribution, HubRequestExtractor hre, ILogger<ChannelInteractionModule.StreamExtractor> logger)
|
||||||
{
|
{
|
||||||
_tcpListener = new(options.Value.Endpoint);
|
_tcpListener = new(options.Value.Endpoint);
|
||||||
_identityGenerator = identityGenerator;
|
_identityGenerator = identityGenerator;
|
||||||
@@ -30,6 +32,7 @@ namespace mROA.Implementation.Backend
|
|||||||
_callIndexProvider = callIndexProvider;
|
_callIndexProvider = callIndexProvider;
|
||||||
_hub = hub;
|
_hub = hub;
|
||||||
_hre = hre;
|
_hre = hre;
|
||||||
|
_logger = logger;
|
||||||
_distribution = distribution.Value;
|
_distribution = distribution.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +69,7 @@ namespace mROA.Implementation.Backend
|
|||||||
CallIndexProvider = _callIndexProvider
|
CallIndexProvider = _callIndexProvider
|
||||||
};
|
};
|
||||||
var streamExtractor =
|
var streamExtractor =
|
||||||
new ChannelInteractionModule.StreamExtractor(client.GetStream(), _serialization, context);
|
new ChannelInteractionModule.StreamExtractor(client.GetStream(), _serialization, context, _logger);
|
||||||
interaction.IsConnected = () => streamExtractor.IsConnected;
|
interaction.IsConnected = () => streamExtractor.IsConnected;
|
||||||
streamExtractor.MessageReceived = async message =>
|
streamExtractor.MessageReceived = async message =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.IO;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Channels;
|
using System.Threading.Channels;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using mROA.Abstract;
|
using mROA.Abstract;
|
||||||
|
|
||||||
namespace mROA.Implementation
|
namespace mROA.Implementation
|
||||||
@@ -147,14 +148,16 @@ namespace mROA.Implementation
|
|||||||
private readonly IContextualSerializationToolKit _serializationToolkit;
|
private readonly IContextualSerializationToolKit _serializationToolkit;
|
||||||
private readonly Memory<byte> _buffer = new byte[BufferSize];
|
private readonly Memory<byte> _buffer = new byte[BufferSize];
|
||||||
private readonly IEndPointContext _context;
|
private readonly IEndPointContext _context;
|
||||||
|
private readonly ILogger _logger;
|
||||||
private readonly byte[] _lenBuffer;
|
private readonly byte[] _lenBuffer;
|
||||||
|
|
||||||
public StreamExtractor(Stream ioStream, IContextualSerializationToolKit serializationToolkit,
|
public StreamExtractor(Stream ioStream, IContextualSerializationToolKit serializationToolkit,
|
||||||
IEndPointContext context)
|
IEndPointContext context, ILogger logger)
|
||||||
{
|
{
|
||||||
_ioStream = ioStream;
|
_ioStream = ioStream;
|
||||||
_serializationToolkit = serializationToolkit;
|
_serializationToolkit = serializationToolkit;
|
||||||
_context = context;
|
_context = context;
|
||||||
|
_logger = logger;
|
||||||
_lenBuffer = new byte[2];
|
_lenBuffer = new byte[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,6 +179,7 @@ namespace mROA.Implementation
|
|||||||
|
|
||||||
await _ioStream.ReadExactlyAsync(localSpan, cancellationToken: token);
|
await _ioStream.ReadExactlyAsync(localSpan, cancellationToken: token);
|
||||||
var message = _serializationToolkit.Deserialize<NetworkMessageHeader>(localSpan, _context);
|
var message = _serializationToolkit.Deserialize<NetworkMessageHeader>(localSpan, _context);
|
||||||
|
// _logger.LogTrace("RECV {0}", message.ToString());
|
||||||
MessageReceived(message);
|
MessageReceived(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,6 +199,8 @@ namespace mROA.Implementation
|
|||||||
header.CopyTo(_buffer);
|
header.CopyTo(_buffer);
|
||||||
var sendingSpan = _buffer[..(len + 2)];
|
var sendingSpan = _buffer[..(len + 2)];
|
||||||
await _ioStream.WriteAsync(sendingSpan, token);
|
await _ioStream.WriteAsync(sendingSpan, token);
|
||||||
|
// _logger.LogTrace("SEND {0}", message.ToString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SendFromChannel(ChannelReader<NetworkMessageHeader> channel,
|
public async Task SendFromChannel(ChannelReader<NetworkMessageHeader> channel,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Net;
|
|||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using mROA.Abstract;
|
using mROA.Abstract;
|
||||||
using mROA.Implementation.Backend;
|
using mROA.Implementation.Backend;
|
||||||
@@ -15,17 +16,19 @@ namespace mROA.Implementation.Frontend
|
|||||||
private readonly IPEndPoint _serverEndPoint;
|
private readonly IPEndPoint _serverEndPoint;
|
||||||
private TcpClient _tcpClient = new();
|
private TcpClient _tcpClient = new();
|
||||||
private readonly IChannelInteractionModule _interactionModule;
|
private readonly IChannelInteractionModule _interactionModule;
|
||||||
|
private readonly ILogger _logger;
|
||||||
private readonly IContextualSerializationToolKit _serialization;
|
private readonly IContextualSerializationToolKit _serialization;
|
||||||
private ChannelInteractionModule.StreamExtractor? _currentExtractor;
|
private ChannelInteractionModule.StreamExtractor? _currentExtractor;
|
||||||
private CancellationTokenSource _rawExtractorCancellation;
|
private CancellationTokenSource _rawExtractorCancellation;
|
||||||
private readonly IEndPointContext _context;
|
private readonly IEndPointContext _context;
|
||||||
|
|
||||||
public NetworkFrontendBridge(IOptions<GatewayOptions> options, IEndPointContext context, IContextualSerializationToolKit serialization, IChannelInteractionModule interactionModule)
|
public NetworkFrontendBridge(IOptions<GatewayOptions> options, IEndPointContext context, IContextualSerializationToolKit serialization, IChannelInteractionModule interactionModule, ILogger<ChannelInteractionModule.StreamExtractor> logger)
|
||||||
{
|
{
|
||||||
_serverEndPoint = options.Value.Endpoint;
|
_serverEndPoint = options.Value.Endpoint;
|
||||||
_context = context;
|
_context = context;
|
||||||
_serialization = serialization;
|
_serialization = serialization;
|
||||||
_interactionModule = interactionModule;
|
_interactionModule = interactionModule;
|
||||||
|
_logger = logger;
|
||||||
_rawExtractorCancellation = new CancellationTokenSource();
|
_rawExtractorCancellation = new CancellationTokenSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +64,7 @@ namespace mROA.Implementation.Frontend
|
|||||||
private void PrepareExtractor()
|
private void PrepareExtractor()
|
||||||
{
|
{
|
||||||
_currentExtractor =
|
_currentExtractor =
|
||||||
new ChannelInteractionModule.StreamExtractor(_tcpClient.GetStream(), _serialization, _context);
|
new ChannelInteractionModule.StreamExtractor(_tcpClient.GetStream(), _serialization, _context, _logger);
|
||||||
|
|
||||||
_ = _currentExtractor.SendFromChannel(_interactionModule.TrustedPostChanel,
|
_ = _currentExtractor.SendFromChannel(_interactionModule.TrustedPostChanel,
|
||||||
_rawExtractorCancellation.Token);
|
_rawExtractorCancellation.Token);
|
||||||
|
|||||||
@@ -39,4 +39,10 @@
|
|||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="Microsoft.Extensions.Logging.Abstractions">
|
||||||
|
<HintPath>..\..\..\..\.nuget\packages\microsoft.extensions.logging.abstractions\9.0.7\lib\netstandard2.0\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
Reference in New Issue
Block a user