Some latency bug found
This commit is contained in:
@@ -9,9 +9,9 @@ namespace Example.Backend
|
|||||||
[SharedObjectSingleton]
|
[SharedObjectSingleton]
|
||||||
public class LoadTestImp : ILoadTest
|
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)
|
public int Last(int next)
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class Program
|
|||||||
builder.Modules.Add(new BackendIdentityGenerator());
|
builder.Modules.Add(new BackendIdentityGenerator());
|
||||||
// builder.UseNetworkGateway(new IPEndPoint(IPAddress.Loopback, 4567), typeof(NextGenerationInteractionModule),
|
// builder.UseNetworkGateway(new IPEndPoint(IPAddress.Loopback, 4567), typeof(NextGenerationInteractionModule),
|
||||||
// builder.GetModule<IIdentityGenerator>()!);
|
// builder.GetModule<IIdentityGenerator>()!);
|
||||||
var listening = new IPEndPoint(IPAddress.Loopback, 4567);
|
var listening = new IPEndPoint(IPAddress.Any, 4567);
|
||||||
builder.UseNetworkGateway(listening, typeof(ChannelInteractionModule),
|
builder.UseNetworkGateway(listening, typeof(ChannelInteractionModule),
|
||||||
builder.GetModule<IIdentityGenerator>()!);
|
builder.GetModule<IIdentityGenerator>()!);
|
||||||
builder.Modules.Add(new UdpGateway(listening));
|
builder.Modules.Add(new UdpGateway(listening));
|
||||||
|
|||||||
@@ -127,12 +127,12 @@ class Program
|
|||||||
DemoCheck.TaskCancelation = true;
|
DemoCheck.TaskCancelation = true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const int iterations = 10000;
|
const int iterations = 10;
|
||||||
var timer = Stopwatch.StartNew();
|
var timer = Stopwatch.StartNew();
|
||||||
var x = 0;
|
var x = 0;
|
||||||
for (int i = 0; i < iterations; i++)
|
for (int i = 0; i < iterations; i++)
|
||||||
{
|
{
|
||||||
x = loadSingleton.Next(x);
|
x = await loadSingleton.Next(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|||||||
@@ -9,42 +9,11 @@ namespace Example.Shared
|
|||||||
[SharedObjectInterface]
|
[SharedObjectInterface]
|
||||||
public interface ILoadTest : IShared
|
public interface ILoadTest : IShared
|
||||||
{
|
{
|
||||||
int Next(int last);
|
Task<int> Next(int last);
|
||||||
int Last(int next);
|
int Last(int next);
|
||||||
void C();
|
void C();
|
||||||
void A();
|
void A();
|
||||||
|
|
||||||
Task AsyncTest(CancellationToken token = default);
|
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;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Channels;
|
using System.Threading.Channels;
|
||||||
@@ -158,6 +159,7 @@ namespace mROA.Implementation
|
|||||||
|
|
||||||
public class StreamExtractor
|
public class StreamExtractor
|
||||||
{
|
{
|
||||||
|
private static Stopwatch profiler = new Stopwatch();
|
||||||
private readonly Stream _ioStream;
|
private readonly Stream _ioStream;
|
||||||
private readonly IContextualSerializationToolKit _serializationToolkit;
|
private readonly IContextualSerializationToolKit _serializationToolkit;
|
||||||
private const int BufferSize = ushort.MaxValue;
|
private const int BufferSize = ushort.MaxValue;
|
||||||
@@ -171,6 +173,7 @@ namespace mROA.Implementation
|
|||||||
_ioStream = ioStream;
|
_ioStream = ioStream;
|
||||||
_serializationToolkit = serializationToolkit;
|
_serializationToolkit = serializationToolkit;
|
||||||
_context = context;
|
_context = context;
|
||||||
|
profiler.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Action<NetworkMessageHeader> MessageReceived = _ => { };
|
public Action<NetworkMessageHeader> MessageReceived = _ => { };
|
||||||
@@ -194,11 +197,14 @@ namespace mROA.Implementation
|
|||||||
|
|
||||||
public async Task SingleReceive(CancellationToken token = default)
|
public async Task SingleReceive(CancellationToken token = default)
|
||||||
{
|
{
|
||||||
|
Console.WriteLine($"Receive start. Time: {profiler.ElapsedMilliseconds}ms");
|
||||||
var len = ReadMessageLength();
|
var len = ReadMessageLength();
|
||||||
|
Console.WriteLine($"Received len {len}. Time: {profiler.ElapsedMilliseconds}ms");
|
||||||
var localSpan = _buffer[..len];
|
var localSpan = _buffer[..len];
|
||||||
|
|
||||||
await _ioStream.ReadExactlyAsync(localSpan, cancellationToken: token);
|
await _ioStream.ReadExactlyAsync(localSpan, cancellationToken: token);
|
||||||
|
Console.WriteLine($"Received. Time: {profiler.ElapsedMilliseconds}ms");
|
||||||
|
profiler.Restart();
|
||||||
var message = _serializationToolkit.Deserialize<NetworkMessageHeader>(localSpan, _context);
|
var message = _serializationToolkit.Deserialize<NetworkMessageHeader>(localSpan, _context);
|
||||||
MessageReceived(message);
|
MessageReceived(message);
|
||||||
}
|
}
|
||||||
@@ -215,9 +221,13 @@ namespace mROA.Implementation
|
|||||||
{
|
{
|
||||||
var rawMessage = _serializationToolkit.Serialize(message, _context);
|
var rawMessage = _serializationToolkit.Serialize(message, _context);
|
||||||
var header = BitConverter.GetBytes((ushort)rawMessage.Length).AsMemory(0, sizeof(ushort));
|
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(header, token);
|
||||||
await _ioStream.WriteAsync(rawMessage, token);
|
await _ioStream.WriteAsync(rawMessage, token);
|
||||||
|
Console.WriteLine($"Send. Time: {profiler.ElapsedMilliseconds}ms");
|
||||||
|
profiler.Restart();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SendFromChannel(ChannelReader<NetworkMessageHeader> channel,
|
public async Task SendFromChannel(ChannelReader<NetworkMessageHeader> channel,
|
||||||
|
|||||||
Reference in New Issue
Block a user