Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-5030

Only modify TCP buffer sizes if explicitly configured

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Dotnet Drivers

      In TcpStreamFactory, the socket's SO_RCVBUF and SO_SNDBUF are set to the values contained in TcpStreamSettings:

      socket.ReceiveBufferSize = _settings.ReceiveBufferSize;
      socket.SendBufferSize = _settings.SendBufferSize;
      

      The default value for these buffer sizes is 64KB. (See the constructor for TcpStreamSettings.) Most users do not explicitly modify these settings and end up with the defaults.

      The MSDN docs for Socket.ReceiveBufferSize indicate that the value is OS-dependent, but the API docs say (incorrectly) that it is 8KB:

      An Int32 that contains the size, in bytes, of the receive buffer. The default is 8192.

      Empirically comparing the values set by various OSes:

      OS SO_RCVBUF SO_SNDBUF
      Windows 10 65536 65536
      MacOS Sonoma 408300 146988
      Ubuntu 20.04 131072 131072

      While the intent was to increase the TCP buffer sizes, modern OSes appear to have increased their defaults and thus the code is actually decreasing the TCP buffer sizes.

      We should make TcpStreamSettings.ReceiveBufferSize and TcpStreamSettings.SendBufferSize nullable and only modify the OS defaults if their values are explicitly set by the user.

      This issue originated from this forums post.

            Assignee:
            james.kovacs@mongodb.com James Kovacs
            Reporter:
            james.kovacs@mongodb.com James Kovacs
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: