Operators describe a slow link with words that do not survive measurement: "it feels sticky", "SSH hangs for a second", "the dashboard freezes". Our case was an edge relay pair sitting between a factory network and a remote-support gateway. One relay ran on a 1 vCPU / 1 GB Guangzhou VM behind carrier NAT; the other terminated several TCP relays on a Hong Kong BGP host. Interactive sessions were fine most of the day, then a historian upload or a remote-support file transfer would start and every session on the box would stall for a few seconds.
The link was not obviously broken. Round-trip time to the gateway was 3.8 ms with 0.02 ms jitter, path MTU 1500 passed end to end, and ICMP showed zero loss over 50 probes. Everything a monitoring dashboard shows was green.
That is the point where most tuning sessions go wrong: a green dashboard invites sysctl guessing. The actual faults were three, and only one of them was a kernel parameter.
Why "ping is fine" proves almost nothing
A 64-byte ICMP echo does not fill a queue, does not trigger a traffic policer for long enough to drop anything, and is frequently handled on a different priority path than bulk TCP. It measures reachability and propagation delay, nothing else. In our case it was actively misleading:
- ICMP loss was 0%, while the same path dropped 28% of a 250 Mbit/s UDP stream.
ssshowed listening sockets whose accept queue was one sixteenth of the configured limit.- TCP retransmitted thousands of segments per ten-second transfer while the NIC reported zero drops.
Each of those is invisible to a ping chart and each of them has a different owner: carrier, kernel, application.
Measure the path before changing a single sysctl
The order matters. First establish the path ceiling with UDP, because TCP hides loss behind retransmission and congestion-window collapse. Then measure TCP to see what the stack actually achieves. Only then look at counters.
# 1. Path quality: latency, jitter, MTU
ping -c 50 -i 0.2 203.0.113.10
ping -c 2 -M do -s 1472 203.0.113.10
# 2. Ceiling sweep: UDP shows loss the moment a policer engages
for rate in 100 150 200 250 350; do
iperf3 -c 203.0.113.10 -p 13845 -u -b ${rate}M -t 10
done
# 3. What TCP really delivers, one stream and reverse
iperf3 -c 203.0.113.10 -p 13845 -t 10
iperf3 -c 203.0.113.10 -p 13845 -t 10 -R
# 4. Counters: loss, retransmission, listening queue depth
ss -ltn
tc -s qdisc show dev ens5
nstat -az | grep -Ei 'retrans|timewait|listen|ofo|dsack'
The UDP sweep is the single most useful command in this whole article. TCP at 209 Mbit/s looked acceptable; the UDP sweep showed the path was already shedding 28% of the offered load at 250 Mbit/s.
What the counters actually showed
Every datapoint below is from the same pair of hosts, roughly fifteen minutes apart, with no other traffic on the relay.

