User:Ant P./Traffic shaping with sch-cake

From Gentoo Wiki
Jump to: navigation, search
Warning
This page is a work in progress by Ant P. (talk | contribs). Treat its contents with caution.

The Cake scheduler was added to Linux 4.19 with an explicit goal of obsoleting traditional traffic shaping scripts.

Installation

Kernel 4.19 and sys-apps/iproute2 4.19.0 or greater is required.

KERNEL Enable sch_cake
[*] Networking support  --->
    Networking options  --->
        [*] QoS and/or fair queueing  ---> 
            <M/*>   Common Applications Kept Enhanced (CAKE)

Configuration

The scheduler has a few command-line options (documented in tc-cake); the most important is the 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.

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):

FILE /etc/local.d/00_net_tc.start
#!/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.

Testing

Cake produces some very detailed statistics; try generating some traffic with this running:

user $watch tc -s qdisc show

For internet testing, the DSLReports speed test is very useful as it also measures bufferbloat.