[ Date Index ] [ Thread Index ] [ <= Previous by date / thread ] [ Next by date / thread => ]
I've been fighting a battle with bittorrent which has a habit of hoggingthe whole connection to itself when i'm not looking. I have speed limits set but that doesn't
take into account the changing apparent connection speed, which depends on what other people in the house are doing (of which i have no idea), ISP contention ratios and also Virgin's throttling. I don't want to setthe limits based on the worst case, so yesterday I hacked together a ping-based throttling
script. I present it here incase anyone else is interested/has comments. how it works: 1: ping a server to get it's IP (output of ping was easier to deal with than the output of nslookup) 2: repeatedly ping the IP from #1 3: average the last 5 results from #2 4: if result from #3 is too high, limit the upstream bandwidth limit (how this happens depends on how high it is) 5: if the result from #3 is too low, increase the upstream bandwidth limit I have it set to control between 100 and 200ms. the scripts: my autospeed script with a modified copy of wondershaper are available here: http://yatt.doesntexist.com/scripts/pingwatch.pl http://yatt.doesntexist.com/scripts/wshaper-over-lan.htb from memory, I modded wondershaper so that ack packets aren't throttled either but I can't remember if I had a good reason for it. someone else had previously modified it so that only internet traffic is throttled (or rather lan traffic is throttled separately to 100mbit each way) instructions: 1: save both files to the same directory, which should also be the current working directory 2: edit pingwatch.pl. At a minimum you would need to change $iface and $maxupstream. If you decrease $maxupstream then also decrease $upstream. data rates are in kbit/s. Also, you should probably change the address it will ping in lines 6 and 9 (make sure you put the same address in both). I found using google was too slow, so i tracerouted google and chose a virgin (my ISP) server closer to me. 3: run pingwatch.pl as root (yes I know terrible practice. see 1st note below) and 4: When you're finished, Ctrl+C to exit 5: run wshaper-over-lan.htb [your interface] [your lan speed] [your lan speed] to remove the limits (or clear the iptables rules) 6: tell me what you think. I also use mtr google.com to watch it's performance Things to note: -it's a quick and dirty prototype so no "your code is crap!" comments please- suggestions of general improvements are more what I was after -I have a feeling that wondershaper will clear your existing iptables rules and replace them with it's own so make sure your own rules are backed up first. -the variables from lines 109 to 126 can be modified to match your needs but i haven't put any sanity checking so you might break things. Todo: -make it all 1 script -some magic cleverer control algorithm -use perl functions rather than external ping program -maybe get it to figure out some of the parameters itself. eg vary $maxupstream based on the actual data rate. No point increasing the limit if the data isn't being limited by it. -better output to summarise what's going on rather than a huge list.-see if it can be done with trickle or equivalent so it's on a per application basis.
Sample output: yatt@yerserver:~$ sudo ./pingwatch.pl 195.182.178.129 13.5 12.5 13.3 17.2 17.9 Ping: 15.4 Shaping eth1 : down: 10000 up: 501 increase Ping: 16.58 Shaping eth1 : down: 10000 up: 502 increase Ping: 30.88 Shaping eth1 : down: 10000 up: 503 increase Ping: 61.04 Shaping eth1 : down: 10000 up: 504 increase Ping: 117.26 Ping: 177.44 Ping: 263.16 Shaping eth1 : down: 10000 up: 488 decrease Ping: 354.8 Shaping eth1 : down: 10000 up: 472 decrease Ping: 429 Shaping eth1 : down: 10000 up: 456 decrease note that Ping is the average of the last 5 ping results -- The Mailing List for the Devon & Cornwall LUG http://mailman.dclug.org.uk/listinfo/list FAQ: http://www.dcglug.org.uk/linux_adm/list-faq.html