5 ms·
Add Latency to Localhost
A short post on using tc to simulate high latency connections on a local box.
- burgerbrain 16y agoqdiscs 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 16y agoThis was apparently last updated in 2009: http://www.linuxfoundation.org/collaborate/workgroups/networking/netem http://www.linuxfoundation.org/collaborate/workgroups/networ...
- joshuacc 16y agoAnyone 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 16y agoHost the app on a local Linux VM perhaps?
- joelhaasnoot 16y agoThis 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.
- rayvega 16y agoUnfortunately, 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:YJ8bhlDGpkAJ:www.iet.unipi.it/~luigi/ip_dummynet/+dummynet&cd=1&hl=en&ct=clnk&gl=us 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 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.
- teej 16y agoCharles (http://www.charlesproxy.com http://www.charlesproxy.com) is cross platform and does latency, among a dozen other really useful things.
- Yrlec 16y agoIf you only want it for http you could use Fiddler (http://www.fiddler2.com http://www.fiddler2.com)
- mquander 16y agoI've used TMNetSim here, which also lets you simulate variable latency and packet loss: http://tmurgent.com/Tools.aspx http://tmurgent.com/Tools.aspx
- suraj 16y agoIf you have a spare machine, you can use WanEm http://wanem.sourceforge.net/ 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.
- delano 16y agoOn 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
- MikeCapone 16y agoCould 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 16y agoI've encountered bugs that were not reproducible due to the speed of local socket connections. I had to use a remote server to debug.
- JonnieCache 16y agoFor 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.
- jallmann 16y agoTesting 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.
- pasbesoin 16y agoPark a "chatty" protocol host on the other side of the planet. (E.g. a rich client.) Watch latency kill performance.
- dbotha 16y agoI'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.
- xtacy 16y agoMininet 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/Mininet http://www.openflowswitch.org/foswiki/bin/view/OpenFlow/Mini... Paper: http://conferences.sigcomm.org/hotnets/2010/papers/a19-lantz.pdf http://conferences.sigcomm.org/hotnets/2010/papers/a19-lantz... Other similar projects: * http://clownix.net/ * http://www-x.antd.nist.gov/nistnet/
- huhtenberg 16y agoClosely related - http://kerneltrap.org/node/467 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 :)
- deleted 16y ago[deleted]
- s3graham 16y agoiprelay too: iprelay -b30000 8000:localhost:80
- jws 16y agoDo 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 16y agoip link set lo mtu 1500
- jtchang 16y agoFor 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.