User:Ant P./Traffic shaping with sch-cake
This page provides a quick start guide to using the Cake network scheduler. Cake was added in Linux 4.19 with an explicit goal of obsoleting traditional traffic shaping scripts.
Kernel 4.19 and sys-apps/iproute2 4.19.0 or greater is required.
[*] Networking support ---> Networking options ---> [*] QoS and/or fair queueing ---> <M/*> Common Applications Kept Enhanced (CAKE)
The scheduler has a few command-line options (documented in bandwidth option. Setting this to match the advertised upload bandwidth of a network interface will eliminate bufferbloat by limiting outgoing packets to approximately that speed. This will keep ping times stable under load, but it can also have the counter-intuitive effect of increasing both upload and download bandwidth due to TCP's sensitivity to congestion.); the most important is the
Here is a real world example, started via /etc/init.d/local, for a router with three network interfaces; gigabit Ethernet, 802.11n Wi-Fi and slow ADSL (via a modem on an Ethernet VLAN, but this works for direct WAN connections also):
#!/sbin/tc -batch qdisc replace root dev eth0 cake bandwidth 1gbit ethernet lan diffserv4 qdisc replace root dev wlan0 cake bandwidth 135mbit ethernet metro diffserv4 qdisc replace root dev wan0 cake bandwidth 830kbit pppoa-llc internet diffserv4 nat
Here, the ethernet and pppoa-llc keywords are used to specify the framing overhead of the bottleneck in the connection, after the raw bandwidth is accounted for. If your external modem/router supports UPnP, the upnpc -s command (from net-libs/miniupnpc) can query its exact upload bitrate, which is 830kbit in this example.
The remainder is safe to omit but still useful: lan, metro and internet keywords are shorthands for round-trip times of 1ms, 10ms and 100ms respectively (note that the Cake manpage recommends against using lan for Wi-Fi). diffserv4 and nat are used to fine-tune fairness between multiple traffic flows.
Cake produces some very detailed statistics; try generating some traffic with this running:
watch tc -s qdisc show
For internet testing, the DSLReports speed test is very useful as it also measures bufferbloat.