Tips To Improve TCP Performance

Photo by NASA on Unsplash

Tips To Improve TCP Performance

I've started reading High Performance Browser Networking book and found some useful tips about optimizing the TCP performance at the end of chapter 2, Building Blocks of TCP, so I decided to share them.

Tuning Server Configuration

TCP best practices and underlying algorithms that govern its performance continue to evolve, and most of these changes are available only in the latest kernels.
Keeping your servers up to date ensures the optimal interaction between the sender's and the receiver's TCP stacks.

With the latest kernel in place, it is good practice to ensure that your server is configured to use the following best practices:

1. Increasing TCP's Initial Congestion Window

A larger starting congestion window allows TCP transfers more data in the first roundtrip and significantly accelerates the window growth, an especially critical optimization for bursty and short-lived connections.

To learn more about this, read this section about Congestion avoidance and control.

2. Slow Start Restart

Disabling slow-restart after idle will improve the performance of long-lived TCP connections, which transfers data in bursts.
To learn more about this, read this note about Slow Start Restart.

4. Window Scaling

Enabling window scaling increases the maximum receive window size and allows high-latency connections to achieve better throughput.
To learn more about this, read this note about Window Scaling.

4. TCP Fast Open

Allows application data to be sent in the initial SYN packet in certain situations.
TFO is a new optimization, which requires support on both client and server.
To learn more about this, read this note about TCP Fast Open.

Tuning Application Behavior

Tuning the performance of TCP allows the server and client to deliver the best throughput and latency for an individual connection.
However, how an application uses each new, or established, TCP connection can have an even greater impact:

  • No bit is faster than the one that is not sent; send fewer bits.

  • We can't make the bits travel faster, but we can move the bits closer.

  • TCP connection reuse is critical to improve performance.

Eliminating unnecessary resources or ensuring the minimum number of bits is transferred by applying the appropriate compression algorithms and locating the bits closer to the client, by geo-distributing servers around the world (using a CDN) will help reduce the latency of network roundtrips and significantly improve TCP performance.

Performance Checklist

Optimizing TCP performance pays high dividends, regardless of the type of application, for every new connection to your servers.
A short list to put on the agenda:

  • Upgrade server kernel to the latest version.

  • Ensure that CWND size is set to 10.

  • Disable slow-start after idle.

  • Ensure that window scaling is enabled.

  • Eliminate redundant data transfers.

  • Compress transferred data.

  • Position servers closer to the use to reduce roundtrip times.

  • Reuse established TCP connections whenever possible.