My internet was under performing quite severly and I didn’t know why. Occasionally for periods of time from a few minutes to hours at a time our internet would become unusable.
First thing was isolating the problem . I installed all the monitoring tools I could to find to narrow down the problem to an application or device.
I managed to find the app causing all my issues, it was Google Photo’s but there were no throttling options in the software to stop it.
I was honestly so surprised, but anytime a device in our house came home to land on the WiFi, we couldn’t browse the web until it was done uploading it’s photo’s.
The worst thing about the problem is that we love Google Photo’s and couldn’t live without. From the free uploads at a great quality to the AI on the image categorization and knowing all the photos I’m in with my favourite people.
Back to the cons! No internet for quite a substantial portion of time until videos and photos were uploaded snugly and safely to the web vault, was not something we wanted to live with.
What I wanted to solve
I wanted internet all the time, I didn’t want to manually have to throttle all connections on the network, install software on each device to do the same.
I wanted something to automatically take care of an issue I couldn’t solve inside the Google Photo’s app. I had an idea that I could setup a device which would automatically share the bandwidth fairly between all our users and programs fairly.
The Raspberry Pi is an awesome piece of hardware, anytime I have a IT household problem to solve it usually has just what I need. From the earliest iteration it was a phenomenal piece of hardware in a bite size format and a teeny tiny price of just $35.
A brief investigation into the Raspberry Pi 3 showed that you can run it in a Access Point mode, and with the Ethernet wired into the network, the rest would be software.
The initial problem was to setup the Pi as a WiFi router, which is quite well documented on the web, I followed this guide.
The last piece of the puzzle. I was actually quite surprised that a piece of software called IP Tables, which is normally used for directing traffic was actually able do quality management and throttling.
The IP Tables result was actually pretty great, but was quite complicated to setup, I modified a guide I found and … we now have the best internet we ever had at home, even though the line is quite slow, it’s never felt slow for us again.
A little bit more technical stuff
Using Traffic Control (tc) command you can setup discovery queues which allow traffic to be classified into classes.
tc qdisc add dev eth0 root handle 1: htb default 15 tc class add dev eth0 parent 1:1 classid 1:10 htb rate 80kbit ceil 80kbit prio 0
Inside the classes you can classify traffic filters, which will put your traffic into buckets.
Once you have your traffic classified into buckets you start prioritizing which buckets will get bandwidth allocation.
tc filter add dev eth0 parent 1:0 protocol ip prio 1 handle 1 fw classid 1:10
And you can also prioritize certain packets, normally ones that are critical but never actually use a lot of bandwidth, some like SSH which is text only for controlling servers and SYN, which is handshaking packets, giving these the highest priorities should never take away from your top download speed, but does give you much better response times on websites.
iptables -t mangle -I PREROUTING -p tcp -m tcp --tcp-flags SYN,RST,ACK SYN -j MARK --set-mark 0x1 iptables -t mangle -I PREROUTING -p tcp -m tcp --tcp-flags SYN,RST,ACK SYN -j RETURN
I did have a few issues getting it to start on boot, which was quite a pain due to all the commands, but did eventually get it to start up in init.d
Where to from here
I could have used some expensive off the shelf hardware to fix the problem, or buy faster internt, but it was actually great being able to take hardware I had around the house and fix a problem I was having.
This actually accomplished everything I wanted, but there were a few things that would have been nice to add. Since I had the WiFi router functioning on a full linux computer, getting some metrics off it would have been great.
View bandwidth usage by PC, Protocol, Country, Website.
Setup a user login and guest system for logins and turn this into an open hotspot, with only unused capacity being shared.
Thresholds for certain services, like limit Netflix automatically so it only streams at 720p and not 1080p.
Back to cat memes!