Hacker News new | past | comments | ask | show | jobs | submit login
Add Latency to Localhost (haxx.se)
126 points by turbodog on Dec 14, 2010 | hide | past | favorite | 23 comments



On FreeBSD and OSX, you can use ipfw:

    sudo ipfw pipe 1 config bw 50KBytes/s delay 100ms
    sudo ipfw add 1 pipe 1 src-port 80
    sudo ipfw add 2 pipe 1 dst-port 80
But don't forget to disable it!

    sudo ipfw delete 1
    sudo ipfw delete 2


Mininet is a project at Stanford that provides an API to emulate a multi-node network on a single machine. It uses linux containers and namespaces for configuration/resource isolation.

Project page: http://www.openflowswitch.org/foswiki/bin/view/OpenFlow/Mini...

Paper: http://conferences.sigcomm.org/hotnets/2010/papers/a19-lantz...

Other similar projects:

  * http://clownix.net/
  * http://www-x.antd.nist.gov/nistnet/


Closely related - http://kerneltrap.org/node/467 - FreeBSD network stack virtualization, though it seems to be RiP now.

It is (was) not the only implementation of the idea that is as basic as it is extremely useful for testing in complex network setups.

All network stack variables (i.e. settings and state) are gather in one big struct and all network stack functions operate exclusively on the contents of this stack. Every process has one stack instance assigned to it by default and it may switch to another instance at any time. There are no changes to any socket-level API, all calls function exactly as before, but they are executed in the context of process' effective stack.

Process' default stack is inherited from the parent process, and this makes it trivial to run any existing application in a context of specific stack (by launching it from a process that selects desired stack and then does the exec).

At the bottom each stack connects to one or more network interfaces. Stacks may connect to the physical devices (multiple stacks per device is OK as long as it supports promiscuous mode), or they may connect to a virtual interface. Virtual interfaces in turn may have their inputs and outputs meshed together via hubs, switches or direct links, all of which may in turn be configured to emulate packet loss, latency, jitter and what not.

That's your basic network stack virtualization. Functioning version can be assembled from a forked Linux source in a couple of weekends. If only someone would bother submitting the patch after that :)


Anyone know a good way to replicate this in Windows? Would be great to have a more user-like experience when working on my Rails app.


Charles (http://www.charlesproxy.com) is cross platform and does latency, among a dozen other really useful things.


Unfortunately, I'm unaware of how to do this natively but I recommend using Dummynet which has a Windows port of the FreeBSD networking tool. Oddly, their website appears to be down so here is the Google cache:

http://webcache.googleusercontent.com/search?q=cache:YJ8bhlD...

You need to install the drivers but once done you effectively use the same commands with ipfw as on FreeBSD (as described in another thread http://news.ycombinator.com/item?id=2005190). I just used it for the first time the other day to test a web app browsing with a 400ms delay on a WinXP machine. It worked like a charm.


Host the app on a local Linux VM perhaps?


This is what I do and it works perfectly. I use VirtualBox and can stop any of the servers at any time and reduce my memory/CPU footprint for other activities. VirtualBox also lets me configure the network easily.


If you only want it for http you could use Fiddler (http://www.fiddler2.com)


If you have a spare machine, you can use WanEm http://wanem.sourceforge.net/ livecd. WanEm gives you a nice web interface to configure network parameters. I have used it successfully to check effects of latency on Lotus Notes on Windows.


I've used TMNetSim here, which also lets you simulate variable latency and packet loss:

http://tmurgent.com/Tools.aspx


Do be aware that your linux loopback has an MTU an order of magnitude greater than ethernet, so your latency sensitive TCP startup times are not going to behave the same.


  ip link set lo mtu 1500


Could anyone explain why that would be desirable? Is it to test out a website design that you are hosting locally, and you want it to "feel" right? Something else?


I've encountered bugs that were not reproducible due to the speed of local socket connections. I had to use a remote server to debug.


Testing protocol implementations. I had a recent bug where the speed on localhost was masking a race condition between the packet reader and parser. Only caught it when testing over the Internet.

Basically you want full control over your simulation parameters.


For the development/testing of any client-server app where you anticipate deployment to a network with variable latency. In 2010 this means websites.

Mostly to simulate the real-world UX of ajax sites that have a lot of server roundtrips.

It's vital in these kind of interfaces for everything to happen before the magic 150ms threshold of perceived instantaneousness.


I'm currently developing a multiplayer game and use this (although with additional arguments to include variation/jitter and packet loss) to simulate somewhat more realistic network conditions. I find it's great for exposing bugs in the networking protocol that would otherwise only arise under poorer network conditions.


Park a "chatty" protocol host on the other side of the planet. (E.g. a rich client.)

Watch latency kill performance.


qdiscs in linux have always seems something of an underdocumented dark art to me. I've used HTB to slow down packets that I mark with iptable rules, but that's about as fancy as I can get. Does anybody know of some nice documentation about this stuff that isn't a decade old? ;)



For those on FreeBSD dummynet was perhaps one of the most useful traffic shapers I've ever used. I had a router built on FreeBSD going strong for more than 3 years on an old pentium 90 that would route traffic like no ones business.


iprelay too:

    iprelay -b30000 8000:localhost:80




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: