

Add Latency to Localhost - turbodog
http://daniel.haxx.se/blog/2010/12/14/add-latency-to-localhost/
A short post on using tc to simulate high latency connections on a local box.
======
delano
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

------
xtacy
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...](http://www.openflowswitch.org/foswiki/bin/view/OpenFlow/Mininet)

Paper:
[http://conferences.sigcomm.org/hotnets/2010/papers/a19-lantz...](http://conferences.sigcomm.org/hotnets/2010/papers/a19-lantz.pdf)

Other similar projects:

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

~~~
huhtenberg
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 :)

------
joshuacc
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.

~~~
turbodog
Host the app on a local Linux VM perhaps?

~~~
joelhaasnoot
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.

------
jws
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.

~~~
huhtenberg

      ip link set lo mtu 1500

------
MikeCapone
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?

~~~
johnrob
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.

------
burgerbrain
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? ;)

~~~
samstokes
This was apparently last updated in 2009:

[http://www.linuxfoundation.org/collaborate/workgroups/networ...](http://www.linuxfoundation.org/collaborate/workgroups/networking/netem)

------
jtchang
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.

------
s3graham
iprelay too:

    
    
        iprelay -b30000 8000:localhost:80

