Configure the winsock default send- and receive-buffer size

12 October 2002 by Snakefoot | Comment » | Trackback Off
Usually when reading about TCPIP there is only mentioned one Receive Window for a connection, which is used to control congestion created by network latency.

In the WinNT network architecture a layer is placed on top of the TCPIP layer called AFD(Ancillary Function Driver for Winsock). The AFD provides the winsock interface, which is used by most network applications in Windows and is also supporting things like DNS and DHCP.

The AFD uses two windows which acts as a flowcontrol for the application creating the socket:
  • Send Window: Used when the application is sending data over a connection, if more data is sent than the receiver is able to acknowledge then the AFD-Send-Window will block the transfer for the application, when it reaches the limit of the AFD-Send-Window. The application creating the socket can use setsockopt to adjust SO_SNDBUF.
  • Receive Window: Acts just like the TCPIP-Receive Window, and when creating a Winsocket over TCPIP, then AFD will use the TCPIP Receive Window as AFD-Receive Window. The application creating the socket can use setsockopt to adjust SO_RCVBUF.
The default size of the two AFD-Windows is configured at boot time and is dependent on the available amount of physical memory:
  • 4096 bytes if less than 19 MByte RAM
  • 8192 bytes if more than 19 MByte RAM
If using a high latency or high bandwidth network then the AFD windows can affect performance. A small AFD-Send-Window will constantly be blocking the application sending data. A small AFD-Receive-Window will constantly be saturating the application receiving data (And blocking the remote sender). The two AFD-Windows should have the same value as the optimal TCPIP-Receive-Window to get the best speed.

To set the default size of the AFD-Windows use the following DWORD registry keys :

[HKEY_LOCAL_MACHINE \SYSTEM \CurrentControlSet \Services \Afd \Parameters]
DefaultReceiveWindow = 16384
DefaultSendWindow = 16384

Note that the AFD-Windows should be rounded to a multiple of memory page size (Usually 4096 Bytes). Not a multiple of the Maximum Segment Size(MSS) which is recommended for the TCPIP-Window.

Related : Recommended settings for the TCP/IP stack

More Info MSDN - Write Scalable Winsock Apps Using Completion Ports
More info MS KB Q214397
More info MS KB Q246984
More info MS KB Q311084

Updated: 21 October 2007

Comments:

Comment by john - 23 February 2011 @ 13:40 Reply

great resource, thanks for this post!

Leave a comment


NB! Use the Forum for computer help and off-topic questions.

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>