voidfuchsia.com

  • photography
  • code
Home › Blogs › voidfuchsia's blog

BitTorrent affecting the latency of your other (and sometimes more important and work related) traffic?

voidfuchsia — Sun, 09/06/2009 - 23:03

Are you having problems with BitTorrent lagging anything else you do on the network? Are you a level 80 Rogue in World of Warcraft that can't comprehend 300-500ms of lag because your Slice and Dice will drop? Did that idiot ally just PWN you because you wanted to get a movie for your girlfriend (cuz we all know grrls don't play WoW ;) )?

If you answered yes to any of the above questions, then this article is for you. Sit back, relax, and rescue your spare 4 year old 2.4Ghz P4 from being used as an end-table and get rid of network latency at the same time!

Things you'll need:
* spare 2.0Ghz+ system (I used an old 2.4Ghz w/1GB of 400Mhz RDRAM and a 20GB HD and 2 random "found around the house" network cards"
* The Vyatta Community Edition installation disk (burn it from the iso found on http://www.vyatta.com)
* As many spare network cards as you want to traffic across
* A spare night on the weekend to tweak all your settings

First - throw your network cards into the system and boot the Vyatta CD. It'll give you a nice login prompt and not much else. Log in with username vyatta password vyatta. Once you're in, type 'install-system" hit enter, and follow the prompts to set it up on your superOld hard drive (with all defaults except custom passwords and users etc). Reboot and continue with step 2.

Second - I'm going to assume that you probably needed your existing ISP connection so you can read l33t tutorials like this one, so hopefully you just connected one of the network cards that you don't plan on using for your ISP connection into a spare port on your switch. If this is not the case, you should do so - you can set Vyatta up entirely and switch it for your router once you're done (especially if you're cool enough to have a static IP, which is what this 'tutorial' covers. If you need pppoe or dhcp from your ISP, that's covered in a ton of other tutorials online, but if you get stuck, please feel free to email me at cryptographrix@gmail.com. Worst case scenario, hit the 'Call Me' button on the right hand side of this page and I'll try to help over the phone.).

Third - now that you've rebooted into your live installation (you remembered to remove the installation CD after the install completed, right?), you get to learn how to set up rudimentary network access and web interface - after all, you don't want to type EVERYTHING to set this up, do ya?

To do this, type 'show interfaces' at the prompt and hit enter. Vyatta does tab completion for all builtin commands, so you should really just do 'sh(tab) int(tab)' and you'll end up with 'show interfaces'...regardless, here's something like what the output should look like:

vyatta@gateway:~$ show interfaces
Interface    IP Address         State       Link   Description
eth0         -                        up          up
eth1         -                        up          up
eth2          -                       up          up     Cable Internet
lo           127.0.0.1/8        up          up
lo           ::1/128            up          up

One of those ethernet interfaces is where your switch is connected. To figure out which one is connected, type 'dmesg' and hit enter and look at the end of the dmesg output to see which one has a link.

Once you've figured that out, you gotta set it up with an ip. To do this, type 'configure' and hit enter. You'll be greeted by a friendly [edit] prompt. Violate the poor prompt by typing the following:

set interfaces ethernet (ethPortThatsConnected) address (arbitraryIPaddress)/24 (or whatever your subnet mask is)
set service https
commit
exit

The second 'set' command turned on https access. Once you've committed, you should be able to go to your main workstation, sit down and access the router by opening up a browser and going to https://(VyattaIPAddress). Use the non-root username and password you set up at installation to login (you did set up a non-root user, right?).

If everything went to plan, you should be staring at a screen of every single Vyatta option you could ever set. Go to Service->Nat and turn that on. Go to Service->DHCP-server and turn that on. While you're there, turn on SSH if you want. Once you're done turning on all of the services you're going to eventually configure, hit 'Commit.' (changes only get queued until you commit them, and unless you save them, you'll have to re-enter them at boot, so I suggest you hit save after every time you make significant changes that you've verified.)

Fourth - I'm not going to cover the basics of routing and IP assignment here. That's covered in sooo many online tutorials that it's redundant. You're reading this for the QoS capabilities of Vyatta, so that's what I'm going to cover. All I can say about routing is that if you're using a static IP, your static route under Protocols->Static->Route should be 0.0.0.0/0 or you'll never get anywhere.

So...QoS....here is what the QoS policy for outbound on my cable modem port looks like:

  qos-policy {
      traffic-shaper CableInternet {
          bandwidth 20mbit
          class 10 {
              bandwidth 50%
              burst 15k
              ceiling 75%
              description "Matches WoW port"
              match WowPort {
                  ip {
                      destination {
                          port 3724
                      }
                  }
              }
              queue-type fair-queue
          }
          class 20 {
              bandwidth 20%
              burst 15k
              ceiling 30%
              description "Matches HTTP port"
              match HTTPPort {
                  ip {
                      destination {
                          port 80
                      }
                  }
              }
              queue-type fair-queue
          }
          class 30 {
              bandwidth 5%
              burst 15k
              ceiling 10%
              description "Matches HTTPS port"
              match HTTPSPort {
                  ip {
                      destination {
                          port 443
                      }
                  }
              }
              queue-type fair-queue
          }
          default {
              bandwidth 5%
              burst 15k
              ceiling 8%
              queue-type fair-queue
          }
          description "This policy covers all latency-sensitive applications."
      }
  }

Basically, I use port matching to prioritize WoW, HTTP, and HTTPS. Everything else gets 5% of my bandwidth (20Mbit) with a ceiling of 8%.

But wait - this tutorial is about bittorrent, right? Where are my manners????.....

It turns out that one of the behaviors of the traffic-shaper is that if a match goes overlimit, the traffic shaper increases its latency to make up for it (or something like that - read http://luxik.cdi.cz/~devik/qos/htb/manual/userg.htm#prio).

As a result, if you prioritize BitTorrent traffic just like all the other traffic in your house (let's say you got everyone to agree to use ONLY ports x,y,z or some other method that ensures that you CAN make a match), and let's say, just for a couple seconds, someone decides to watch a video online or something, their latency will take a hit by torrent traffic as the traffic-shaper increases the latency of their stream due to going overlimit. In this case, it makes sense to prioritize ONLY the stuff that is latency-sensitive, because the traffic shaper will basically shove non-prioritized stuff into the lowest 'queue,' ('default' in this example) and you can give prioritized traffic higher limits to ensure that they go overlimit as rarely as possible.

I found myself asking 'won't that kill my Torrent download/upload speeds?' so I ran a little test. Turns out that I can be downloading/uploading without any caps, and at almost any rate (even more than when I didn't have a router with QoS), and if I do something on any prioritized protocol, the torrent latency just takes a hit (think: it's almost always going to be overlimit)....which is fine with me - When I want to torrent something, I don't usually care that torrenting varies speeds so long as the latency on foreground applications doesn't get hit too much.

Thing is, with the Vyatta traffic shaper you're basically prioritizing what you use. I.e. - if you REALLLY really care about your AIM latency, you're going to have to search on google to find out what port it uses/how to match it etc., and you're going to have to create the match rules under your qos-policy.

Anyway, yeah - this isn't too formal, but it's a basic introduction to QoS on Vyatta, and how I solved the 'bittorrent vs. other traffic' dilemma. Feel free to comment, etc.

Technorati Tags:Technorati Tags: bittorrent fair-queue HTB qos Technology traffic-shaper vyatta
  • bittorrent
  • fair-queue
  • HTB
  • qos
  • Technology
  • traffic-shaper
  • vyatta
  • voidfuchsia's blog
  • Login or register to post comments

Navigation

  • Recent posts

User login

  • Create new account
  • Request new password

Flickr

  • No photos found
  • photography
  • code