Some latency bug found

This commit is contained in:
2025-06-30 15:45:41 +03:00
parent af6e7b6547
commit 1b0f867653
5 changed files with 17 additions and 38 deletions
+2 -2
View File
@@ -9,9 +9,9 @@ namespace Example.Backend
[SharedObjectSingleton]
public class LoadTestImp : ILoadTest
{
public int Next(int last)
public Task<int> Next(int last)
{
return last + 1;
return Task.FromResult( last + 1);
}
public int Last(int next)
+1 -1
View File
@@ -20,7 +20,7 @@ class Program
builder.Modules.Add(new BackendIdentityGenerator());
// builder.UseNetworkGateway(new IPEndPoint(IPAddress.Loopback, 4567), typeof(NextGenerationInteractionModule),
// builder.GetModule<IIdentityGenerator>()!);
var listening = new IPEndPoint(IPAddress.Loopback, 4567);
var listening = new IPEndPoint(IPAddress.Any, 4567);
builder.UseNetworkGateway(listening, typeof(ChannelInteractionModule),
builder.GetModule<IIdentityGenerator>()!);
builder.Modules.Add(new UdpGateway(listening));
+2 -2
View File
@@ -127,12 +127,12 @@ class Program
DemoCheck.TaskCancelation = true;
#endif
const int iterations = 10000;
const int iterations = 10;
var timer = Stopwatch.StartNew();
var x = 0;
for (int i = 0; i < iterations; i++)
{
x = loadSingleton.Next(x);
x = await loadSingleton.Next(x);
}
timer.Stop();
+1 -32
View File
@@ -9,42 +9,11 @@ namespace Example.Shared
[SharedObjectInterface]
public interface ILoadTest : IShared
{
int Next(int last);
Task<int> Next(int last);
int Last(int next);
void C();
void A();
Task AsyncTest(CancellationToken token = default);
}
partial class LoadTestProxy2
: RemoteObjectBase, ILoadTest
{
public LoadTestProxy2(int id, IRepresentationModule representationModule, IEndPointContext context)
: base(id, representationModule, context)
{
}
public void A(){
CallAsync(0).Wait();
}
public async System.Threading.Tasks.Task AsyncTest(System.Threading.CancellationToken token){
await CallAsync(1, cancellationToken : token);
}
public void C(){
CallAsync(2).Wait();
}
public System.Int32 Last(System.Int32 next){
return GetResultAsync<System.Int32>(3, new System.Object[] { next }).GetAwaiter().GetResult();
}
public System.Int32 Next(System.Int32 last){
return GetResultAsync<System.Int32>(4, new System.Object[] { last }).GetAwaiter().GetResult();
}
}
}
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Threading.Channels;
@@ -158,6 +159,7 @@ namespace mROA.Implementation
public class StreamExtractor
{
private static Stopwatch profiler = new Stopwatch();
private readonly Stream _ioStream;
private readonly IContextualSerializationToolKit _serializationToolkit;
private const int BufferSize = ushort.MaxValue;
@@ -171,6 +173,7 @@ namespace mROA.Implementation
_ioStream = ioStream;
_serializationToolkit = serializationToolkit;
_context = context;
profiler.Start();
}
public Action<NetworkMessageHeader> MessageReceived = _ => { };
@@ -194,11 +197,14 @@ namespace mROA.Implementation
public async Task SingleReceive(CancellationToken token = default)
{
Console.WriteLine($"Receive start. Time: {profiler.ElapsedMilliseconds}ms");
var len = ReadMessageLength();
Console.WriteLine($"Received len {len}. Time: {profiler.ElapsedMilliseconds}ms");
var localSpan = _buffer[..len];
await _ioStream.ReadExactlyAsync(localSpan, cancellationToken: token);
Console.WriteLine($"Received. Time: {profiler.ElapsedMilliseconds}ms");
profiler.Restart();
var message = _serializationToolkit.Deserialize<NetworkMessageHeader>(localSpan, _context);
MessageReceived(message);
}
@@ -215,9 +221,13 @@ namespace mROA.Implementation
{
var rawMessage = _serializationToolkit.Serialize(message, _context);
var header = BitConverter.GetBytes((ushort)rawMessage.Length).AsMemory(0, sizeof(ushort));
Console.WriteLine($"Send start. Time: {profiler.ElapsedMilliseconds}ms");
await _ioStream.WriteAsync(header, token);
await _ioStream.WriteAsync(rawMessage, token);
Console.WriteLine($"Send. Time: {profiler.ElapsedMilliseconds}ms");
profiler.Restart();
}
public async Task SendFromChannel(ChannelReader<NetworkMessageHeader> channel,