Faster cbor. Up to 234 000 rps
This commit is contained in:
@@ -0,0 +1,16 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<PublishAot>true</PublishAot>
|
||||||
|
<InvariantGlobalization>true</InvariantGlobalization>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Example.Shared\Example.Shared.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
using System.Net;
|
||||||
|
using Example.Shared;
|
||||||
|
using mROA.Abstract;
|
||||||
|
using mROA.Cbor;
|
||||||
|
using mROA.Codegen;
|
||||||
|
using mROA.Implementation;
|
||||||
|
using mROA.Implementation.Backend;
|
||||||
|
using mROA.Implementation.Bootstrap;
|
||||||
|
using mROA.Implementation.Frontend;
|
||||||
|
|
||||||
|
const int C = 100;
|
||||||
|
var time = TimeSpan.FromSeconds(10);
|
||||||
|
Console.WriteLine($"Starting bench for {time} from {C} connections");
|
||||||
|
var cts = new CancellationTokenSource();
|
||||||
|
new RemoteTypeBinder();
|
||||||
|
|
||||||
|
var tasks = new Task<int>[C];
|
||||||
|
for (int i = 0; i < C; i++)
|
||||||
|
{
|
||||||
|
tasks[i] = Requests(cts.Token);
|
||||||
|
}
|
||||||
|
|
||||||
|
cts.CancelAfter(time);
|
||||||
|
Console.WriteLine("Start waiting");
|
||||||
|
await Task.WhenAll(tasks);
|
||||||
|
Console.WriteLine("End waiting");
|
||||||
|
|
||||||
|
var totalRequests = tasks.Sum(i => i.Result);
|
||||||
|
Console.WriteLine($"Total requests: {totalRequests}");
|
||||||
|
Console.WriteLine($"Results: {totalRequests / time.TotalSeconds:N} RPS");
|
||||||
|
|
||||||
|
async Task<int> Requests(CancellationToken token)
|
||||||
|
{
|
||||||
|
var builder = new FullMixBuilder();
|
||||||
|
|
||||||
|
builder.Modules.Add(new CborSerializationToolkit());
|
||||||
|
builder.Modules.Add(new EndPointContext());
|
||||||
|
builder.Modules.Add(new RemoteInstanceRepository());
|
||||||
|
builder.Modules.Add(new ChannelInteractionModule());
|
||||||
|
// builder.Modules.Add(new UdpUntrustedInteraction());
|
||||||
|
builder.Modules.Add(new RepresentationModule());
|
||||||
|
var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 4567);
|
||||||
|
builder.Modules.Add(new NetworkFrontendBridge(serverEndPoint));
|
||||||
|
builder.Modules.Add(new StaticRepresentationModuleProducer());
|
||||||
|
// builder.Modules.Add(new RequestExtractor());
|
||||||
|
builder.Modules.Add(new BasicExecutionModule());
|
||||||
|
var methodRepo = new CollectableMethodRepository();
|
||||||
|
methodRepo.AppendInvokers(new GeneratedInvokersCollection());
|
||||||
|
builder.Modules.Add(methodRepo);
|
||||||
|
builder.Modules.Add(new GeneratedCallIndexProvider());
|
||||||
|
builder.UseCollectableContextRepository();
|
||||||
|
builder.Modules.Add(new CancellationRepository());
|
||||||
|
|
||||||
|
builder.Build();
|
||||||
|
|
||||||
|
var frontendBridge = builder.GetModule<IFrontendBridge>()!;
|
||||||
|
await frontendBridge.Connect();
|
||||||
|
// _ = builder.GetModule<RequestExtractor>()!.StartExtraction();
|
||||||
|
// _ = builder.GetModule<UdpUntrustedInteraction>().Start(serverEndPoint);
|
||||||
|
var context = builder.GetModule<RemoteInstanceRepository>();
|
||||||
|
|
||||||
|
var factory =
|
||||||
|
context.GetSingletonObject<ILoadTest>(
|
||||||
|
builder.GetModule<IEndPointContext>());
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
int a;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
a = await factory.Next(2);
|
||||||
|
count++;
|
||||||
|
} while (!token.IsCancellationRequested);
|
||||||
|
|
||||||
|
Console.WriteLine(a);
|
||||||
|
return count;
|
||||||
|
}
|
||||||
@@ -15,12 +15,13 @@ namespace mROA.Cbor
|
|||||||
{
|
{
|
||||||
private Dictionary<Type, List<PropertyInfo>> _propertiesCache = new();
|
private Dictionary<Type, List<PropertyInfo>> _propertiesCache = new();
|
||||||
public static TimeSpan SerializationTime = TimeSpan.Zero;
|
public static TimeSpan SerializationTime = TimeSpan.Zero;
|
||||||
|
|
||||||
public byte[] Serialize(object objectToSerialize, IEndPointContext context)
|
public byte[] Serialize(object objectToSerialize, IEndPointContext context)
|
||||||
{
|
{
|
||||||
var sw = Stopwatch.StartNew();
|
var sw = Stopwatch.StartNew();
|
||||||
var writer = new CborWriter();
|
var writer = new CborWriter(initialCapacity:64);
|
||||||
WriteData(objectToSerialize, writer, context);
|
WriteData(objectToSerialize, writer, context);
|
||||||
var result = writer.Encode();
|
var result = writer.Encode();
|
||||||
sw.Stop();
|
sw.Stop();
|
||||||
SerializationTime = SerializationTime.Add(sw.Elapsed);
|
SerializationTime = SerializationTime.Add(sw.Elapsed);
|
||||||
return result;
|
return result;
|
||||||
@@ -28,7 +29,7 @@ namespace mROA.Cbor
|
|||||||
|
|
||||||
public int Serialize(object objectToSerialize, Span<byte> destination, IEndPointContext context)
|
public int Serialize(object objectToSerialize, Span<byte> destination, IEndPointContext context)
|
||||||
{
|
{
|
||||||
var writer = new CborWriter();
|
var writer = new CborWriter(initialCapacity:64);
|
||||||
WriteData(objectToSerialize, writer, context);
|
WriteData(objectToSerialize, writer, context);
|
||||||
return writer.Encode(destination);
|
return writer.Encode(destination);
|
||||||
}
|
}
|
||||||
@@ -288,7 +289,6 @@ namespace mROA.Cbor
|
|||||||
return ReadDictionary(reader, type, context);
|
return ReadDictionary(reader, type, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (type == typeof(DateTimeOffset))
|
if (type == typeof(DateTimeOffset))
|
||||||
return reader.ReadDateTimeOffset();
|
return reader.ReadDateTimeOffset();
|
||||||
|
|
||||||
@@ -418,7 +418,8 @@ namespace mROA.Cbor
|
|||||||
property.SetValue(obj, value);
|
property.SetValue(obj, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
reader.ReadEndArray();
|
if (reader.PeekState() == CborReaderState.EndArray)
|
||||||
|
reader.ReadEndArray();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -447,6 +448,7 @@ namespace mROA.Cbor
|
|||||||
{
|
{
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
var propertiesList = FilterProperties(type.GetProperties());
|
var propertiesList = FilterProperties(type.GetProperties());
|
||||||
_propertiesCache[type] = propertiesList;
|
_propertiesCache[type] = propertiesList;
|
||||||
return propertiesList;
|
return propertiesList;
|
||||||
|
|||||||
Reference in New Issue
Block a user