Simulating Slow Internet Connection

前端 未结 16 1588
深忆病人
深忆病人 2020-11-27 09:30

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 th

相关标签:
16条回答
  • 2020-11-27 10:10

    One common case of shaping a single TCP connection can actually be assembled from dual pairs of socat and cpipe in UNIX fashion like this:

    socat TCP-LISTEN:5555,reuseaddr,reuseport,fork SYSTEM:'cpipe -ngr -b 1 -s 10 | socat - "TCP:localhost:5000" | cpipe -ngr -b 1 -s 300'

    This simulates a connection with bandwidth of approximately 300kB/s from your service at :5000 and to at approximately 10kB/s and listens on :5555 for incoming connections. Caveat: Note that this per-connection, so each individual TCP connection gets this amount.

    Explanation: The outer (left) socat listens with the given options on :5555 as a forking server. The first cpipe command in the SYSTEM:... option then throttles data that went into socket :5555 (and comes out of the first, outer socat) to at most 10kByte/s. That data is then forwarding using another socat which connects to localhost:5000 (where the service you want to slow down should be listening). Data from localhost:5000 is then put into the right cpipe command, which (with the given values) throttles it to about 300kB/s.

    The option -ngr to cpipe is important. It causes cpipe to read non-greedily from its input file-descriptor. Otherwise, you might get stuck with data in the buffers not being forwarded and waiting for a reply.

    Using the more common buffer tool instead of cpipe is likely possible as well.

    (Credits: This is based on the "double-tee" recipe by Christophe Loor from the socat documentation)

    0 讨论(0)
  • 2020-11-27 10:11

    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!

    0 讨论(0)
  • 2020-11-27 10:13

    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.

    0 讨论(0)
  • 2020-11-27 10:15

    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.

    0 讨论(0)
提交回复
热议问题