MoLa: My Internet connection slows down when I download — how can I speed it up?

You’re browsing the Web. It’s smooth, fast sailing, with pages loading in a snap. Then you start a download — and what was formerly a fast Internet connection turns into a slower-than-dialup experience. What happened?

Why Web browsing slows down when downloading files

Believe it or not, this is common. If you’re like me, you have a fast fiber, DSL or cable modem hookup to the Internet, directly hooked to your computer. You’re probably using file sharing applications all the time, as well. This causes terrible Web browsing — and you can easily figure that out, because as soon as you stop any file sharing applications, Web browsing speed returns back to normal.

The slowdown is caused by the queues at your ISP (or your modem). The ISP limits your Internet speed either at the modem, or at the router assigned to your modem. Since information can’t come in as fast as possible, long queues of pending information build up in your router/modem.

The effect? After you click on a link in your Web browser, quite a lot of information (usually, your download) needs to be dispatched before you get to see the new Web page.

The solution: rate-limiting (odd, isn’t it?)

Counterintuitive as it may sound, the solution to the queues is to limit the rate at which information reaches your computer, directly on your computer. By using a clever combination of bandwidth limiting and priorization of outbound packages, you can have almost-normal Web browsing speeds, combined with fast downloads.

In other words:

  • Anything your computer sends to the Internet will be given priorities, and important information will jump the queue. Sends of acknowledgements and interactive traffic (remote desktops, shells) will get priority.
  • If any computer attempts to send data to your computer too quickly, your computer will tell it to slow down. This will avoid the buildup in the queue at your ISP.

Basically, you’ll be executing a tradeoff: decreasing latency at the expense of a bit (5% to 10%) of bandwidth, but the cost is certainly worth it.

Now, you may balk because this technique requires you to actually scale back (a bit) your connection speed. Do not — if you follow through, your effective download speed will go up, because TCP acknowledgements arrive to their destination faster. If you’re using BitTorrent (which requires uploading), you’ll see a stable, maxed-out, download speed, instead of seeing dips in download speed when uploading.

As usual, the solution is a clever script that does everything for you, instead of you having to do it manually.

The script that solves the speed problem

Further below, you’ll find instructions on how to use it.

#!/bin/bash

Wonder Shaper

please read the README before filling out these values

#

Set the following values to somewhat less than your actual download

and uplink speed. In kilobits. Also set the device that is to be shaped.

DOWNLINK=176 UPLINK=120 DEV=eth1

low priority source netmasks

NOPRIOHOSTSRC=

low priority destination netmasks

NOPRIOHOSTDST=

low priority source ports

NOPRIOPORTSRC="6881 6882 13810 6346 4800"

low priority destination ports

NOPRIOPORTDST=

high priority source netmasks

HIPRIOHOSTSRC=

high priority destination netmasks

HIPRIOHOSTDST=

high priority source ports

HIPRIOPORTSRC="5900 5901"

high priority destination ports

HIPRIOPORTDST=

if [ "$1" = "status" ] then echo "Queueing disciplines:" tc -s qdisc ls dev $DEV

    rootclassoutput=`tc -s class ls dev $DEV | grep -A 5 "htb 1:1 "`
    allclassesoutput=`tc -s class ls dev $DEV`

    echo ""
    echo "Root class:"
    echo "$rootclassoutput"
    echo ""
    echo "Child classes:"
    echo "$allclassesoutput" | cut -d "

” -f 6,7,8,9,10,11 –complement exit fi

clean existing down- and uplink qdiscs, hide errors

tc qdisc del dev $DEV root 2> /dev/null > /dev/null tc qdisc del dev $DEV ingress 2> /dev/null > /dev/null

if [ "$1" = "stop" ] then exit fi

uplink

we’ll have four classes:

10: acknowledgements and traffic marked as interactive (Minimize-Delay)

20: high-priority outbound traffic

30: regular traffic

40: low-priority outbound traffic and traffic marked as bulk (Maximize-Throughput)

install root HTB, point default traffic to 1:30:

tc qdisc add dev $DEV root handle 1: htb default 30

shape everything at $UPLINK speed - prevents huge outbound queues:

tc class add dev $DEV parent 1: classid 1:1 htb rate ${UPLINK}kbit burst 5k

tc class add dev $DEV parent 1:1 classid 1:10 htb rate ${UPLINK}kbit ceil ${UPLINK}kbit burst 5k prio 1 tc class add dev $DEV parent 1:1 classid 1:20 htb rate ${UPLINK}kbit ceil ${UPLINK}kbit burst 5k prio 2 tc class add dev $DEV parent 1:1 classid 1:30 htb rate $[8$UPLINK/10]kbit ceil ${UPLINK}kbit burst 5k prio 3 tc class add dev $DEV parent 1:1 classid 1:40 htb rate $[6$UPLINK/10]kbit ceil ${UPLINK}kbit burst 5k prio 4

all get Stochastic Fairness:

tc qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10 tc qdisc add dev $DEV parent 1:20 handle 20: sfq perturb 10 tc qdisc add dev $DEV parent 1:30 handle 30: sfq perturb 10 tc qdisc add dev $DEV parent 1:40 handle 40: sfq perturb 10

TOS Minimum Delay (ssh, NOT scp) in 1:10:

tc filter add dev $DEV parent 1:0 protocol ip prio 10 u32 \ match ip tos 0×10 0xff \ flowid 1:10

To speed up downloads while an upload is going on, put ACK packets in 1:10:

tc filter add dev $DEV parent 1:0 protocol ip prio 11 u32 \ match ip protocol 6 0xff \ match u8 0×05 0×0f at 0 \ match u16 0×0000 0xffc0 at 2 \ match u8 0×10 0xff at 33 \ flowid 1:10

