How to Tune TCP for Throughput
Adjust send and receive buffers, window scaling and congestion control so a high-latency link is not limited by defaults.
On this page
Introduction
A default TCP stack is tuned for the common case: a short round-trip time and a modest bandwidth. On a link with high latency or high bandwidth, the defaults leave throughput on the table, because the amount of data in flight is limited by the window size, and the default window is often too small for a link whose bandwidth-delay product is large. Tuning TCP is about matching the window and the buffer to the actual bandwidth-delay product, and choosing a congestion control algorithm that fits the network. This article covers the buffer settings, window scaling, congestion control, and how to measure whether the tuning helped.
Why the Defaults Limit Throughput
TCP throughput is bounded by the window: the sender can have only so much unacknowledged data in flight, which is the receive window and the congestion window together. On a link with a large bandwidth-delay product, that product is how many bytes must be in flight to fill the pipe, and if the window is smaller, throughput is the window divided by the round-trip time, regardless of the bandwidth available.
A local connection has a tiny bandwidth-delay product, so the default window suffices. A connection across a continent or a satellite has a huge one, and the same default window yields a fraction of the possible throughput. The fix is to raise the window and the buffers, and to ensure window scaling is enabled so windows larger than 64 kilobytes can be advertised at all.
Send and Receive Buffers
The send buffer holds data the application has written but the network has not yet acknowledged; the receive buffer holds data received but not yet read by the application. Both bound the maximum window. Increase them so the window can grow to the bandwidth-delay product, and set the maximum high enough that a high-latency connection can use it. Autotuning lets the kernel size the buffer from the connection’s behaviour, which is the modern default and usually better than a fixed value.
# Inspect current TCP buffer and window settings
sysctl net.ipv4.tcp_rmem net.ipv4.tcp_wmem net.ipv4.tcp_window_scaling
# Enable autotuning and raise the maximums (values are min, default, max in bytes)
sysctl -w net.ipv4.tcp_rmem="4096 87380 134217728"
sysctl -w net.ipv4.tcp_wmem="4096 65536 134217728"
sysctl -w net.ipv4.tcp_window_scaling=1
# Make it persistent
cat >> /etc/sysctl.d/99-tcp-tuning.conf <<'EOF'
net.ipv4.tcp_rmem = 4096 87380 134217728
net.ipv4.tcp_wmem = 4096 65536 134217728
net.ipv4.tcp_window_scaling = 1
EOF
sysctl --system
Window Scaling
The original TCP window field is sixteen bits, which caps the advertised window at 64 kilobytes, far below what a high-latency link needs. Window scaling is a negotiated multiplier that extends the effective window beyond that limit. Both endpoints must support it, and it must be enabled on hosts that carry long-distance traffic. Without scaling, raising the buffers has no effect because the window cannot be advertised.
Scaling is negotiated at connection setup, so it applies to new connections only and cannot be changed mid-connection. Verify it is enabled, and remember that a middlebox that rewrites or resets scaling options can break high-throughput connections even when both endpoints support it.
Congestion Control
The congestion window is the sender’s estimate of the network’s capacity; the algorithm controlling it decides how fast to ramp up and how to react to loss. Loss-based algorithms such as CUBIC treat any loss as congestion and back off, which on a link with random loss (a wireless or long-haul path) can halve throughput for a loss that was not congestion. Delay-based and hybrid algorithms estimate the bottleneck differently and can be gentler on such links.
# List available congestion control algorithms
sysctl net.ipv4.tcp_available_congestion_control
# Use BBR (where available) for high-latency or lossy links
sysctl -w net.ipv4.tcp_congestion_control=bbr
sysctl -w net.core.default_qdisc=fq
# Verify the change and inspect per-connection state via TCP_INFO
sysctl net.ipv4.tcp_congestion_control
ss -ti | head -5 # shows cwnd, rtt, retransmits per socket
Related Socket Options
Application-level socket options complement the host settings. TCP_NODELAY disables Nagle’s algorithm, which is right for latency-sensitive interactive traffic and wrong for bulk transfer where coalescing small writes helps. SO_REUSEPORT lets several processes share a listening socket so the kernel distributes connections, which improves throughput on multi-core servers by avoiding a single accept queue.
For a bulk transfer, do not disable Nagle; for an interactive protocol, do. Match the socket options to the traffic, because the same default is wrong for one of the two. And remember that a large send buffer only helps if the application writes in large chunks; a server that writes a few bytes per system call cannot fill the window.
Measuring the Result
Change one setting at a time and measure throughput and latency before and after, because the settings interact and a change that helps throughput can hurt latency. Use a bulk transfer benchmark over the real path, not a loopback test, because the bandwidth-delay product of loopback is nothing like the real link. Compare the achieved throughput against the bandwidth-delay product to see whether the window is still the limit.
Watch for the signs that the window is the bottleneck: throughput multiplied by round-trip time roughly equals the window size, and the window sits at its maximum. If the received window is large but throughput is low, the congestion algorithm or the application’s write pattern is the limit, not the buffer. Measure to know which.
Conclusion
TCP throughput is bounded by how much data is in flight, which the window and the bandwidth-delay product determine. Raise the send and receive buffers so the window can grow, enable window scaling or the larger window cannot be advertised, and choose a congestion algorithm that fits the network path. Use TCP_NODELAY for interactive traffic and not for bulk, and write in large chunks so the application can fill the window. Change one setting at a time and measure over the real path, because the tuning that helps throughput can cost latency.
Sources: TCP congestion control, RFC 7323: TCP extensions for high performance, BPF BBR congestion control.
FAQ
- Why is throughput low on a high-latency link with plenty of bandwidth?
- The window limits how much data can be in flight, so throughput is roughly the window divided by the round-trip time. On a link with a large bandwidth-delay product, the default window is too small; raise the buffers and enable window scaling.
- When should TCP_NODELAY be enabled?
- For latency-sensitive interactive protocols, to avoid Nagle delaying small writes for coalescing. For bulk transfer, leave it off, because coalescing many small writes into fewer segments is beneficial. Match the option to the traffic type.
Report a problem with this articleOpens a pre-filled issue on GitHub.