feat: replace inline writes with channel-based write loop and batch flush

This commit is contained in:
Joseph Doherty
2026-02-22 23:41:44 -05:00
parent ad6a02b9a2
commit 31660a4187
3 changed files with 118 additions and 71 deletions

View File

@@ -244,7 +244,7 @@ public sealed class NatsServer : IMessageRouter, ISubListAccess, IDisposable
// Simple round-robin -- pick based on total delivered across group
var idx = Math.Abs((int)Interlocked.Increment(ref sender.OutMsgs)) % queueGroup.Length;
// Undo the OutMsgs increment -- it will be incremented properly in SendMessageAsync
// Undo the OutMsgs increment -- it will be incremented properly in SendMessage
Interlocked.Decrement(ref sender.OutMsgs);
for (int attempt = 0; attempt < queueGroup.Length; attempt++)
@@ -270,8 +270,7 @@ public sealed class NatsServer : IMessageRouter, ISubListAccess, IDisposable
if (sub.MaxMessages > 0 && count > sub.MaxMessages)
return;
// Fire and forget -- deliver asynchronously
_ = client.SendMessageAsync(subject, sub.Sid, replyTo, headers, payload, CancellationToken.None);
client.SendMessage(subject, sub.Sid, replyTo, headers, payload);
}
public Account GetOrCreateAccount(string name)