Modifying SQM for Twitch Streamers

This tutorial is for openWrt routers only and assumes you’ve completed https://www.stoplagging.com/openwrt-method-fq_codel-cake/ with cake set up.

Why do we need to do this? Normally cake is fine by itself and ensures fair usage of your shared Internet at home. This great for gamers, video conferences, and VOIP call in general.

However, as a twitch streamer your situation is unique. If you have small upload bandwidth such as 5Mbps up, and stream at a bitrate of 3Mbps or higher you need to configure cake to be unfair and give more upload to your twitch streaming packets. The download direction can remain fair and doesn’t need to be configured.

Overall there are 2 things that need to be done. First is to make room in the Priority Bucket by making it higher than the default. The second is to mark your twitch packets with DSCP so that it goes into the Priority Bucket.

Credits: to moeller0 for helping me find this solution.

1. OpenWrt Section

First SSH into your router. If you don’t know how to SSH don’t worry just download PuTTY and install it. After that, launch PuTTY, and type in your router’s IP address under “Host Name (or IP Address)” and click on open. After that login as your username and password. That’s pretty much SSHing to your router!

Install nano text editor

Do this if you’re not familiar with vi or linux shell in general.

opkg update
opkg install nano
Make a copy of simple.qos to twitch.qos and edit it
cd /usr/lib/sqm
ls
cp simple.qos twitch.qos
nano twitch.qos

nano twitch.qos will open the nano text editor and allow you to edit the twitch.qos file.

What you need to do is modify the following from PRIO_RATE=`expr $CEIL / 3` to PRIO_RATE=3500 under the egress() code block. Egress means upload traffic.

image-1588621781100.png

It doesn’t have to be 3500 but don’t put in your max bandwidth because you will starve the other buckets. I stream at 3000 so I wanted to leave an extra 500 headroom for other computers and gaming traffic in the priority bucket by setting it to 3500.

If you’re unfamiliar with nano you can search for PRIO_RATE= with Ctrl+W, typing in PRIO_RATE=, and pressing Enter. Do make sure you’re in the egress block though.

Finally after modifying this you want to Save & Exit. To do this do Ctrl + O and press Enter.

You can now exit PuTTY.

Login to your router’s webpage in the browser. Change the queue setup script from whatever you were using to twitch.qos. Then press Save & Exit.

image-1588621973293.png

2. Marking Twitch Stream Packets in Windows PowerShell

Search for powershell in Windows 10 and run as administrator

image-1588620087423.png

Type in the following below. In my example my obs is called “obs64.exe” yours may be different if you use something like streamlabs. To find out your apps name you can go to Task Manager and click on the Details tab to see.

New-NetQosPolicy -Name "twitch" -AppPathNameMatchCondition "obs64.exe" -PolicyStore ActiveStore -NetworkProfile All -DSCPAction 46

Use Get-NetQosPolicy -Store ActiveStore to list existing policies and Remove-NetQosPolicy -Name "twitch" -Store ActiveStore to remove policy if you do not need them anymore.

image-1588620215657.png

3. Optional: How to check if streaming packets are marked with Wireshark

This step is optional and helps prove that your twitch packets are being marked properly.

Install Wireshark. https://www.wireshark.org/download.html

Select your Ethernet interface that you use to connect to the Internet.

To filter packets marked by DSCP type in “ip.dsfield.dscp==46” on the filter.

Notes: 46 Means Expediated Forwarding as described in RFC 2475.

To filter packets based on the RTMP protocol (which twitch uses) and the DSCP mark type in the following for the filter. 1

ip.dsfield.dscp==46 && rtmpt

To add a DSCP Column to wireguard, Right click on a column. Click on “Column Preferences…”, press the + Sign. Title = DSCP. Type = Custom. Fields = “ip.dsfield.dscp”. Then resize columns until you see the DSCP column.

image-1588620002398.png