Skip to content

Conversation

@mtmk
Copy link
Member

@mtmk mtmk commented May 23, 2025

To use this feature it needs to be explicitly turned on to avoid potential issues with existing installations.
Set RequestReplyMode option to Direct to turn it on:

var opts = new NatsOpts { RequestReplyMode = NatsRequestReplyMode.Direct };
await using var connection = new NatsConnection(opts);

JS Publish:

Method Mode Mean Gen0 Gen1 Gen2 Allocated
PublishAsync SharedInbox 136,716.0 us - - - 3617.91 KB
PublishAsync Direct 123,555.9 us - - - 2359.89 KB
PublishConcurrentlyAsync SharedInbox 8,862.1 us 250.0000 125.0000 46.8750 2992.3 KB
PublishConcurrentlyAsync Direct 11,191.3 us 250.0000 125.0000 46.8750 2997.1 KB

KV:

Method Mode Mean Gen0 Gen1 Gen2 Allocated
TryGetAsync SharedInbox 142.3 us 0.2441 - - 4.26 KB
TryGetAsync Direct 135.0 us - - - 2.25 KB
GetAsync SharedInbox 160.9 us 0.2441 - - 5.51 KB
GetAsync Direct 177.0 us 0.2441 - - 3.45 KB
TryGetMultiAsync SharedInbox 1,574.0 us 41.0156 9.7656 1.9531 536.02 KB
TryGetMultiAsync Direct 1,585.5 us 23.4375 5.8594 - 322.94 KB
GetMultiAsync SharedInbox 1,768.5 us 56.6406 9.7656 1.9531 743.52 KB
GetMultiAsync Direct 1,760.2 us 39.0625 15.6250 - 536.43 KB

we have performance gains for all except PublishConcurrently which is ~20% slower. shouldn't be a show stopper since it's not widely used and the feature is opt-in.


for (var i = 0; i < retryMax; i++)
{
if (Connection.Opts.RequestReplyMode == NatsRequestReplyMode.Direct)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feature toggle needs to be explicitly turned on to avoid existing applications being affected.

@mtmk mtmk marked this pull request as ready for review May 23, 2025 22:44
@mtmk mtmk requested a review from scottf May 23, 2025 22:44
mtmk added a commit that referenced this pull request May 24, 2025
* Add RequestReplyMode for JetStream (#867)
@mtmk mtmk mentioned this pull request May 24, 2025
Copy link
Member

@wallyqs wallyqs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mtmk mtmk merged commit e59beee into main May 24, 2025
24 of 25 checks passed
@mtmk mtmk deleted the js-pub-req-rep-direct branch May 24, 2025 00:57
mtmk added a commit that referenced this pull request May 24, 2025
* Add RequestReplyMode for JetStream (#867)
aradalvand pushed a commit to aradalvand/nats.net that referenced this pull request May 25, 2025
* Add RequestReplyMode for JetStream

* Add benchmarks
aradalvand pushed a commit to aradalvand/nats.net that referenced this pull request May 25, 2025
* Add RequestReplyMode for JetStream (nats-io#867)
mtmk added a commit that referenced this pull request Jun 30, 2025
* Fix inbox collection was modified exception (#885)
* Cleanup Csproj (#869)
* Add RequestReplyMode for JetStream (#867)
@mtmk mtmk mentioned this pull request Jun 30, 2025
mtmk added a commit that referenced this pull request Jun 30, 2025
* Fix inbox collection was modified exception (#885)
* Cleanup Csproj (#869)
* Add RequestReplyMode for JetStream (#867)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants