Reduce internet lag on OpenWRT

How to reduce internet lag on OpenWRT when there is heavy download/upload activity on the same internet connection.

Motivation

When there is heavy download/upload activity going on in my home network, latency spikes. This effect is felt when playing real-time online games where latency could cause a very unpleasant lag experience.

For example, I ran a continuous ping against Google DNS and then started Speedtest. Take a look at the spike in latency. This is on a 100Mbps/50Mbps download/upload link:

64 bytes from 8.8.8.8: seq=10 ttl=124 time=3.321 ms
64 bytes from 8.8.8.8: seq=11 ttl=124 time=3.488 ms
64 bytes from 8.8.8.8: seq=12 ttl=124 time=3.539 ms
64 bytes from 8.8.8.8: seq=13 ttl=124 time=24.593 ms
64 bytes from 8.8.8.8: seq=14 ttl=124 time=21.562 ms
64 bytes from 8.8.8.8: seq=15 ttl=124 time=50.528 ms
64 bytes from 8.8.8.8: seq=16 ttl=124 time=50.492 ms
64 bytes from 8.8.8.8: seq=17 ttl=124 time=48.279 ms
64 bytes from 8.8.8.8: seq=18 ttl=124 time=42.630 ms
64 bytes from 8.8.8.8: seq=19 ttl=124 time=53.913 ms
64 bytes from 8.8.8.8: seq=20 ttl=124 time=40.759 ms
64 bytes from 8.8.8.8: seq=21 ttl=124 time=29.398 ms
64 bytes from 8.8.8.8: seq=22 ttl=124 time=17.992 ms
64 bytes from 8.8.8.8: seq=23 ttl=124 time=23.571 ms
64 bytes from 8.8.8.8: seq=24 ttl=124 time=5.479 ms
64 bytes from 8.8.8.8: seq=25 ttl=124 time=5.117 ms

There is an easy way to resolve this without needing to stop downloads/uploads.

Solution

Overview

I installed Smart Queue Management (SQM). With minimal configuration, ping times spiked to no more than 11 milliseconds while running speed test.

Measure current speed

Before tweaking settings, obtain a baseline top download/upload speed via speed test.

Setup

Install SQM packages:

opkg update
opkg install sqm-scripts luci-app-sqm

A new menu item should appear under Network called SQM QoS.

Check the Enable box.

Select your WAN interface, in my case it is named pppoe-wan.

For Queue Discipline, select cake and use piece_of_cake.qos queue setup script.

For Link Layer Adaptation, the SQM guide on OpenWRT suggests the following (as at 2018-08-11):

  • For VDSL - Choose Ethernet, and set per packet overhead to 8
  • For DSL of any other type - Choose ATM, and set per packet overhead to 44
  • For Cable or other kinds of connections - Choose Ethernet, and set per packet overhead to 18

The download and upload speeds should be set to a figure between 80 and 95 percent of the maximum speed from the baseline obtained. Tweak the settings then conduct a speed test while running ping continuously to determine the maximum spike in latency until an reaching an acceptable threshold (determined by you). In my case, it is set to 90 percent. As you have figured, the trade-off is that top speed has now reduced.

Results

Here are the ping results with SQM enabled while running speed test:

64 bytes from 8.8.8.8: seq=11 ttl=124 time=3.504 ms
64 bytes from 8.8.8.8: seq=12 ttl=124 time=3.784 ms
64 bytes from 8.8.8.8: seq=13 ttl=124 time=8.375 ms
64 bytes from 8.8.8.8: seq=14 ttl=124 time=5.295 ms
64 bytes from 8.8.8.8: seq=15 ttl=124 time=9.399 ms
64 bytes from 8.8.8.8: seq=16 ttl=124 time=11.281 ms
64 bytes from 8.8.8.8: seq=17 ttl=124 time=8.722 ms
64 bytes from 8.8.8.8: seq=18 ttl=124 time=10.971 ms
64 bytes from 8.8.8.8: seq=19 ttl=124 time=5.967 ms
64 bytes from 8.8.8.8: seq=20 ttl=124 time=7.454 ms
64 bytes from 8.8.8.8: seq=21 ttl=124 time=8.961 ms
64 bytes from 8.8.8.8: seq=22 ttl=124 time=11.533 ms
64 bytes from 8.8.8.8: seq=23 ttl=124 time=5.365 ms
64 bytes from 8.8.8.8: seq=24 ttl=124 time=10.102 ms
64 bytes from 8.8.8.8: seq=25 ttl=124 time=10.312 ms
64 bytes from 8.8.8.8: seq=26 ttl=124 time=6.405 ms
64 bytes from 8.8.8.8: seq=27 ttl=124 time=6.356 ms
64 bytes from 8.8.8.8: seq=28 ttl=124 time=4.418 ms
64 bytes from 8.8.8.8: seq=29 ttl=124 time=4.547 ms

No more death lags.