Skip to content

SQM and CAKE: stop lag under download and upload

  • Decide whether “lag while downloading/uploading” is bufferbloat, rather than Wi-Fi, ONT, or ISP congestion.
  • Install and configure sqm-scripts and 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.
  • OpenWrt 25.12.6 with apk; sqm-scripts 1.7.2; optional luci-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.

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.
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”.

Router shellRecord WAN, CPU and current qdisc
Terminal window
ip -br link
ip -br addr
uci show network | grep -E "wan|device"
uci show sqm 2>/dev/null || echo "sqm not installed"
top -bn1 | head -15

Write 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.

Router shellTake an idle baseline
Terminal window
ping -c 20 1.1.1.1
ping -c 20 192.168.50.1

Use irtt/flent if available; otherwise record min/avg/max/mdev and loss.

ExpectedIdle latency/loss is recorded for comparison.

Router shellInstall SQM
Terminal window
apk update
apk add sqm-scripts luci-app-sqm

luci-app-sqm alone does not install the scripts; verify with apk info -e sqm-scripts.

Expectedsqm-scripts and the LuCI app are installed.

LuCIConfigure SQM in LuCI

Open Network → SQM QoS:

  1. Enable it.
  2. Select wan (not br-lan).
  3. Set download/upload to 85%–95% of measured throughput.
  4. Choose cake and piece_of_cake.qos.
  5. Select the real link layer (do not copy Ethernet values on PPPoE/VLAN).
  6. Save and apply.

Start conservatively; raise the rate only after latency improves.

ExpectedWAN has cake/piece_of_cake and can be enabled/disabled.

Router shellCLI equivalent (inspect the section name first)
Terminal window
uci show sqm

The section may not be @queue[0]; use the real name. Example:

Terminal window
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 restart

These numbers are examples, not your line parameters; verify linklayer/overhead.

Expecteduci show sqm shows the queue you changed.

Router shellConfirm the qdisc is attached
Terminal window
tc -s qdisc show dev wan
tc -s qdisc show | grep -E "cake|fq_codel|ifb"
logread -e sqm | tail -30

If 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.

ComputerMeasure latency under download/upload

Keep a ping running while another terminal saturates the line:

Terminal window
# terminal A
ping -i 0.2 1.1.1.1
# terminal B: use a trusted speed/download tool to saturate the line

Record:

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

Terminal window
logread -e sqm | tail -50
tc -s qdisc show dev wan
uci show sqm

Common causes: wrong interface, missing sqm-scripts, unsupported qdisc/script combination, tc errors. Disable SQM and restore the previous state before debugging.

  • Rate set too low: raise it in steps from the measured value.
  • CAKE too costly on a weak CPU: use fq_codel or a lower rate.
  • Wrong link overhead: correct it for PPPoE/VLAN.
  • Disable SQM and confirm throughput returns.
  • 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.
Terminal window
uci set sqm.@queue[0].enabled='0'
uci commit sqm
/etc/init.d/sqm restart

Or restore the previous /etc/config/sqm backup.

  • Environment: OpenWrt 25.12.6 x86 VM 200; WAN eth1 DHCP 192.168.50.158/24; sqm-scripts 1.7.2-r1, luci-app-sqm.
  • Config: eth1, download 100000 Kbps, upload 20000 Kbps, piece_of_cake.qos, cake.
  • Start: SQM: ... started on eth1 successfully; tc -s qdisc show dev eth1 showed qdisc cake ... bandwidth 20Mbit.
  • Stop: SQM: Stopping SQM on eth1; qdisc returned to fq_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.
  • 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

Router.Homes

Independent OpenWrt notes. Every page states the firmware, device, package manager and way back.

Icons: Solar by 480 Design, CC BY 4.0