C# get max value for Socket.ReceiveBufferSize and Socket.SendBufferSize on a system

前端 未结 2 1573
囚心锁ツ
囚心锁ツ 2021-02-05 19:22

Our high throughput application (~1gbps) benefits greatly from a large ReceiveBufferSize and SendBufferSize.

I noticed on my machine I can have a 100 MB buffer size with

2条回答
  •  执笔经年
    2021-02-05 20:06

    Actually for high performance networking the SO_RCVBUF and SO_SNDBUF options should be set to 0 to avoid buffer copies, as per KB181611:

    If you use the SO_RCVBUF and SO_SNDBUF option to set zero TCP stack receive and send buffer, you basically instruct the TCP stack to directly perform I/O using the buffer provided in your I/O call. Therefore, in addition to the nonblocking advantage of the overlapped socket I/O, the other advantage is better performance because you save a buffer copy between the TCP stack buffer and the user buffer for each I/O call. But you have to make sure you don't access the user buffer once it's submitted for overlapped operation and before the overlapped operation completes.

    The max values you can set these options (which are the real setting behind the managed Socket.ReceiveBufferSize) are 'implementation dependent'. Other TCP parameters are documented at TCP/IP Registry Settings.

提交回复
热议问题