-->

Mimic 'slowness' of web server on local co

2020-06-16 06:10发布

问题:

Is it possible to somehow mimic the slower download speeds of my website, as if it is hosted on a web server, but from my localhost?

It's hard to test things like Ajax loading icons when the content loads so quick from your local machine so I think this could help me out a lot?

I was wondering if there was a tool that you could use for this or if you'd need to use javascript to add setTimeout or setInterval code?

回答1:

If you are using Windows, then download the Fiddler tool Fiddler.

This will setup a HTTP proxy that you can use for testing HTTP headers and view all the HTTP traffic within the PC and browser. You can then use the Rules > Performance > Simulate Modem Speeds option to slow the browser's HTTP connection.

There is also a Fiddler Switch plug-in for Firefox available to toggle the Fiddler proxy.



回答2:

First of all, please never mangle your code with if ( DEBUG ) workSlowly(); statements. You will get bitten by this practice, and it will hurt.

Second of all, use one of the traffic throttling solutions which have already been posted here. I'm going to add a Java-based solution: Sloppy. It's dead easy to set up and runs everywhere where Java runs.



回答3:

If you're on a *nix platform, you could alter the 'nice' level to basically make your process an afterthought behind most others until you achieve a level of 'lag' that is satisfactory to your needs.



回答4:

This question may help you out.

Personally, I add something like this at the top of my library file or whatever file always gets included:

if(DEBUG) {
    sleep(2);
}

The above is PHP, but most languages are going to have something similar.



回答5:

One option is (if You are on linux, but other unix system have similar tools) Traffic shaping (google for 'HTB', 'qdics' and 'tc' command)

Second option will be apache_mod_cband module, this is also probably easer to get going.



回答6:

You could try Charles. It's cross platform - I use it and it works really well.

http://www.charlesproxy.com/



回答7:

On windows you can use Proxomitron or you can install fiddler (for ie). Both let you set the download speed.



回答8:

If you use Fiddler 2, you can install this Add-On: Fiddler - Connection Simulator.

It gives you a nice UI to setup Bandwith and different simulation kinds.



标签: hosting