开发者

How to slow down file downloads on local ruby webserver?

I'd like to mock large (>100MB) and slow file downloads locally by a ruby service - rails, sinatra, rack or something else.

After starting server and writing something like: http://localhost:30开发者_如何学JAVA00/large_file.rar, I'd like to slooowly download a file (for testing purposes).

My question is, how to throttle local webserver to certain maximum speed? Because if file is stored locally, it will by default download very fast.


You should use curl for this, which allows you to specify a maximum transfer speed with the --limit-rate option. The following would download a file at about 10KB per second:

curl --limit-rate 10K http://localhost:3000/large_file.rar

From the documentation:

The given speed is measured in bytes/second, unless a suffix is appended. Appending ‘k’ or ‘K’ will count the number as kilobytes, ‘m’ or M’ makes it megabytes, while ‘g’ or ‘G’ makes it gigabytes. Examples: 200K, 3m and 1G.

The given rate is the average speed counted during the entire transfer. It means that curl might use higher transfer speeds in short bursts, but over time it uses no more than the given rate.

More examples here (search for "speed limit"): http://www.cs.sunysb.edu/documentation/curl/index.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