Skip to content

Instantly share code, notes, and snippets.

@tcpdump-examples
Last active February 15, 2021 11:42
Show Gist options
  • Save tcpdump-examples/627b02bd5c56f6c93a8b38911a8128b9 to your computer and use it in GitHub Desktop.
Save tcpdump-examples/627b02bd5c56f6c93a8b38911a8128b9 to your computer and use it in GitHub Desktop.

source: Why Tcp Window Scaling Improves Network Performance?

Tcp window scaling is a key design in tcp protocol to improve network performance. Today we will dive into this topic to see how tcp window scale works in Linux.

What is tcp window scaling?

The TCP Window Scale option allows window size larger than 65K bytes by using a scale factor to multiply the window size value. This factor is set based on maximum size of receive buffer used by TCP sockets.

In the following example, maximum size of receive buffer is 4194304, so the scale factor is 7.

net.ipv4.tcp_rmem = 4096 87380 4194304

Note: The largest supported scaling factor is 14. This allows TCP window sizes

of up to one Gigabyte.

We can get more info from here. https://www.ietf.org/rfc/rfc1323.txt

Benefit of tcp_window_scaling

The base window size can not exceed 65535 bytes due to the limitations of the TCP header. This makes the window size too small.

This option improves network bandwidth a lot. We can get the window size up to 1GB.

How to Check tcp_window_scaling in Linux?

This is enabled by default in most Linux distributions. We can check it by the following command.

cat /proc/sys/net/ipv4/tcp_window_scaling If the output is 1, that means tcp window scaling is enabled.

If the output is 0, that means tcp window scaling is disabled.

How to enable tcp_window_scaling?

We can use the following command to enable TCP window scaling.

sysctl -w net.ipv4.tcp_window_scaling=1 To make this reboot persistent, we can add the following line to /etc/sysctl.conf

net.ipv4.tcp_window_scaling=1

Tips for Tcp_window_scaling

The window scaling option only appears in the first two packets of a TCP connection, it cannot be changed afterwards.

This only works by enabling this option on both sender and receiver ends. This wouldn't improve the performance of existing connection since the tcp handshark was finished before. We need to restart the tcp connection to utilize this.

Example of tcp window scaling

The scp speed between our two US datacenters was about 1-2MB/s. From the network packets, it turns out that this option was not enabled on one server. We can get more info about how to use tcpdump to capture packets from here.

After tcp window scale is enabled, the scp speed reaches 40MB/s. This is a huge improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment