Slashdot Mirror


Why BitTorrent Causes Latency and How To Fix It

Sivar recommends an article by George Ou examining why BitTorrent affects performance so much more than other types of file transfer and a recommendation on how to fix it. The suggestion is to modify P2P clients so that, at least on upload, they space their traffic evenly in time so that other applications have a chance to fit into the interstices. "[Any] VoIP [user] or online gamer who has a roommate or a family member who uses BitTorrent (or any P2P application) knows what a nightmare it is when BitTorrent is in use. The ping (round trip latency) goes through the roof and it stays there making VoIP packets drop out and game play impossible."

22 of 315 comments (clear)

  1. QoS? by Opportunist · · Score: 5, Funny

    Hey, I have a really spiffy idea. How about creating a router that can determine which packets take precedence? I'll make millions off that idea...

    What? Oh, damn Linux! What? Oh, Windows can do it too now? Why do I always have the good ideas about 10 years too late?

    --
    We used to have a Bill of Rights. Now, with the rights gone, all we have left is the bill.
    1. Re:QoS? by pin0chet · · Score: 5, Informative

      OpenWRT and Tomato feature impressive QoS capabilities as well.

      L7-filter can even manage traffic at the application layer. Just set Bittorrent to "Bulk" and put Skype and Xbox live as "Premium."

      Managing traffic on the router level is a lot easier than on the PC level, especially when you have several devices on a single network competing for scarce bandwidth.

    2. Re:QoS? by cgdiaz · · Score: 5, Insightful

      Well, since the article is about how to stop other users on the network from ruining your net experience, I think we assume they will be on a router of some sort.

    3. Re:QoS? by Dolda2000 · · Score: 4, Informative
      It sounds like you're doing it wrong. I've set up HTB shaping with tc on Linux as well, and it works very well. Flawlessly, I might even say.

      There are two key points:

      • You absolutely need to limit to absolute maximum outbound bandwidth (on the root qdisc, in other words) to a value slightly below your real outbound bandwidth. This point is critical. Without it, there's no point in even trying to shape the traffic, since the modem will start buffering.
      • It helps very greatly if it is possible for you to classify torrent traffic into a HTB class with lower priority than whatever class the packets you care about go into. There are several possibilities for going about that:
        • If the program in question supports setting the DSCP field of the packets (where the TOS field went previously), you can use iptables with -m dscp to set the fwmark on them to classify more precisely (remember to clear the DSCP field before sending the packets out from your network, though).
        • If a program running locally on the router does not support setting DSCP values, you can create a group, set the program to SGID to that group, and use iptables with -m owner --gid-owner $GROUPNAME to set the fwmark. The same method can be used to set the DSCP field on packets from a Linux machine other than the router.

      For reference, here is the script that I use to set up the traffic shaping. It might prove useful to you.

      #!/bin/sh

      # Current bandwidth allocation:
      # 1:11 1:121 1:122 1:13 1:14 1:15 1:1
      # (25 + (175 + 75) + 125 + 175 + 25) = 600

      tc qdisc add dev wan root handle 1: htb default 122
      # Root
      tc class add dev wan parent 1: classid 1:1 htb rate 600kbit ceil 600kbit cburst 1500 burst 50kb
      # TOS Min-Delay
      tc class add dev wan parent 1:1 classid 1:11 htb prio 0 rate 25kbit ceil 50kbit burst 10kbit
      # Bulk
      tc class add dev wan parent 1:1 classid 1:12 htb prio 1 rate 250kbit ceil 600kbit burst 10kb
      # HTTP
      tc class add dev wan parent 1:1 classid 1:13 htb prio 1 rate 125kbit ceil 600kbit burst 50kb
      # FTP (Needs iptables support)
      tc class add dev wan parent 1:1 classid 1:14 htb prio 1 rate 175kbit ceil 600kbit burst 10kb
      # Low priority
      tc class add dev wan parent 1:1 classid 1:15 htb prio 2 rate 25kbit ceil 500kbit
      burst 10kb
      # TOS Max-Bandwidth
      tc class add dev wan parent 1:12 classid 1:121 htb prio 1 rate 175kbit ceil 600kbit
      # Default
      tc class add dev wan parent 1:12 classid 1:122 htb prio 1 rate 75kbit ceil 600kbit
      # TOS Min-Cost (Needs iptables support)
      tc class add dev wan parent 1:15 classid 1:151 htb prio 2 rate 5kbit ceil 400kbit burst 10kb
      # Auxiliary low prio bands
      tc class add dev wan parent 1:15 classid 1:152 htb prio 2 rate 5kbit ceil 400kbit burst 10kb
      tc class add dev wan parent 1:15 classid 1:153 htb prio 2 rate 5kbit ceil 400kbit burst 10kb
      tc class add dev wan parent 1:15 classid 1:154 htb prio 2 rate 5kbit ceil 400kbit burst 10kb
      tc class add dev wan parent 1:15 classid 1:155 htb prio 2 rate 5kbit ceil 400kbit burst 10kb

      # Filters
      tc filter add dev wan parent 1: protocol ip prio 1 handle 11 fw flowid 1:151
      tc filter add dev wan parent 1: protocol ip prio 1 handle 12 fw flowid 1:152
      tc filter add dev wan parent 1: protocol ip prio 1 handle 13 fw flowid 1:153
      tc filter add dev wan parent 1: protocol ip prio 1 handle 14 fw flowid 1:154
      tc filter add dev wan parent 1: protocol ip prio 1 handle 15 fw flowid 1:155
      tc filter add dev wan parent 1: protocol ip prio 2 handle 1 fw flowid 1:14
      tc filter add dev wan parent 1: protocol ip prio 3 u32 match ip tos 0x10 0x1e flowid 1:11
      tc filter add dev wan parent 1: protocol ip prio 3 u32 match ip tos 0x08 0x1e flowid 1:121
      tc filter add dev wan parent 1: protocol ip prio 3 u32 match ip sport 80 0xffff flowid 1:13
      tc filter add dev wan parent 1: protocol ip prio 3 u32 match ip sport 443 0xffff flowid 1:13

      # Leaf nodes
      tc qdisc add dev wan parent 1:11 handle 2: sfq p

    4. Re:QoS? by Donjo · · Score: 5, Funny

      Was it some guy from 127.0.0.1? I used Zone Alarm once and that guy was always trying to hack me. To bad I showed him, I made a batch file and pinged him thousands of times a second. Then my computer lagged so I stopped but I think I probably got him pretty good. /sarcasm

    5. Re:QoS? by schnipschnap · · Score: 5, Insightful

      You should have taken a quick look at the article first. The author basically experienced excessive lag even though he did cap his upload rate, compared to what an upload or download via a different protocol (FTP, HTTP, VoIP) would cause. This is because the BT client fires or receives packets whenever they are available, while the others receive or send packets in a spaced manner (unless they saturate the pipe). That means that even though your upload rate may be limited to 10 KB/s, if your total upload is 20 KB/s, you might experience a maximum lag of 0.5 seconds. The guy put up a lot of graphs to illustrate that it happens quite often actually. It seems that he got those patterns with the "official" client and with Azureus.

  2. Next on /. by this+great+guy · · Score: 5, Funny

    Why BitTorrent causes network bandwidth to be used. And network packets to be sent & received. Really sometimes I wonder.

  3. QoS, but only on the Telco Side by corsec67 · · Score: 4, Informative

    While I prefer Tomato on a WRT-54GL, that would do absolutely nothing at all to solve this issue. A router behind a modem can really only regulate the upload, and can't easily prevent a flood of data on the downstream side.

    This issue is with the queue on the Telco's DSLAM, or on the other side of the cable from the modem. This is more like an invited DDOS, which no amount of filtering at or behind the modem can resolve, because the modem is getting the traffic from the DSLAM after it goes through the queue.

    The only way to have QOS solve this issue would be to ask the telco to do the QOS for you, and the amount of processing power to do that nicely isn't trivial.

    --
    If I have nothing to hide, don't search me
    1. Re:QoS, but only on the Telco Side by WhatAmIDoingHere · · Score: 5, Interesting

      I use between 50 and 80% of my max upload for torrents. I'm able to play TF2 and ping in the 20s. This article is addressing an issue that has been covered in every single "So, you want to use BitTorrent" article EVER.

      Hell, Azureus has a plugin to test ping an IP address/website, and if it takes longer than a set time, it slows down your uploads. uTorrent has a feature like that, as well.

      --
      Not a Twitter sockpuppet... but I wish I was.
    2. Re:QoS, but only on the Telco Side by silas_moeckel · · Score: 4, Informative

      Funny I'm a network guy and grok normal QOS. DD WRT and the like are capable of inbound QOS to some degree via inbound rate shaping. You loose some bandwidth and you can do the same with cisco kit and some creative use of it's rate shaping. It's not as good as QOS but it works.

      --
      No sir I dont like it.
    3. Re:QoS, but only on the Telco Side by Bruha · · Score: 4, Informative

      That is completely false. QOS features have long been supported by CEF and many other ASIC based solutions in Cisco and many other service provider equipment. For many years now it's been there and has been ignored. At my company I have been preaching QOS to make sure that user experience is guaranteed. Routing protocols get first shot, then HTTP(S)/Telnet(SSH)/POP3/IMAP/SMTP etc etc. Every other app is regulated to bulk. Then that 95% will never see latency of problems with their web surfing and even games such as WOW DOOM, Xbox live etc can get priority queues over bulk downloads.

      Once it's done at the network level the same can be applied down to the user level with the packets as they're tagged.

      What we lack is ways for routers to signal upstream routers for dynamic QOS to the customer network.

    4. Re:QoS, but only on the Telco Side by snookums · · Score: 4, Informative

      The article is looking at a download link that is saturated from P2P transfers from other people. In BitTorrent, the more slowly you upload, the more slowly you download. Actually, this is pretty much nonsense. In a heavily contended torrent, with more requests in the cloud than there is upload bandwidth to serve it, then often priority is given to better uploaders. However, on torrents with a good supply of fast seeds and few leechers (e.g. an old torrent with dedicated seeds provided by the content owner) it is very easy to reach the download cap you've set in your client while uploading next to nothing.

      --
      Be careful. People in masks cannot be trusted.
    5. Re:QoS, but only on the Telco Side by supernova_hq · · Score: 4, Funny

      20s?!?
      I'm hoping you meant 20ms...

      That's not even lag, that's simply not being connected to the server!

  4. How clever by blue+l0g1c · · Score: 4, Funny

    Homebrew traffic shaping. *facepalm*

  5. Re:My Roommate owes me 5000g by Midnight+Thunder · · Score: 5, Funny

    Do you know how many times I've died in WoW because of his porn downloading?

    As long as you haven't signed a contract with your roommate, then you could throttle him ;)

    --
    Jumpstart the tartan drive.
  6. Re:Wait, wait wait! by Just+Some+Guy · · Score: 4, Interesting

    So, if the ISPs do traffic shaping "to improve the service" it's bad, but we admit that on the small scale (when it affects ourselfs) there is a real need for traffic shaping!

    I don't mind traffic shaping at all, anywhere. QoS is a good thing, even when the ISPs do it. What I mind a whole awful lot is traffic blocking, ala Comcast.

    --
    Dewey, what part of this looks like authorities should be involved?
  7. Uh, yeah? by Anonymous Coward · · Score: 5, Insightful

    And we admit that on a small scale, we need to control our eating, but we don't want the grocery store telling us how much of things we can buy.

  8. Traffic shaping works but fair-queue works better. by m.dillon · · Score: 4, Interesting

    Traffic shaping and QOS will help a little, but the real problem is simply that you can't afford to delay priority traffic by more then one or two full-sized packets on any connection less then a few megabits (meaning: just about all home interconnects). If you wait any longer then that, it becomes noticeable.

    Traffic shaping and QOS are not usually able to make that guarantee. A straight priority queue with bandwidth guarantees can, as long as you are able to actually classify the torrent traffic differently from your other traffic.

    Part of the problem is that it is often not possible to distinguish between the batch and the interactive traffic with Shaping/QOS. Not only is QOS almost universally set wrong, but the simple fact is that one can mix interactive and batch traffic over the SAME ports (http, ssh, dynamically allocated ports)and that can make it virtually impossible to use traffic shaping or QOS to keep the mess away from your interactive traffic.

    The best general solution is to use a straight priority mechanic with minimum bandwidth settings to separate as much of the bulk traffic out as you can, and then run fair-queueing at each priority level to take care of any that leaks through. This will do a very good job cleaning up the traffic. DragonFly has a fair-queue implementation for PF that does this. There is also at least one fair-queue implementation for PF in the wild.

    Fair-queueing essentially classifies connections (the one in DFly uses PF's keep-state to classify connections), generates a hash and indexes a large array of mini-queues. One packet is then pulled off the head of each mini-queue. One enhancement I would like to make to the DFly implementation which I haven't done yet is to use the keep-state to actually determine which connections are batch and which are interactive, and have a parameter that allows the queue to give additional priority to the interactive connections by occasionally skipping the hoppers related to the batch connections. A quick and dirty way to do that is to simply check the queue length for each mini-queue.

    In anycase, its a problem for which solutions are available. Regardless of what you use it has become apparent in the last few years that the only way one can classify the traffic well enough to properly queue it is by building keep-state knowledge on a connection by connection basis.

    -Matt

  9. Re:My Roommate owes me 5000g by Vectronic · · Score: 5, Funny

    "...then you could throttle him"

    eewww. he no doubt can handle that himself.

  10. Use randomized time rather than even spacing by karl.auerbach · · Score: 5, Informative

    We long ago learned that when inserting time between protocol events that it is far better to use a time randomized between an upper and lower bound than to use a repeating interval.

    When fixed repeating intervals are used, separate instances of a protocol (and other protocols that use repeating intervals) slowly tend to fall into lock-step patterns with pulsating waves of traffic in accord with those patterns.

    In other words, fixed protocol timers can create the traffic equivalent of the Tacoma Narrows bridge.

    By-the-way, ping (ICMP Echo request/reply) is a terrible way to measure network latency. ICMP is often a disfavored form of traffic as it crosses routers, sometimes even rate limited.

    There are better tools for measuring link properties, for example there is "pchar" - http://www.kitchenlab.org/www/bmah/Software/pchar/

    I worked on a method to do even better measurements, but I put it aside several years ago: Fast Path Characterization Protocol at http://www.cavebear.com/archive/fpcp/fpcp-sept-19-2000.html

  11. Re:Simpler solution by flerchin · · Score: 5, Insightful

    Read the bloody article. He shows that bittorent traffic capped to 10% of total bandwidth still causes more latency than an http download using 90% of the pipe. The total latency hit is small, but still significant for VOIP or high intensity gaming.

    --
    --why?
  12. Re:From the Great Geek Philosopher Hypocrates by chubs730 · · Score: 4, Insightful

    When are ethical issues not directly derived from self interest? The issue with throttling at an ISP level is receiving the service one pays for. Bandwidth shaping for a personal network, deciding what one would like to do with the service they purchased, is an entirely separate issue.