| Test | Offered | Delivered | Loss | Interpretation |
|---|---|---|---|---|
| ICMP, 50 probes | 64 B | 64 B | 0% | Path is reachable, nothing more |
| Path MTU probe, DF bit | 1472 B | 1472 B | 0% | No fragmentation black hole |
| UDP 10 s | 100 Mbit/s | 100 Mbit/s | 0% | Path is clean below the ceiling |
| UDP 10 s | 200 Mbit/s | 199 Mbit/s | under 1% | Still clean |
| UDP 10 s | 250 Mbit/s | 179 Mbit/s | 28% | A policer is active |
| UDP 10 s | 350 Mbit/s | 174 Mbit/s | 50% | Hard ceiling near 200 Mbit/s |
| TCP one stream | unthrottled | 209 Mbit/s | 14,000 retransmits in 8 s | Stack fighting the ceiling |
| TCP reverse | unthrottled | 407 Mbit/s | thousands of retransmits | Asymmetric policing |
Two counter groups decided the diagnosis. First, the local queue was innocent: tc -s qdisc showed a few thousand drops accumulated across 149 GB, and the NIC drop counters were zero. Second, the loss was real and not a reordering artefact:
TCPOFOQueuestayed at 0 andDSACKRecvat 2, so the receiver was not merely seeing out-of-order delivery.TCPLostRetransmitreached 4,721, meaning even the retransmissions were being discarded.- The peer's own retransmit counter was about twelve times lower than ours, which places the loss on our egress, downstream of the NIC.
That combination — clean MTU, zero local drops, real loss on retransmissions, and a stable 3.8 ms RTT — is the signature of a rate policer in the provider path, not of congestion, bufferbloat, or a misconfigured interface.
The trap: every rate-bearing qdisc replaces the pacing layer
The obvious next move is traffic shaping: queue the excess in our own qdisc instead of letting the carrier discard it. That is standard advice and it failed catastrophically here.
The relay ran BBR on a virtio NIC with the root discipline set to fq. We replaced it with three different rate-bearing configurations, each time measuring with the same peer and the same ten-second iperf3 run:
| Root discipline | Uplink | Downlink | Limiter counters | Verdict |
|---|---|---|---|---|
fq (baseline) | 209 Mbit/s, later 122–239 Mbit/s | 407 Mbit/s | n/a | Works |
cake 185mbit diffserv4 | 1.05 Mbit/s | 24.9 Mbit/s | dropped near 0 | Collapsed |
cake 185mbit (plain) | 1.05 Mbit/s | 124 Mbit/s | overlimits 1,498, dropped 0 | Collapsed |
htb 185mbit + fq_codel leaf | 1.22 Mbit/s | 1.05 Mbit/s | overlimits 0, dropped 0 | Collapsed |
The instructive row is the last one. HTB reported overlimits 0, meaning the shaper never actually had to throttle anything — the connection was already at 1.22 Mbit/s, far below its 185 Mbit/s ceiling. The collapse therefore was not the limiter doing its job correctly, nor a misconfigured burst size, nor a queue too small for BBR's bandwidth-delay product.
Two mechanisms explain what we saw, and both are worth checking before you copy a shaping recipe from a blog post:
- Pacing dependency. BBR paces packets through the qdisc's pacing hooks.
fqis where that pacing is realised per flow. A classful qdisc without equivalent pacing support turns a smooth 200 Mbit/s pacing schedule into bursts that the carrier policer discards, and TCP collapses. - Lost multi-queue fan-out. On a multi-queue virtio device the stack ships with an
mqroot and one child qdisc per TX queue. A single-rootcakeorhtbfunnels every flow through one lock and one queue pair, which on a small 1 vCPU instance is enough to serialise the sender.
We rolled back within the same hour. A tenth of the throughput is worse than an impolite carrier policer, and no sysctl can repair a bad queue topology.
There is also a persistence trap that outlives the experiment. net.core.default_qdisc only applies to newly created devices; it does not rewrite a qdisc that already exists. Worse, a forgotten post-up line in /etc/network/interfaces can silently restore fq_codel on the next reboot or interface bounce, quietly removing the pacing layer months after you fixed it. Verify with tc qdisc show, not with sysctl net.core.default_qdisc.
Stale listen backlogs: the 4096 nobody notices
The second fault had nothing to do with bandwidth. Both relays accepted connections slowly during reconnect storms, and the reason was a listening socket that was older than the configuration meant to improve it.
net.core.somaxconn was already 65535 on both hosts. The listening sockets were not:
State Recv-Q Send-Q Local Address:Port
LISTEN 0 4096 0.0.0.0:10801
LISTEN 0 511 0.0.0.0:80
Send-Q on a listening socket is the actual accept queue limit, frozen at the value in force when the socket was created. nginx had been reloaded several times since the sysctl was raised, but reload keeps the existing listen sockets; it only re-binds when the listen options themselves change. The master process was 43 days old, so every relay port still advertised 4096, and ListenDrops had accumulated 1,625 events.
Two config layers matter here:
| Layer | Setting | Applies when |
|---|---|---|
| Kernel | net.core.somaxconn = 65535 | Caps new listening sockets only |
| nginx stream | listen 10801 backlog=65535; | On socket creation or rebind |
| nginx http | listen 80 backlog=65535; | Defaults to 511 when unset |
The fix is not reload. It is systemctl restart nginx, which recreates the listening sockets and lets them inherit somaxconn. After the restart the same ss -ltn output read 65535 for every relay port and ListenDrops stopped increasing. For the HTTP listeners, adding backlog=65535 to the listen directive does rebind on reload, because the listen options changed.
This is the cheapest performance fix in the entire article and it is invisible unless you look at Send-Q instead of somaxconn.
Which sysctls actually mattered
With the path characterised and the queue topology left alone, the kernel tuning shrank to a short list. Everything below was verified after sysctl --system.
| Parameter | Before | After | Effect observed |
|---|---|---|---|
net.ipv4.tcp_max_tw_buckets | 30000 | 65536 | Stops the kernel from killing TIME_WAIT entries during reconnect storms; overflow had been recorded 11,706 times |
net.ipv4.tcp_retries2 | 15 | 10 | Dead peers fail in about five minutes instead of fifteen |
net.ipv4.tcp_syn_retries | 6 | 4 | Unreachable backends fail over in about 15 s instead of 127 s |
net.ipv4.tcp_notsent_lowat | unset | 131072 | Less unsent data buffered per connection, lower tail latency on multiplexed tunnels |
vm.swappiness | 60 | 10 | No swap on these hosts; prevents future swap thrash |
Three popular changes did nothing measurable and are worth naming, because they are repeated endlessly in tuning guides:
- Raising
rmem_maxandwmem_maxdoes not help whentcp_rmemandtcp_wmemalready cap autotuning. The socket never grows past those limits. net.core.default_qdiscdoes not change an existing device. Onlytc qdisc replacedoes, and only until the next boot hook.somaxconnalone does nothing for a process that has not recreated its listening socket.
And one thing that looked like a bug but was not: the interface reported mq with an fq_codel child while default_qdisc said fq. That is expected on multi-queue NICs, where mq is the root and the per-queue child is inherited from default_qdisc at creation time.
A verification sequence worth keeping
Any change to queues, listen backlogs, or kernel network parameters should be followed by the same five checks. They take fifteen seconds and catch the mistakes above.
sysctl --system
nginx -t && nginx -s reload
ss -ltn | awk 'NR==1 || $4 ~ /:80$/ || $4 ~ /:1080[0-9]$/'
tc -s qdisc show dev ens5
nstat -az | grep -E 'ListenDrops|TCPTimeWaitOverflow|TCPLostRetransmit'
Read them in this order: does the kernel agree with the file, did nginx accept the config, did the listening sockets actually change, is the root discipline still the one you intended, and are the drop counters still moving. A change that leaves a counter climbing was not a fix.
What we changed, and what we did not
Applied:
- Replaced a
post-up tc qdisc replace ... fq_codelhook that would have silently removed the pacing layer on the next reboot. - Restarted nginx so stale listen sockets inherited
somaxconn, and addedbacklog=65535to the HTTP listeners. - Raised
tcp_max_tw_bucketsto 65536 on the hosts that had recorded TIME_WAIT overflow. - Shortened
tcp_retries2andtcp_syn_retriesso failed backends stop holding sessions open.
Deliberately not applied:
- No qdisc shaping on the virtio hosts. The measured collapse outweighs the theoretical benefit of local queuing, and the real ceiling belongs to the provider.
- No nginx
limit_rate. Both sites served API and reverse-proxy traffic only; there was no large-file location to throttle, so a global limit would have slowed normal requests. - No
rsync --bwlimitstill, because rsync is not installed. When bulk transfers are added, that is where they should be capped, at the application layer, not by breaking the qdisc under BBR.
The remaining asymmetry — a hard policer near 200 Mbit/s on egress — cannot be fixed from inside the guest. It can only be measured, reported to the provider, and routed around. For factory-side remote support over such a link, that means keeping interactive traffic and bulk historian uploads on separate paths where possible, and treating "fits in a 150 Mbit/s budget" as the design assumption rather than the headline bandwidth.
If you maintain industrial edge nodes, the transferable lesson is that kernel networking counters and queue depth deserve the same attention as cable diagnostics. A CRC counter on a switch port tells you the physical layer is unhappy; a ListenDrops counter and a Send-Q of 4096 tell you the application layer is.



