SQM and CAKE: stop lag under download and upload
Outcome
Section titled “Outcome”- Decide whether “lag while downloading/uploading” is bufferbloat, rather than Wi-Fi, ONT, or ISP congestion.
- Install and configure
sqm-scriptsand CAKE on OpenWrt 25.12. - Record idle vs loaded latency, loss and throughput instead of claiming “it feels faster”.
- Know when SQM is the wrong tool, and how to turn it off quickly.
Applicable environment
Section titled “Applicable environment”- OpenWrt 25.12.6 with
apk;sqm-scripts 1.7.2; optionalluci-app-sqm. - The router is the main NAT gateway and WAN traffic passes through it. On an AP/bypass router, SQM may not see the main traffic.
- CAKE costs CPU; on gigabit lines check single-core usage before adding shaping.
- This page is E2 partial: install and CAKE attach/stop were tested. Throughput/latency claims need a real WAN and are E3.
Is it bufferbloat?
Section titled “Is it bufferbloat?”Typical signs:
- Idle ping is fine, but latency spikes as soon as a download/upload starts; games jump, calls stutter.
- Capping download/upload makes latency fall again.
- The same happens on wired and Wi-Fi clients, pointing to the WAN queue.
Not bufferbloat:
- Only one room/client on Wi-Fi is bad: check signal, interference, roaming.
- High latency/loss even when idle: check ONT, ISP, line.
- Router CPU is already saturated; SQM may make it worse.
Key parameters
Section titled “Key parameters”| Parameter | Meaning | Common mistake |
|---|---|---|
interface |
interface to shape, usually wan |
using eth0/br-lan so traffic bypasses it |
download/upload |
shaped rate (kbit/s) | using the advertised plan rate, keeping the queue full |
qdisc |
cake or fq_codel |
enabling SQM but leaving the default qdisc |
script |
piece_of_cake.qos / simplest.qos |
wrong script, options do not apply |
linklayer/overhead |
link-layer overhead | copying Ethernet values on PPPoE/VLAN |
| CPU | CAKE compute cost | gigabit CAKE on a CPU that cannot keep up |
Start at 85%–95% of measured throughput, then tune from loaded latency. Do not put “100M plan = 100000”.
Before you change anything
Section titled “Before you change anything”ip -br linkip -br addruci show network | grep -E "wan|device"uci show sqm 2>/dev/null || echo "sqm not installed"top -bn1 | head -15Write down the WAN logical interface, physical device, plan/measured rate and CPU model. Keep LuCI/SSH access.
ExpectedYou know which interface you are changing and whether SQM is already active.
ping -c 20 1.1.1.1ping -c 20 192.168.50.1Use irtt/flent if available; otherwise record min/avg/max/mdev and loss.
ExpectedIdle latency/loss is recorded for comparison.
Minimal steps
Section titled “Minimal steps”apk updateapk add sqm-scripts luci-app-sqmluci-app-sqm alone does not install the scripts; verify with apk info -e sqm-scripts.
Expectedsqm-scripts and the LuCI app are installed.
Open Network → SQM QoS:
- Enable it.
- Select
wan(notbr-lan). - Set download/upload to 85%–95% of measured throughput.
- Choose
cakeandpiece_of_cake.qos. - Select the real link layer (do not copy Ethernet values on PPPoE/VLAN).
- Save and apply.
Start conservatively; raise the rate only after latency improves.
ExpectedWAN has cake/piece_of_cake and can be enabled/disabled.
uci show sqmThe section may not be @queue[0]; use the real name. Example:
uci set sqm.@queue[0].enabled='1'uci set sqm.@queue[0].interface='wan'uci set sqm.@queue[0].download='90000'uci set sqm.@queue[0].upload='18000'uci set sqm.@queue[0].qdisc='cake'uci set sqm.@queue[0].script='piece_of_cake.qos'uci set sqm.@queue[0].linklayer='ethernet'uci set sqm.@queue[0].overhead='0'uci commit sqm/etc/init.d/sqm restartThese numbers are examples, not your line parameters; verify linklayer/overhead.
Expecteduci show sqm shows the queue you changed.
tc -s qdisc show dev wantc -s qdisc show | grep -E "cake|fq_codel|ifb"logread -e sqm | tail -30If you only see noqueue/pfifo_fast, SQM is not active; check the interface and /etc/init.d/sqm logs.
Expectedcake/fq_codel appears on wan and the log is clean.
Loaded verification
Section titled “Loaded verification”Keep a ping running while another terminal saturates the line:
# terminal Aping -i 0.2 1.1.1.1
# terminal B: use a trusted speed/download tool to saturate the lineRecord:
- idle vs loaded min/avg/max/mdev;
- loss;
- whether throughput dropped significantly;
- whether one router CPU core is saturated.
Without this data, do not write “SQM reduced latency”.
ExpectedYou have before/after data, not a feeling.
Failure branches and recovery
Section titled “Failure branches and recovery”SQM does not start / no qdisc
Section titled “SQM does not start / no qdisc”logread -e sqm | tail -50tc -s qdisc show dev wanuci show sqmCommon causes: wrong interface, missing sqm-scripts, unsupported qdisc/script combination, tc errors. Disable SQM and restore the previous state before debugging.
Throughput collapses / CPU saturates
Section titled “Throughput collapses / CPU saturates”- Rate set too low: raise it in steps from the measured value.
- CAKE too costly on a weak CPU: use
fq_codelor a lower rate. - Wrong link overhead: correct it for PPPoE/VLAN.
- Disable SQM and confirm throughput returns.
No effect
Section titled “No effect”- Traffic bypasses the router (AP/bypass/switch).
- The bottleneck is Wi-Fi or ISP congestion.
- Only download is shaped; upload is still congested.
- You measured idle latency, not loaded latency.
Quick disable
Section titled “Quick disable”uci set sqm.@queue[0].enabled='0'uci commit sqm/etc/init.d/sqm restartOr restore the previous /etc/config/sqm backup.
E2 lab run (2026-10-20)
Section titled “E2 lab run (2026-10-20)”- Environment: OpenWrt 25.12.6 x86 VM 200; WAN
eth1DHCP192.168.50.158/24;sqm-scripts 1.7.2-r1,luci-app-sqm. - Config:
eth1, download100000 Kbps, upload20000 Kbps,piece_of_cake.qos,cake. - Start:
SQM: ... started on eth1 successfully;tc -s qdisc show dev eth1showedqdisc cake ... bandwidth 20Mbit. - Stop:
SQM: Stopping SQM on eth1; qdisc returned tofq_codel. - Do not use these VM numbers to claim lower latency/better experience; no real line, load latency or throughput comparison.
- Not tested: real broadband bufferbloat before/after, CPU single-core use, PPPoE/VLAN overhead, Wi-Fi bottleneck.
- Recipe:
tests/recipes/sqm-25.12.md.
E2 status and sources
Section titled “E2 status and sources”- This is E2 partial: install, CAKE attach/stop and recovery were tested; real-line performance remains E3 scope.
- A VM only proves commands/qdisc attach; it cannot represent home broadband. Do not use VM numbers to claim “it works”.
- In a real environment, record line/CPU/qdisc, idle/load latency and throughput before deciding to keep SQM.
Sources
Independent OpenWrt notes. Every page states the firmware, device, package manager and way back.
Icons: Solar by 480 Design, CC BY 4.0