Simulating Slow Internet Connection

2020-01-24 19:07发布

问题:

I know this is kind of an odd question. Since I usually develop applications based on the "assumption" that all users have a slow internet connection. But, does anybody think that there is a way to programmatically simulate a slow internet connection, so I can "see" how an application performs under various "connection speeds"?

I'm not worried about which language is used. And I'm not looking for code samples or anything, just interested in the logic behind it.

回答1:

If you're running windows, fiddler is a great tool. It has a setting to simulate modem speed, and for someone who wants more control has a plugin to add latency to each request.

I prefer using a tool like this to putting latency code in my application as it is a much more realistic simulation, as well as not making me design or code the actual bits. The best code is code I don't have to write.

ADDED: This article at Pavel Donchev's blog on Software Technologies shows how to create custom simulated speeds: Limiting your Internet connection speed with Fiddler.



回答2:

Starting with Chrome 38 you can do this without any plugins. Just click inspect element (or F12 hotkey), then click on "toggle device mod" and you will see something like this:

Among many other features it allows you to simulate specific internet connection (3G, GPRS)

P.S. for people who try to limit the upload speed. Sadly at the current time it is not possible.

P.S.2 now you do not need to toggle anything. Throttling panel is available right from the network panel.

Note that while clicking on the No throttling you can create your custom throttling options.



回答3:

Google recommends:

  • Network Link Conditioner on OSX
  • Clumsy on Windows
  • Dummynet on Linux


回答4:

I was using http://www.netlimiter.com/ and it works very well. Not only limit speed for single processes but also shows actual transfer rates.



回答5:

On Linux machines u can use wondershaper

apt-get install wondershaper

$ sudo wondershaper {interface} {down} {up}

the {down} and {up} are bandwidth in kpbs

So for example if you want to limit the bandwidth of interface eth1 to 256kbps uplink and 128kbps downlink,

$ sudo wondershaper eth1 256 128

To clear the limit,

$ sudo wondershaper clear eth1 


回答6:

There are TCP proxies out there, like iprelay and Sloppy, that do bandwidth shaping to simulate slow connections. You can also do bandwidth shaping and simulate packet loss using IP filtering tools like ipfw and iptables.



回答7:

You can try Dummynet, it can simulates queue and bandwidth limitations, delays, packet losses, and multipath effects



回答8:

Use a web debugging proxy with throttling features, like Charles or Fiddler.

You'll find them useful web development in general. The major difference is that Charles is shareware, whereas Fiddler is free.



回答9:

Also, for simulating a slow connection on some *nixes, you can try using ipfw. More information is provided by Ben Newman's answer on this Quora question



回答10:

Use a tool like TCPMon. It can fake a slow connection.

Basically, you request it the exact same thing and it just forwards the exact same request to the real server, and then delays the response with only the set amount of bytes.



回答11:

You can use NetEm (Network Emulation) as a proxy server to emulate many network characteristics (speed, delay, packet loss, etc.). It controls the networking using iproute2 package and it's enabled in the kernel of the most Linux distributions.

It is controlled by the tc command-line application (from the iproute2 package), but there are also some web interface GUIs for NetEm, for example PHPnetemGUI2.

The advantage is that, as I wrote, it can emulate not only different network speeds but also, for example, the packet loss, duplication and/or corruption, random or defined delay, etc., so you can emulate various poorly performing networks.

For your application it's absolutely transparent, you can configure the operating system to use the NetEm proxy server, so all connections from that machine will go trough NetEm. Or you can configure only your application to use it as a proxy.

I have been using it to test the performance of an Android app on various emulated poor-performance networks.



回答12:

Mac OSX since 10.10 has an app called Murus Firewall, which acts as a GUI to pf, the replacement for ipfw.

It works very well for system-wide or domain-specific throttling. I was just able to use it to slide my download speed between 300Kbps and 30Mbps to test how a streaming video player adjusts.



回答13:

There is also another tool called WIPFW - http://wipfw.sourceforge.net/

It's a bit old school, but you can use it to simulate a slower connection. It's Windows based, and the tool allows the administrator to monitor how much traffic the router is getting from a certain machine, or how much WWW traffic it is forwarding, for example.



回答14:

Updating this (9 years after it was asked) as the answer I was looking for wasn't mentioned:

Firefox also has presets for throttling connection speeds. Find them in the Network Monitor tab of the developer tools. Default is 'No throttling'.

Slowest is GPRS (Download speed: 50 Kbps, Upload speed: 20 Kbps, Minimum latency (ms): 500), ranging through 'good' and 'regular' 2G, 3G and 4G to DSL and WiFi (Download speed: 30Mbps, Upload speed: 15Mbps, Minimum latency (ms): 2).

More in the Dev Tools docs.



回答15:

For Linux, the following list of papers might be useful:

  • A Comparative Study of Network Link Emulators (2009)
  • KauNet: A Versatile and Flexible Emulation System (2009)
  • Dummynet Revisited (2010)
  • Measuring Accuracy and Performance of Network Emulators (2015)

Personally, whilst Dummynet is good, I find NetEm to be the most versatile for my use-cases; I'm usually interested in the effect of delays, rather than bandwidth (i.e. WiFi connection issues), and it's super-easy to emulate random packet loss/corruption, etc. It's also very accessible, and free (unlike the hardware-based Linktropy).

On a side-note, for Windows, Clumsy is awesome. I would also like to add that (regarding websites) browser throttling is not an accurate method for emulating real-life network issues (I think "TKK" commented on a few of the reasons why above).

Hope this helps someone!