Why Do You Need the TCP Window Size?

Photo by Erik Mclean on Unsplash
Multiple packages, one acknowledge

How does my machine decide to send an acknowledgment packet to the remote server?

Each TCP packet has a header. Each header has a 2-byte long reserved field for Window Size. The receiver and the sender reveal their available Window Size in the TCP package’s header. You can see the Window Size value in the output above: the parameter `win`.

What is the Window Size?

The receiver tells the sender its window size (how much data to receive before sending an acknowledgment).

This feature has two advantages:

1) The application does not need to be notified each time a package arrives. The application receives bulk data from the TCP buffer.

What happens if the window size is full?

When the application does not read data from the TCP buffer, TCP tells the sender, “my window size for this TCP connection is 0 (zero)”.

const server = new net.Server();
server.listen(8080, "", function() {
console.log(`Server is ready to use.`);

What is the maximum value of Window Size?

The Window Size space field is 2-byte long in the TCP header. This means that the maximum window size (read buffer) value can be 65,535 bytes. We use the TCP Window Scale Factor, as 65,635 bytes are pretty low for modern network infrastructures.

(2 ^ window scale factor value) * window size.
Window size = 65,535
Window scale factor = 14
(2 ^ 14) * 65, 535
16384 * 65,635 = 1 Gigabyte

How to calculate TCP Throughput?

TCP Throughput means the maximum number of bits that can be transmitted per second.

Window size: 65535 bytes
Window scale factor: 7
RTT: 35 ms (0.035 seconds)
Total window size per connection: (2 ^ 7) * 65535 = 8388480 Bytes8388480 * 8 = 67107840 (Window size in bit)67107840 / 0.035 = 1917366857 bits = 1917 Mbps

How to calculate the most efficient TCP Window?

(Bandwidth in bit per second * RTT in seconds) / 8 = Window Size / 1000

Bandwith: 100 Mbps -> 100.000.000 Bits
RTT: 65 ms -> 0.065 seconds
(100.000.000 * 0.065) / 8 = 6.500.000
6.500.000 / 8 = 812.500 Bytes
812.500 / 1000 = 812 KB Window Size.

What is the difference between MSS and Window Size?

MSS (maximum segment size) and Window Size things are independent of each other.

How to adjust Window Size in Linux?

It would be best if you made sure window scaling is enabled on your Linux:

sysctl net.ipv4.tcp_window_scaling
root@main:~# sysctl net.ipv4.tcp_rmem
net.ipv4.tcp_rmem = 4096 131072 6291456



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store