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

前端 未结 2 1618
囚心锁ツ
囚心锁ツ 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:09

    Those two properties internally play with the socket options (via SetSocketOption, eventually to the native setsockopt). If memory serves these are going to depend on the non-paged pool memory available (which changes machine to machine) and potentially which network driver is on each machine.

    Regardless, you actually aren't guaranteed that the buffer size you requested is used, you'll have to retrieve the current buffer size after the fact to make sure it was used. Moreover, on Windows 7 and 2008 machines it is my understanding that your buffers may be dynamically increased/decreased.

    In short, you likely can only test increasing buffer sizes and take the maximum that does not cause an error. There are too many variables at play which could determine the maximum size.

提交回复
热议问题