A few things, mostly technical notes...

Sunday, January 13, 2019

Controlling bufferbloat on a raspberry pi router

I've a raspberry pi 3b+ acting as my home router.

I noticed that I've severe Bufferbloat, according to tests performed at http://www.dslreports.com/speedtest.

Below is a script that I used to improve my Bufferbloat issue.

Using the FQ_Codel (Fair Queuing Controlled Delay) AQM algorithm, I could control the Bufferbloat issue.  FQ_Codel uses a stochastic  (randomly determined) model to classify incoming packets into different flows and  is used  to  provide  a fair share of the bandwidth to all the flows using  the queue. Each such flow is managed by the CoDel  queuing  discipline.  Reordering  within a flow is avoided since Codel internally uses a FIFO  queue.

All we need to know is what's the theoretical maximum outbound speed, and the interface to control - ext_up and ext. Here, eth1 is my interface that is connected to the cable modem, my upload is capped at a puny 5mbps, thanks to my predatory ISP. 

shaper.sh

#!/bin/bash 
# evuraan at gmail - 
# Freely given - use at your own risk!

# Also see: https://wiki.gentoo.org/wiki/Traffic_shaping

ext="eth1"
ext_up="5000kbit" # Max theoretical

tc="/sbin/tc"

q="1514"                # HTB Quantum = 1500bytes IP + 14 bytes ethernet.
quantum="300"  # fq_codel quantum 300 gives a boost to interactive flows
modprobe ifb
modprobe sch_fq_codel

#########
# EGRESS
#########
# Add FQ_CODEL to EGRESS on external interface
$tc qdisc add dev $ext root handle 1: htb default 11
$tc class add dev $ext parent 1: classid 1:1 htb rate $ext_up
$tc class add dev $ext parent 1:1 classid 1:11 htb rate $ext_up prio 0 quantum $q
$tc qdisc add dev $ext parent 1:11 fq_codel quantum $quantum noecn

I would run this from /etc/crontab as soon as the pi reboots:

# grep shaper /etc/crontab
@reboot  root /home/code/shaper.sh  1>/dev/null 2>/dev/null || :

The results has been remarkable:

https://dfkrkqaqb1zsx.cloudfront.net/speedtest/cdn/44540652.png



I could significantly improve my bufferbloat situation with this small script. I hope someone else finds good use of this article. 

The future holds CAKE!

In the future this will get even more easier, as Linux 4.19 comes with new queuing discipline for the network packet scheduler called cake (Common Applications Kept Enhanced.)

With cake, AQM become much easier:


modprobe sch_cake
modprobe act_mirred
tc qdisc add dev eth2 root cake bandwidth XXmbit # where XX is your mbit. You can do kbit also. substitute your outbound interface for eth2.

References: 

Recommended LWN article: Let them run CAKE
 Project page: https://www.bufferbloat.net/projects/codel/wiki/Cake/

Followers


Creative Commons License
This work is licensed under a Creative Commons License.