From c7c5b1637c4b0d97e449a9cc96659c783a6fd3df Mon Sep 17 00:00:00 2001 From: Mitrofanov Mikhail Date: Sat, 19 Jul 2025 17:18:46 +0300 Subject: [PATCH] Direct to exe mode works faster, but has restrictions --- Example.Backend/Program.cs | 2 ++ Example.Frontend/Program.cs | 3 +++ Example.Load/Program.cs | 2 +- mROA/Implementation/Backend/BasicExecutionModule.cs | 6 +++++- mROA/Implementation/Backend/NetworkGatewayModule.cs | 7 +++++-- mROA/Implementation/ChannelInteractionModule.cs | 8 +++++++- mROA/Implementation/Frontend/NetworkFrontendBridge.cs | 7 +++++-- mROA/mROA.csproj | 6 ++++++ 8 files changed, 34 insertions(+), 7 deletions(-) diff --git a/Example.Backend/Program.cs b/Example.Backend/Program.cs index fdf34c8..e80c1d7 100644 --- a/Example.Backend/Program.cs +++ b/Example.Backend/Program.cs @@ -9,12 +9,14 @@ using mROA.Implementation; using mROA.Implementation.Backend; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; class Program { public static void Main(string[] args) { var builder = Host.CreateApplicationBuilder(); + builder.Services.AddLogging(l => l.AddConsole()); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); diff --git a/Example.Frontend/Program.cs b/Example.Frontend/Program.cs index b21b094..de23bb0 100644 --- a/Example.Frontend/Program.cs +++ b/Example.Frontend/Program.cs @@ -8,6 +8,7 @@ using Example.Frontend; using Example.Shared; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; using mROA.Abstract; using mROA.Cbor; using mROA.Codegen; @@ -23,6 +24,8 @@ class Program new RemoteTypeBinder(); var builder = Host.CreateApplicationBuilder(new HostApplicationBuilderSettings { DisableDefaults = true }); + builder.Services.AddLogging(l => l.SetMinimumLevel(LogLevel.Trace).AddConsole()); + builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(provider => diff --git a/Example.Load/Program.cs b/Example.Load/Program.cs index 36be5f4..5ea37cd 100644 --- a/Example.Load/Program.cs +++ b/Example.Load/Program.cs @@ -32,7 +32,7 @@ Console.WriteLine("End waiting"); var totalRequests = tasks.Sum(i => i.Result); Console.WriteLine($"Total requests: {totalRequests:N0}"); Console.WriteLine($"Results: {totalRequests / time.TotalSeconds:N} RPS"); - +File.AppendAllText("results.txt", $"[DIRECT TO EXE] {totalRequests}\r\n"); async Task> GetLoadEndpoints(int count) { diff --git a/mROA/Implementation/Backend/BasicExecutionModule.cs b/mROA/Implementation/Backend/BasicExecutionModule.cs index b32cdfd..d8ce917 100644 --- a/mROA/Implementation/Backend/BasicExecutionModule.cs +++ b/mROA/Implementation/Backend/BasicExecutionModule.cs @@ -1,5 +1,6 @@ using System; using System.Threading; +using Microsoft.Extensions.Logging; using mROA.Abstract; using mROA.Implementation.CommandExecution; @@ -10,17 +11,20 @@ namespace mROA.Implementation.Backend private readonly ICancellationRepository _cancellationRepo; private readonly IMethodRepository _methodRepo; private readonly IContextualSerializationToolKit _serialization; + private readonly ILogger _logger; - public BasicExecutionModule(ICancellationRepository cancellationRepo, IMethodRepository methodRepo, IContextualSerializationToolKit serialization) + public BasicExecutionModule(ICancellationRepository cancellationRepo, IMethodRepository methodRepo, IContextualSerializationToolKit serialization, ILogger logger) { _cancellationRepo = cancellationRepo; _methodRepo = methodRepo; _serialization = serialization; + _logger = logger; } public ICommandExecution Execute(ICallRequest command, IInstanceRepository instanceRepository, IRepresentationModule representationModule, IEndPointContext endPointContext) { + // _logger.LogInformation("Executing {0}", command.Id); try { if (command is CancelRequest) diff --git a/mROA/Implementation/Backend/NetworkGatewayModule.cs b/mROA/Implementation/Backend/NetworkGatewayModule.cs index ecdc97b..ce32fbf 100644 --- a/mROA/Implementation/Backend/NetworkGatewayModule.cs +++ b/mROA/Implementation/Backend/NetworkGatewayModule.cs @@ -4,6 +4,7 @@ using System.Net; using System.Net.Sockets; using System.Threading; using System.Threading.Tasks; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using mROA.Abstract; @@ -14,6 +15,7 @@ namespace mROA.Implementation.Backend private readonly TcpListener _tcpListener; private readonly IConnectionHub _hub; private readonly HubRequestExtractor _hre; + private readonly ILogger _logger; private readonly DistributionOptions _distribution; private readonly IContextualSerializationToolKit _serialization; private readonly Dictionary _extractorsTokenSources = new(); @@ -22,7 +24,7 @@ namespace mROA.Implementation.Backend public NetworkGatewayModule(IOptions options, IIdentityGenerator identityGenerator, IContextualSerializationToolKit serialization, ICallIndexProvider callIndexProvider, IConnectionHub hub, - IOptions distribution, HubRequestExtractor hre) + IOptions distribution, HubRequestExtractor hre, ILogger logger) { _tcpListener = new(options.Value.Endpoint); _identityGenerator = identityGenerator; @@ -30,6 +32,7 @@ namespace mROA.Implementation.Backend _callIndexProvider = callIndexProvider; _hub = hub; _hre = hre; + _logger = logger; _distribution = distribution.Value; } @@ -66,7 +69,7 @@ namespace mROA.Implementation.Backend CallIndexProvider = _callIndexProvider }; var streamExtractor = - new ChannelInteractionModule.StreamExtractor(client.GetStream(), _serialization, context); + new ChannelInteractionModule.StreamExtractor(client.GetStream(), _serialization, context, _logger); interaction.IsConnected = () => streamExtractor.IsConnected; streamExtractor.MessageReceived = async message => { diff --git a/mROA/Implementation/ChannelInteractionModule.cs b/mROA/Implementation/ChannelInteractionModule.cs index d7b85bf..6fd3b38 100644 --- a/mROA/Implementation/ChannelInteractionModule.cs +++ b/mROA/Implementation/ChannelInteractionModule.cs @@ -4,6 +4,7 @@ using System.IO; using System.Threading; using System.Threading.Channels; using System.Threading.Tasks; +using Microsoft.Extensions.Logging; using mROA.Abstract; namespace mROA.Implementation @@ -147,14 +148,16 @@ namespace mROA.Implementation private readonly IContextualSerializationToolKit _serializationToolkit; private readonly Memory _buffer = new byte[BufferSize]; private readonly IEndPointContext _context; + private readonly ILogger _logger; private readonly byte[] _lenBuffer; public StreamExtractor(Stream ioStream, IContextualSerializationToolKit serializationToolkit, - IEndPointContext context) + IEndPointContext context, ILogger logger) { _ioStream = ioStream; _serializationToolkit = serializationToolkit; _context = context; + _logger = logger; _lenBuffer = new byte[2]; } @@ -176,6 +179,7 @@ namespace mROA.Implementation await _ioStream.ReadExactlyAsync(localSpan, cancellationToken: token); var message = _serializationToolkit.Deserialize(localSpan, _context); + // _logger.LogTrace("RECV {0}", message.ToString()); MessageReceived(message); } @@ -195,6 +199,8 @@ namespace mROA.Implementation header.CopyTo(_buffer); var sendingSpan = _buffer[..(len + 2)]; await _ioStream.WriteAsync(sendingSpan, token); + // _logger.LogTrace("SEND {0}", message.ToString()); + } public async Task SendFromChannel(ChannelReader channel, diff --git a/mROA/Implementation/Frontend/NetworkFrontendBridge.cs b/mROA/Implementation/Frontend/NetworkFrontendBridge.cs index 7e25985..40159ee 100644 --- a/mROA/Implementation/Frontend/NetworkFrontendBridge.cs +++ b/mROA/Implementation/Frontend/NetworkFrontendBridge.cs @@ -3,6 +3,7 @@ using System.Net; using System.Net.Sockets; using System.Threading; using System.Threading.Tasks; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using mROA.Abstract; using mROA.Implementation.Backend; @@ -15,17 +16,19 @@ namespace mROA.Implementation.Frontend private readonly IPEndPoint _serverEndPoint; private TcpClient _tcpClient = new(); private readonly IChannelInteractionModule _interactionModule; + private readonly ILogger _logger; private readonly IContextualSerializationToolKit _serialization; private ChannelInteractionModule.StreamExtractor? _currentExtractor; private CancellationTokenSource _rawExtractorCancellation; private readonly IEndPointContext _context; - public NetworkFrontendBridge(IOptions options, IEndPointContext context, IContextualSerializationToolKit serialization, IChannelInteractionModule interactionModule) + public NetworkFrontendBridge(IOptions options, IEndPointContext context, IContextualSerializationToolKit serialization, IChannelInteractionModule interactionModule, ILogger logger) { _serverEndPoint = options.Value.Endpoint; _context = context; _serialization = serialization; _interactionModule = interactionModule; + _logger = logger; _rawExtractorCancellation = new CancellationTokenSource(); } @@ -61,7 +64,7 @@ namespace mROA.Implementation.Frontend private void PrepareExtractor() { _currentExtractor = - new ChannelInteractionModule.StreamExtractor(_tcpClient.GetStream(), _serialization, _context); + new ChannelInteractionModule.StreamExtractor(_tcpClient.GetStream(), _serialization, _context, _logger); _ = _currentExtractor.SendFromChannel(_interactionModule.TrustedPostChanel, _rawExtractorCancellation.Token); diff --git a/mROA/mROA.csproj b/mROA/mROA.csproj index cc70622..f4a4354 100644 --- a/mROA/mROA.csproj +++ b/mROA/mROA.csproj @@ -39,4 +39,10 @@ + + + ..\..\..\..\.nuget\packages\microsoft.extensions.logging.abstractions\9.0.7\lib\netstandard2.0\Microsoft.Extensions.Logging.Abstractions.dll + + +