private async Task PerfTest() { const int OuterLoopCount = 100; const int InnerLoopCount = 10000; const int MessageSize = 1024; var sw = new Stopwatch(); for (int i = 0; i < OuterLoopCount; i++) { using (var content = ExactSizeMemoryPool.Shared.Rent(MessageSize)) { content.Memory.Span.Fill((byte)DataLinkMessageType.Disconnect); BitConverter.TryWriteBytes(content.Memory.Span, i); sw.Restart(); for (int j = 0; j < InnerLoopCount; j++) { _ = _dlc.Broadcast(PerfChannel, content.Memory); } } using (var signal = ExactSizeMemoryPool.Shared.Rent(4)) { BitConverter.TryWriteBytes(signal.Memory.Span, i); var task = _dlc.BroadcastWithAckAsync(PerfChannel, signal.Memory); if (await Task.WhenAny(task, Task.Delay(TimeSpan.FromSeconds(10))) != task) { Console.WriteLine("Perf timeout ..."); } } sw.Stop(); Console.WriteLine($"Perf {i + 1}0000 message sent in {sw.ElapsedMilliseconds} ms."); } }
public static async Task <bool> BroadcastWithAckAsync(this DataLinkCollection dlc, string group, string content) { var length = Encoding.UTF8.GetByteCount(content); using (var owner = ExactSizeMemoryPool.Shared.Rent(length)) { Encoding.UTF8.GetBytes(content, owner.Memory.Span); return(await dlc.BroadcastWithAckAsync(group, owner.Memory)); } }