Many tuning lists online are copied from one another and include settings that do nothing or were removed from the kernel years ago. This is a short list that has a measurable effect on servers that send a lot of video over TCP, with the reason for each line.
The settings
Create /etc/sysctl.d/90-streaming.conf:
# Congestion control
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
# Do not shrink the sending window after a short pause
net.ipv4.tcp_slow_start_after_idle = 0
# Cope with paths that drop large packets silently
net.ipv4.tcp_mtu_probing = 1
# Accept queues for many simultaneous connections
net.core.somaxconn = 4096
net.ipv4.tcp_max_syn_backlog = 8192
net.core.netdev_max_backlog = 5000
# More local ports for outgoing connections to origins
net.ipv4.ip_local_port_range = 10240 65535
# Larger buffer ceilings; the kernel still sizes them automatically
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
# File handles
fs.file-max = 1000000
Apply and verify:
sudo sysctl --system
sysctl net.ipv4.tcp_congestion_control
If the second command does not answer bbr, load the module and make it permanent:
sudo modprobe tcp_bbr
echo tcp_bbr | sudo tee /etc/modules-load.d/bbr.conf
Why each group is there
BBR with fq. The default congestion control backs off hard on every lost packet. On long or lossy paths, which is most home and mobile connections, that means a lower and less steady delivery rate. BBR estimates the real capacity of the path instead. For video this is usually the single biggest improvement, and it needs no change on the viewer’s side.
tcp_slow_start_after_idle = 0. HLS delivery is bursty: a segment, a pause, a segment. By default the kernel treats each pause as a reason to start slowly again. Turning that off keeps the connection at speed between segments.
tcp_mtu_probing = 1. Some networks drop large packets without telling the sender. The symptom is a connection that opens and then hangs. Probing lets the kernel find a size that gets through.
Queues. somaxconn and tcp_max_syn_backlog decide how many new connections can wait while your server is busy. If they are too small, viewers get refused during a rush, for example when a match starts. Your web server has its own limit too: in Nginx it is the backlog parameter of listen.
Buffers. The three numbers are minimum, default and maximum. Only the maximum is raised here. The kernel grows a buffer only when the connection needs it, so this costs memory only on fast, long-distance connections.
File descriptors are a separate limit
Every connection is a file descriptor. Raise the limit for the service itself, because fs.file-max is only the system-wide ceiling.
For a systemd service: LimitNOFILE=65536 in the unit.
For Nginx:
worker_rlimit_nofile 65536;
events { worker_connections 16384; }
What not to copy from old guides
net.ipv4.tcp_tw_recycle: removed from the kernel in version 4.12. It broke connections for users behind shared addresses.- Setting buffer defaults very high: this makes every connection use that much memory, including idle ones.
- Disabling TCP timestamps or selective acknowledgements: both help performance and are needed by BBR and by loss recovery.
Measure before and after
Change one group at a time and compare under real load.
ss -ti | grep -E 'bbr|cubic' | head
nstat -az TcpRetransSegs TcpExtListenOverflows TcpExtListenDrops
ss -tishows the congestion control and delivery rate per connection.TcpExtListenOverflowsandTcpExtListenDropsrising means the accept queue is too small.TcpRetransSegsdivided by sent segments gives the retransmission rate. Above 2 to 3 percent, look at the network path before touching more settings.
If a change makes no difference in these numbers or in what viewers report, remove it. A short configuration you understand is worth more than a long one you copied.