SO_RCVBUF/SO_SNDBUF support

9 views
Skip to first unread message

Maksim Dmitrichenko

unread,
Oct 18, 2025, 8:11:13 AMOct 18
to nats
Hi!

I wonder if there is a reason that NATS client (at least NATS C) doesn't have an option to provide custom socket buffer sizes to set them via SO_RCVBUF/SO_SNDBUF socket option? If there is no any reason, would you review my PR?

--
With best regards,
  Max

Scott Fauerbach

unread,
Oct 18, 2025, 8:46:14 AMOct 18
to nats
As it turns out, this "support" was recently added to the Java client. But notice I put support it in quotes. For Java at least, the api docs for the socket implementation say that the implementation will use this as a hint. Also we've noticed on linux machines running the client, that the size of the buffer changes/grows during runtime all by itself, and turns out that this support may not be of use. Someone else would have to speak to other clients and how their underlying socket implementations accept and use this type of configuration.

Maksim Dmitrichenko

unread,
Oct 21, 2025, 9:17:27 AMOct 21
to nat...@googlegroups.com
Hi Scott!

As to my understanding the SO_RCVBUF/SO_SNDBUF options correspond to
the net.core.rmem_max/net.core.wmem_max parameters though socket
options are applied individually while sysctl are applied to the whole
system and to all socket types. These are maximum values. Regarding
the TCP sockets there are two more params
net.ipv4.tcp_rmem/net.ipv4.tcp_wmem - these control TCP buffer
behavior more precisely but the maximum here is limited by values in
SO_RCVBUF/SO_SNDBUF or net.core.rmem_max/net.core.wmem_max.

So, it is OK that the size of the buffer changes over time. These are
the maximum values that are used when there is a real need for such
big buffers, for example when you need a big throughput while having a
rather large RTT. They are hints for the kernel and no one can
explicitly control exact sizes from the userspace - no matter Java, C
or rust client.

сб, 18 окт. 2025 г. в 16:46, Scott Fauerbach <sc...@synadia.com>:
>
> As it turns out, this "support" was recently added to the Java client. But notice I put support it in quotes. For Java at least, the api docs for the socket implementation say that the implementation will use this as a hint. Also we've noticed on linux machines running the client, that the size of the buffer changes/grows during runtime all by itself, and turns out that this support may not be of use. Someone else would have to speak to other clients and how their underlying socket implementations accept and use this type of configuration.

--
With best regards
Maksim Dmitrichenko
Reply all
Reply to author
Forward
0 new messages