Little background

You are downloading a large file on your computer, and it's putting so much stress on the bandwidth that you can't even open a webpage on any other device on that network. - Have you been in a situation like that? It's called Bufferbloat.

Bufferboat has long been one of the most common problems of any shared network. There have been numerous attempts at mitigating Bufferbloat, but most of these are for corporate-grade networks and are proprietary. Consumer-grade and SOHO routers have historically been notorious for their bad bandwidth management, and most SOHO routers don't come with a Bufferbloat solution set-up. Those that come with one have interfaces that will put 90's systems to shame.

OpenWRT has a package called SQM QoS for Bufferbloat mitigation. If you are someone like me who likes to set up his router once and then keeps running 24x7x365 without any interaction, then it might be the savior for you. I have been using this for the last several months without a single reboot of my router, and to my surprise, my SOHO router still runs like a champ.
SQM QoS is a very lightweight package. It also has an optional Luci (GUI) module that can provide an easy configuration page for the SQM QoS package.

In this post, I will install both the SQM QoS core package and SQM QoS Luci package. I will also install any dependency it might have. Then I will install and configure SQM QoS so it works with your network interface.

I will use a TP-LINK MR3420 V2 router with OpenWRT 15.05.1 installed, but anything with a recent OpenWRT version should work.

Installing the packages

Via SSH

First, we will need to login to our router's SSH (Dropbear) interface. I assume you already know this step.
After logging in, run the following command to locate and install the SQM core package with an OpenWRT interface.

opkg update; opkg install luci-app-sqm

If you don't want luci interface, run this instead:
opkg update; opkg install sqm-scripts

Via Luci

Go to System --> Software tab.

2018-05-22-01_42_17

Now in that Download and install package field, type luci-app-sqm and click OK. It should show a confirmation message.

Configuring SQM QoS

Via Luci

Configuring SQM QoS is super easy with Luci.

First, go the Network --> SQM QoS page.

2018-05-22-01_50_33

Now make the following adjustments to the Basic Settings tab:

  • Interface Name: You should select your WAN or Modem network interface (Usually br-wan or eth2, but YMMV). Please don't select your LAN network.
  • Download Speed: Go to Speedtest.net and run a speedtest of your network. Note down the Upload Speed and Download Speed. Download speed on SQM should be a rough 90-95% of your Speedtest.net result.
  • Upload Speed: 90-95% of Speedtest.net result.

2018-05-22-01_49_44

Now go to the Queue Discipline tab. Make these adjustments:

  • Queue setup script: piece_of_cake.qos

Everything else should be the default.

Now click Save & Apply.

Via SSH

Run the following lines. Make sure to configure the commented lines.

/etc/init.d/sqm enable
/etc/init.d/sqm start
#/etc/init.d/sqm restart
# check logs just in case:
logread
# check defaults and backup them
cat /etc/config/sqm
cp /etc/config/sqm > etc-config-sqm.bak

# example, 30Mb download, 3Mb upload
WAN_NAME='wan'
WAN_IFACE=`uci get network.wan.ifname`
BW_DOWN='30'; BW_UP='3'

uci del sqm.eth1

# important config
uci set sqm.$WAN_NAME='queue'
uci set sqm.$WAN_NAME.interface=$WAN_IFACE # wan, Default 'eth1' (Interface de WAN)
uci set sqm.$WAN_NAME.download=$(($BW_DOWN*1000*85/100)) # 95% of speedtest, 85% isp
uci set sqm.$WAN_NAME.upload=$(($BW_UP*1000*85/100))
# the rest:
uci set sqm.$WAN_NAME.qdisc='fq_codel' # Default 'fq_codel'
uci set sqm.$WAN_NAME.script='simple.qos' # Default 'simple.qos'
uci set sqm.$WAN_NAME.linklayer='none' # Default 'none'
uci set sqm.$WAN_NAME.qdisc_advanced='0' # Default '0'
#uci set sqm.$WAN_NAME.ingress_ecn='ECN' # Default 'ECN'
#uci set sqm.$WAN_NAME.egress_ecn='ECN' # Default 'ECN', docs stats NOECN: At low bandwidth, we recommend that you turn ECN off for the Upload (outbound, egress) direction
#uci set sqm.$WAN_NAME.qdisc_really_really_advanced='0' # Default 0
#uci set sqm.$WAN_NAME.itarget='auto' # Default 'auto'
#uci set sqm.$WAN_NAME.etarget='auto' # Default 'auto'
#uci set sqm.$WAN_NAME.overhead='0' # Default '0' # docs says for ADSL use: '44'
# Default when using luci:
uci set sqm.$WAN_NAME.verbosity='5' # Default luci 'auto'
uci set sqm.$WAN_NAME.debug_logging='0' # Default luci 'auto'
# enable it:
uci set sqm.$WAN_NAME.enabled='1' # Default luci 'auto'

/etc/init.d/sqm restart

That's it! You are now all set to enjoy a Bufferbloat-free internet experience.