QoS - Internet Traffic Shaping/Scheduling
Every now and then, I upload big files such as images and videos, or send an e-mails with big attachments. During these uploads inteactive applications such as an ssh session are lagged to death, and it becomes a pain in the ass to type anything.
Well, to overcome this limitation I came up with a script that limits upload bandwidth of big file uploads and gives the lower priority. Naturally, in contrast it gives higher priority to interactive communication. To do this of course we need some sort of classification of both different cases. I've used probably the simplest one. Big packets are used in big file uploads, I've marked packets with size greater than 500 byte as big. And packets smaller than 500 bytes as small. I've assigned bandwidths to these small and big packets. And voila! It worked for me. I'm using this for years.
[View | Download] the script.
NOTES:
- Edit the file and define upload limits and the device you want to control
- Edit the local network mask so that the LAN traffic is not limited
- You can run `qos.sh stop` to stop scipt functionality but it will delete al the rules in "iptalbes -t mangle"
- Obviously you need necessary kernel modules, you'll get appropriate errors if you don't have them.
Demonstration:
I've started a big file upload, and observed the latency between my ISPs DNS server. You can see the latency starts to drop after some point, that's when I run qos.sh
64 bytes from 62.248.113.53: icmp_seq=1005 ttl=62 time=4162 ms
64 bytes from 62.248.113.53: icmp_seq=1006 ttl=62 time=4732 ms
64 bytes from 62.248.113.53: icmp_seq=1007 ttl=62 time=4743 ms
64 bytes from 62.248.113.53: icmp_seq=1008 ttl=62 time=4529 ms
64 bytes from 62.248.113.53: icmp_seq=1009 ttl=62 time=4421 ms
64 bytes from 62.248.113.53: icmp_seq=1010 ttl=62 time=4635 ms
64 bytes from 62.248.113.53: icmp_seq=1011 ttl=62 time=4073 ms
64 bytes from 62.248.113.53: icmp_seq=1012 ttl=62 time=3946 ms
64 bytes from 62.248.113.53: icmp_seq=1013 ttl=62 time=3767 ms
64 bytes from 62.248.113.53: icmp_seq=1014 ttl=62 time=3202 ms
64 bytes from 62.248.113.53: icmp_seq=1015 ttl=62 time=2860 ms
64 bytes from 62.248.113.53: icmp_seq=1016 ttl=62 time=2496 ms
64 bytes from 62.248.113.53: icmp_seq=1017 ttl=62 time=2067 ms
64 bytes from 62.248.113.53: icmp_seq=1018 ttl=62 time=1699 ms
64 bytes from 62.248.113.53: icmp_seq=1019 ttl=62 time=1329 ms
64 bytes from 62.248.113.53: icmp_seq=1020 ttl=62 time=974 ms
64 bytes from 62.248.113.53: icmp_seq=1021 ttl=62 time=499 ms
64 bytes from 62.248.113.53: icmp_seq=1022 ttl=62 time=332 ms
64 bytes from 62.248.113.53: icmp_seq=1023 ttl=62 time=17.8 ms
64 bytes from 62.248.113.53: icmp_seq=1024 ttl=62 time=11.5 ms
64 bytes from 62.248.113.53: icmp_seq=1025 ttl=62 time=9.01 ms
64 bytes from 62.248.113.53: icmp_seq=1026 ttl=62 time=9.61 ms
64 bytes from 62.248.113.53: icmp_seq=1027 ttl=62 time=13.6 ms
64 bytes from 62.248.113.53: icmp_seq=1028 ttl=62 time=25.0 ms
64 bytes from 62.248.113.53: icmp_seq=1029 ttl=62 time=111 ms
64 bytes from 62.248.113.53: icmp_seq=1030 ttl=62 time=11.3 ms
64 bytes from 62.248.113.53: icmp_seq=1031 ttl=62 time=13.5 ms
64 bytes from 62.248.113.53: icmp_seq=1032 ttl=62 time=28.3 ms
64 bytes from 62.248.113.53: icmp_seq=1033 ttl=62 time=11.7 ms