Skip to content

Commit d80fa38

Browse files
mtmkcaleblloyd
andauthored
Buffer defaults avoiding LOH (#383)
* Buffer defaults avoiding LOH * MinSegmentSize to 64K * MinSegmentSize to 16K * Update src/NATS.Client.Core/Commands/CommandWriter.cs Co-authored-by: Caleb Lloyd <2414837+caleblloyd@users.noreply.github.com> --------- Co-authored-by: Caleb Lloyd <2414837+caleblloyd@users.noreply.github.com>
1 parent 5e66e0b commit d80fa38

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/NATS.Client.Core/Commands/CommandWriter.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ internal sealed class CommandWriter : IAsyncDisposable
2323
// assuming 40 bytes TCP overhead + 40 bytes TLS overhead per packet
2424
private const int SendMemSize = 8520;
2525

26-
// set to a reasonable socket write mem size
27-
private const int MinSegmentSize = 65536;
26+
// should be more than SendMemSize
27+
// https://github.com/nats-io/nats.net.v2/pull/383#discussion_r1484344102
28+
private const int MinSegmentSize = 16384;
2829

2930
private readonly ILogger<CommandWriter> _logger;
3031
private readonly NatsConnection _connection;
@@ -720,6 +721,7 @@ private async ValueTask PongStateMachineAsync(bool lockHeld, CancellationToken c
720721
}
721722
}
722723

724+
[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder))]
723725
private async ValueTask PublishStateMachineAsync(bool lockHeld, string subject, string? replyTo, NatsPooledBufferWriter<byte>? headersBuffer, NatsPooledBufferWriter<byte> payloadBuffer, CancellationToken cancellationToken)
724726
{
725727
try

src/NATS.Client.Core/NatsOpts.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ public sealed record NatsOpts
3131

3232
public ILoggerFactory LoggerFactory { get; init; } = NullLoggerFactory.Instance;
3333

34-
public int WriterBufferSize { get; init; } = 1048576;
34+
public int WriterBufferSize { get; init; } = 65536;
3535

36-
public int ReaderBufferSize { get; init; } = 1048576;
36+
public int ReaderBufferSize { get; init; } = 65536;
3737

3838
public bool UseThreadPoolCallback { get; init; } = false;
3939

0 commit comments

Comments
 (0)