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.
  • ss showed 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.

Engineering diagram comparing uplink throughput for fq, cake and htb queue disciplines next to listening socket backlog before and after an nginx restart
Figure 1: The rate-bearing qdiscs never reached their configured limit, and the accept queue only changed after the listening socket was recreated.

TestOfferedDeliveredLossInterpretation
ICMP, 50 probes64 B64 B0%Path is reachable, nothing more
Path MTU probe, DF bit1472 B1472 B0%No fragmentation black hole
UDP 10 s100 Mbit/s100 Mbit/s0%Path is clean below the ceiling
UDP 10 s200 Mbit/s199 Mbit/sunder 1%Still clean
UDP 10 s250 Mbit/s179 Mbit/s28%A policer is active
UDP 10 s350 Mbit/s174 Mbit/s50%Hard ceiling near 200 Mbit/s
TCP one streamunthrottled209 Mbit/s14,000 retransmits in 8 sStack fighting the ceiling
TCP reverseunthrottled407 Mbit/sthousands of retransmitsAsymmetric 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:

  • TCPOFOQueue stayed at 0 and DSACKRecv at 2, so the receiver was not merely seeing out-of-order delivery.
  • TCPLostRetransmit reached 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 disciplineUplinkDownlinkLimiter countersVerdict
fq (baseline)209 Mbit/s, later 122–239 Mbit/s407 Mbit/sn/aWorks
cake 185mbit diffserv41.05 Mbit/s24.9 Mbit/sdropped near 0Collapsed
cake 185mbit (plain)1.05 Mbit/s124 Mbit/soverlimits 1,498, dropped 0Collapsed
htb 185mbit + fq_codel leaf1.22 Mbit/s1.05 Mbit/soverlimits 0, dropped 0Collapsed

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:

  1. Pacing dependency. BBR paces packets through the qdisc's pacing hooks. fq is 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.
  2. Lost multi-queue fan-out. On a multi-queue virtio device the stack ships with an mq root and one child qdisc per TX queue. A single-root cake or htb funnels 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:

LayerSettingApplies when
Kernelnet.core.somaxconn = 65535Caps new listening sockets only
nginx streamlisten 10801 backlog=65535;On socket creation or rebind
nginx httplisten 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.

ParameterBeforeAfterEffect observed
net.ipv4.tcp_max_tw_buckets3000065536Stops the kernel from killing TIME_WAIT entries during reconnect storms; overflow had been recorded 11,706 times
net.ipv4.tcp_retries21510Dead peers fail in about five minutes instead of fifteen
net.ipv4.tcp_syn_retries64Unreachable backends fail over in about 15 s instead of 127 s
net.ipv4.tcp_notsent_lowatunset131072Less unsent data buffered per connection, lower tail latency on multiplexed tunnels
vm.swappiness6010No 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_max and wmem_max does not help when tcp_rmem and tcp_wmem already cap autotuning. The socket never grows past those limits.
  • net.core.default_qdisc does not change an existing device. Only tc qdisc replace does, and only until the next boot hook.
  • somaxconn alone 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:

  1. Replaced a post-up tc qdisc replace ... fq_codel hook that would have silently removed the pacing layer on the next reboot.
  2. Restarted nginx so stale listen sockets inherited somaxconn, and added backlog=65535 to the HTTP listeners.
  3. Raised tcp_max_tw_buckets to 65536 on the hosts that had recorded TIME_WAIT overflow.
  4. Shortened tcp_retries2 and tcp_syn_retries so 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 --bwlimit still, 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.