{"id":9,"date":"2011-12-15T17:50:00","date_gmt":"2011-12-15T17:50:00","guid":{"rendered":"http:\/\/cazenave.co.uk\/wp\/?p=9"},"modified":"2014-04-24T22:06:14","modified_gmt":"2014-04-24T22:06:14","slug":"automatic-upload-speed-throttling","status":"publish","type":"post","link":"https:\/\/cazenave.co.uk\/automatic-upload-speed-throttling\/","title":{"rendered":"Automatic upload speed throttling"},"content":{"rendered":"

As I’ve discussed before, the broadband service we receive from Virgin is subject to caps on the traffic on the line during certain times of day (see this post I wrote<\/a>). Virgin have a relatively complex system for throttling your speed based on the amount you download and upload within certain times. I have a script which performs a backup of my data from my server at home to my work computer using rsync over SSH. This means that I sometimes have a large amount of data to upload during the day. Since Virgin’s upload restrictions apply between 1500 and 2000 during which time you are permitted to upload a maximum of 1.5GB<\/a>. What this means is that for five hours, the average transfer rate must not exceed 300MB per hour, which equates to a transfer speed of 83.3 kB\/s. I searched for a way to limit my server’s upload speed and came across tc<\/a> (which is a kernel extension which must be enabled in your .config). Slackware’s kernel config includes the necessary parts as modules, so when you use the tc command, they are automatically loaded.<\/p>\n

I found a good example which described what I wanted to achieve (limit my uploads to 83.3 kB\/s) here<\/a>. Using the examples on that page, I wrote a little script to allow me to start and stop the limited uploads easily:<\/p>\n

#!\/bin\/bash<\/p>\n

# Script to throttle uploads during the times when Virgin
# won’t allow unlimited uploads.
#
# Those times are between 1500 and 2000 no more than
# 1.5GB must be uploaded, so the upload speed needs to be
# capped at 83.3kB\/s.<\/p>\n

maxRate=83.3kbps
burstRate=100000kbps
interface=eth0<\/p>\n

clearRule(){
        # First things first, clear the old rule
        tc qdisc del dev eth0 root
}<\/p>\n

makeRule(){
        # Now add the throttling rule
        tc qdisc add dev $interface root handle 1:0 htb default 10
        tc class add dev $interface parent 1:0 classid 1:10 htb rate $maxRate ceil $burstRate prio 0
}<\/p>\n

listRules(){
        tc -s qdisc ls dev $interface
}<\/p>\n

case “$1” in
        ‘start’)
                clearRule
                makeRule
        ;;
        ‘stop’)
                clearRule
        ;;
        ‘status’)
                listRules
        ;;
        *)
                echo “Usage: $0 {start|stop|status}”
        ;;
esac<\/p><\/blockquote>\n

You’ll note I’ve set a $burstRat<\/span>e value of 100MB\/s. This is probably not necessary, but with the same $burstRate<\/span> value as used in $maxRate<\/span>, I was seeing significant slowdown in the responsiveness of the remote session; I hope this high burst rate will alleviate that slowdown.<\/p>\n

I saved this script somewhere where root only could get it and then added the following cronjobs to root’s crontab:<\/p>\n

# Add networking throttling between 1500 and 2000<\/span>
00 15 * * * \/root\/throttle_uploads.sh start<\/span>
00 20 * * * \/root\/throttle_uploads.sh stop<\/span><\/p><\/blockquote>\n

So far, the process appears to be working, insofar as my daily uploads from home to work have slowed to approximately 80kB\/s during the times when Virgin monitor uploads.<\/p>\n","protected":false},"excerpt":{"rendered":"

As I’ve discussed before, the broadband service we receive from Virgin is subject to caps on the traffic on the line during certain times of day (see this post I wrote). Virgin have a relatively complex system for throttling your speed based on the amount you download and upload within certain times. I have a […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[10,13,12,14,11,7,9,16,8,15],"tags":[],"_links":{"self":[{"href":"https:\/\/cazenave.co.uk\/wp-json\/wp\/v2\/posts\/9"}],"collection":[{"href":"https:\/\/cazenave.co.uk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cazenave.co.uk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cazenave.co.uk\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cazenave.co.uk\/wp-json\/wp\/v2\/comments?post=9"}],"version-history":[{"count":0,"href":"https:\/\/cazenave.co.uk\/wp-json\/wp\/v2\/posts\/9\/revisions"}],"wp:attachment":[{"href":"https:\/\/cazenave.co.uk\/wp-json\/wp\/v2\/media?parent=9"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cazenave.co.uk\/wp-json\/wp\/v2\/categories?post=9"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cazenave.co.uk\/wp-json\/wp\/v2\/tags?post=9"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}