Tuning the TCP receive window size for optimal download speed

Broadband Internet Speed test

Internet Speed test Bunny
Are your test results not up to par with your expectations?

It might be that your TCP receive window size is not at its optimal value! Tuning it is the single most important thing towards optimizing your Internet connection settings.

Download registry files.
Broadband Internet Speed test.

So what is this TCP receive window size, why does it matter, and how can I change it?

The TCP receive window is the amount of unacknowledged data between the sender and the receiver. If the window size is set at 16KB, the sender waits after sending 16KB, until the receiver has acknowledged that it has received the data. Only then will the sender start transmitting data again. If the transmission delay between the sender and the receiver is very high, this will result in very slow throughput. Both sender and receiver will spend most of the time waiting for data in transmission between the hosts.

In order to improve throughput the window size needs to be set at a high enough value, that will enable the sender to keep transmitting data at all time. The TCP receive window is an upper bound on the amount of data that will be allowed to be in the pipe between the sending and receiving host.

The actual window size varies throughout the session. The TCP protocol uses something called slow start, meaning the sender will start sending a small amount of data at first, until it receives an acknowledgement message from the receiver. The sender will then try to send larger and larger chunks of data, until the pipe between sender and receiver becomes full, at which point the window size is made smaller, and data starts flowing again, and the window size can be increased again. This cycle of expanding and shrinking continues throughout the session to make sure the connection is working at its maximum.

However, there's a hard limit of the window size! The receiver tells the sender its maximum TCP receive window size, and this sets an upper bound of the connection, regardless of the actual bandwidth available on the network.

Can I do anything about this, and how?

The most common direction for data to flow is from a remote host to your computer. This makes the remote host the sender, and your computer the receiver. Since it's the receiver that sets the upper bound for the throughput, by its advertising the maximum TCP receive window size, any changes you make on your end to the recieve window size will affect the throughput you see.

And yes, you can change this value on your computer!

In most cases, the link between you and your ISP is the slowest link of the network, no matter what site on the Internet you are trying to reach. Therefore any calculations that involve bandwidth values should use the specification your ISP provides.

A lot of Internet sites, due to the global nature of the Internet, will be quite far from where you are located. This will cause a long round-trip delay, that is the time it takes for messages to travel from your computer to the remote Internet site, and back to you.

So how big should the TCP receive window size be?

The calculation is simple:

   receive window size = bandwidth * delay

While you were loading this page we measured the round trip delay from our server to your computer, and got the value 105.362 ms.

Let's say you have a WAN connection with a nominal 1544 kbps bandwidth available, and the delay to the host you want to download from is 105.362 ms.

Using the algorithm above the TCP receive window size should be at least

    1544000 bits/second * 0.105362 seconds = 162679 bits = 20 KB

If you have a WAN connection with a nominal 10 Mbps bandwidth available, with the same delay, the algorithm gives a TCP receive window size of at least

    10 Mbps * 105.362 ms = 129 KB

Now, depending on your delay to our server, and of course the bandwidth you have available, you may or may not get a reasonable figure using this algorithm. If you have very high latency on your link you may get an extremely large value. So are there any negative issues with a large window size?

You might think that if everyone on the Internet pushed their window sizes to 128 KB for instance, Bad Things will happen. The TCP algorithm is smarter than that. The window size is only an upper bound. The sender slowly increases the size of its transmit window. If packet loss is detected by the server it uses that as an indication that the window size is too large, and reduces it. The system is self adjusting, and setting the window size to a large value will not have any negative affects on the network.

Setting the window size at a large value will not negatively affect connections with low latency (small delay). Again, the slow start component of TCP will make sure that the session is working at the maximum of either the bandwidth available or the TCP receive window size, whatever limit is hit first.

The only negative affect is the memory allocation on your computer. This may degrade performance on computers with low memory configuration. But RAM is cheap, and on a system with 128 MB of memory or more, it's unlikely that there will be a lack of resources with a larger TCP receive window size.