是否可以限制wget
或curl
的下载速度?
是否可以在下载时更改节流阀值?
发布于 2012-05-23 05:00:17
是的,wget和curl都支持限制您的下载速度。这两个选项都直接在手册页中提到。
--limit-rate <speed> Specify the maximum transfer rate you want curl to use. This feature is useful if you have a limited pipe and you'd like your transfer not to use your entire bandwidth. 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.
例如:curl --limit-rate 423K
--limit-rate=amount Limit the download speed to amount bytes per second. Amount may be expressed in bytes, kilobytes with the k suffix, or megabytes with the m suffix. For example, --limit-rate=20k will limit the retrieval rate to 20KB/s. This is useful when, for whatever reason, you don't want Wget to consume the entire available bandwidth.
例如:wget --limit-rate=423k
发布于 2013-06-05 01:43:02
可以使用tc
和netem
工具限制通信速率,但这将限制计算机网络接口的速率。我假设您只使用wget
或curl
,而没有其他应用程序通过网络接口交换流量。
tc
使用令牌桶过滤器(TBF)来控制速率。
TBF的一个例子如下(参考文献)。http://www.lartc.org/manpages/tc-tbf.html):
若要附加一个最高速率为0.5mbit/s的TBF,峰值速率为1.0mbit/s的5千字节缓冲区,并计算预桶队列大小限制,以使TBF导致最多70 most的延迟,并具有完美的峰值行为,请发布以下问题:
# tc qdisc add dev eth0 root tbf rate 0.5mbit \ burst 5kb latency 70ms peakrate 1mbit \ minburst 1540
usign和netem的另一个示例如下(在http://www.linuxfoundation.org/collaborate/workgroups/networking/netem中找到):
没有内置到netem纪律的速率控制,而是使用其他执行速率控制的学科之一。在这个例子中,我们使用令牌桶过滤器(TBF)来限制输出。
添加每个数据包通过接口eth0的延迟
# tc qdisc add dev eth0 root handle 1:0 netem delay 100ms
添加tbf中的数据速率、数据包缓冲区大小和最大突发限制。
# tc qdisc add dev eth0 parent 1:1 handle 10: tbf rate 256kbit buffer 1600 limit 3000
查看在tc中为接口eth0分配的规则列表
# tc -s qdisc ls dev eth0
上述命令的输出如下所示
qdisc netem 1: limit 1000 delay 100.0ms
Sent 0 bytes 0 pkts (dropped 0, overlimits 0 )
qdisc tbf 10: rate 256Kbit burst 1599b lat 26.6ms
Sent 0 bytes 0 pkts (dropped 0, overlimits 0 )
检查缓冲区和限制选项,因为您可能会发现您需要比这些(它们是字节)更大的默认值。
https://unix.stackexchange.com/questions/39218
复制