Skip to content

Commit

Permalink
Buffer defaults avoiding LOH (#383)
Browse files Browse the repository at this point in the history
* Buffer defaults avoiding LOH

* MinSegmentSize to 64K

* MinSegmentSize to 16K

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

Co-authored-by: Caleb Lloyd <[email protected]>

---------

Co-authored-by: Caleb Lloyd <[email protected]>
  • Loading branch information
mtmk and caleblloyd authored Feb 9, 2024
1 parent 5e66e0b commit d80fa38
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/NATS.Client.Core/Commands/CommandWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ internal sealed class CommandWriter : IAsyncDisposable
// assuming 40 bytes TCP overhead + 40 bytes TLS overhead per packet
private const int SendMemSize = 8520;

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

private readonly ILogger<CommandWriter> _logger;
private readonly NatsConnection _connection;
Expand Down Expand Up @@ -720,6 +721,7 @@ private async ValueTask PongStateMachineAsync(bool lockHeld, CancellationToken c
}
}

[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder))]
private async ValueTask PublishStateMachineAsync(bool lockHeld, string subject, string? replyTo, NatsPooledBufferWriter<byte>? headersBuffer, NatsPooledBufferWriter<byte> payloadBuffer, CancellationToken cancellationToken)
{
try
Expand Down
4 changes: 2 additions & 2 deletions src/NATS.Client.Core/NatsOpts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public sealed record NatsOpts

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

public int WriterBufferSize { get; init; } = 1048576;
public int WriterBufferSize { get; init; } = 65536;

public int ReaderBufferSize { get; init; } = 1048576;
public int ReaderBufferSize { get; init; } = 65536;

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

Expand Down

0 comments on commit d80fa38

Please sign in to comment.