High-priority traffic in 1:20:

for a in $HIPRIOPORTDST ; do tc filter add dev $DEV parent 1: protocol ip prio 12 u32 match ip dport $a 0xffff flowid 1:20 done for a in $HIPRIOPORTSRC ; do tc filter add dev $DEV parent 1: protocol ip prio 12 u32 match ip sport $a 0xffff flowid 1:20 done for a in $HIPRIOHOSTSRC ; do tc filter add dev $DEV parent 1: protocol ip prio 12 u32 match ip src $a flowid 1:20 done for a in $HIPRIOHOSTDST ; do tc filter add dev $DEV parent 1: protocol ip prio 12 u32 match ip dst $a flowid 1:20 done

Low-priority traffic in 1:40:

for a in $NOPRIOPORTDST ; do tc filter add dev $DEV parent 1: protocol ip prio 13 u32 match ip dport $a 0xffff flowid 1:40 done for a in $NOPRIOPORTSRC ; do tc filter add dev $DEV parent 1: protocol ip prio 13 u32 match ip sport $a 0xffff flowid 1:40 done for a in $NOPRIOHOSTSRC ; do tc filter add dev $DEV parent 1: protocol ip prio 13 u32 match ip src $a flowid 1:40 done for a in $NOPRIOHOSTDST ; do tc filter add dev $DEV parent 1: protocol ip prio 13 u32 match ip dst $a flowid 1:40 done

Maximize throughput (scp, BitTorrent, uploads) in 1:40:

tc filter add dev $DEV parent 1:0 protocol ip prio 14 u32 \ match ip tos 0×08 0xff \ flowid 1:40

rest is ‘non-interactive’ ie ‘bulk’ and ends up in 1:30

tc filter add dev $DEV parent 1: protocol ip prio 15 u32 \ match ip dst 0.0.0.0/0 \ flowid 1:30

#### downlink

slow downloads down to somewhat less than the real speed to prevent

queuing at our ISP. Tune to see how high you can set it.

ISPs tend to have huge queues to make sure big downloads are fast

#

attach ingress policer:

tc qdisc add dev $DEV handle ffff: ingress

filter everything to it (0.0.0.0/0), drop everything that’s

coming in too fast:

tc filter add dev $DEV parent ffff: protocol ip prio 50 u32 match ip src \ 0.0.0.0/0 police rate ${DOWNLINK}kbit burst 5k drop flowid :1

This is a heavily tuned version of the Wonder Shaper script that roams the Linux advanced routing and traffic control Web site.

Keep reading to find out how to install and use this script on your computer.

Pages: 1 2

12 Responses to “MoLa: My Internet connection slows down when I download — how can I speed it up?”

  1. Legithrand Says:

    Nah! I rather have downloads to eat my bandwidth… not much of a browser kinda guy… I always know what I’m looking for (ok, mostly)… But good to know! I’ll have it on my SCRIPTS folder, I might give it a shot sometime…

  2. Rudd-O Says:

    Legithrand:

    The point of the script is that your effective download speed goes up, because TCP acknowledgements arrive faster to their destination. If you’re using BitTorrent (which requires uploading), you’ll see a stable, maxed-out, download speed, instead of seeing jumps.

  3. Rudd-O Says:

    This is a test comment. Ignore me, please.

  4. Jesvin Says:

    Hi

    In this part of the world, I have a broadband @ 64 kbps (ofcourse its BB equipment in use a billion bipac 5200 router :-( ) that peaks 12 kbps down/ 10 kbps up. So I have to paste my actual speeds in the scripts right?

    Also does it help reduce the load time when I have 20 tabs loading at once, especially with pages of lots of images?

    Around here, persons with this kind of knowledge are conceited seniors in ISPs , with stars-in-thier-eyes speeches abt broadbands future, generally inaccessible to customers and openly hurles abuses linux users, calling them troublemakers and blackhat wannabees. You proved that there is still hope in this world.

  5. Rudd-O Says:

    Jesvin:

    You need to paste the speeds minus 10%, in your case minus about 12% (because bursts are 5k). Thanks for the heartwarming comment :-)

  6. Rudd-O Says:

    If you measure 12 KBytes maximum download, then you’d have to place (12 times 8 ) divided by ( 10 times 9 ) == 86 as the download speed.

  7. Smith Data Processing Services » Blog Archive » links for 2007-05-16 Says:

    [...] MoLa: My Internet connection slows down when I download — how can I speed it up? • Rudd-O.com (tags: linux bandwidth howto) [...]

  8. Jesvin Says:

    Hi

    I got a few error messages on lines 84 and 85, apparently because (math with) very samll numbers are involved(12 and 5). After this my browser crawled so slow I had to restart. Could you incorporate a start/stop/resatart features lik a deamon does?

  9. Rudd-O Says:

    It has stop features. If you run it like:

    sudo /etc/rc.wshaper stop

    it will stop working.

  10. Jesvin Says:

    But Rudd-O, waht about the problem of impossible divisions in lines 84 and 85

  11. Rudd-O Says:

    Jesvin: I see no impossible divisions in the script. Everything is divided by ten.

  12. Jesvin Says:

    sorry I didnt post the error earlier

    [root@localhost jesvin]# /etc/rc.d/speed /etc/rc.d/speed: line 84: 87.2/10: syntax error in expression (error token is “.2/10″) /etc/rc.d/speed: line 85: 67.2/10: syntax error in expression (error token is “.2/10″) RTNETLINK answers: Invalid argument RTNETLINK answers: Invalid argument

    After this my BT client slowed threefold. So I stopped it and it went normal again

Leave a Reply