Gau*_*tam 128 networking download wget curl
是否可以节流(限制)wget或的下载速度curl?
下载时是否可以更改节流值?
Ulr*_*gel 168
是的 wget 和 curl 都支持限制您的下载速度。手册页中直接提到了这两个选项。
Run Code Online (Sandbox Code Playgroud)--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
Run Code Online (Sandbox Code Playgroud)--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
小智 7
两年后我会抛出这么一个小节目中,而wget并curl没有互动,至少wget(以及可能的curl,但我不肯定知道)具有-c开关(代表从我离开的下载较早的地方继续)。因此,如果您需要在下载过程中更改速度,并且您大概使用了-c带有 的开关,--limit-rate=x那么您可以停止wget并以不同的速度重新启动它,它会改变。
小智 5
可以使用tc和netem工具限制流量速率,但这将限制计算机网络接口的速率。我假设您只使用wget或curl没有其他应用程序通过网络接口交换流量。
tc 使用令牌桶过滤器(TBF)来控制速率。
TBF 的一个示例如下(参考http://www.lartc.org/manpages/tc-tbf.html):
以 0.5mbit/s 的持续最大速率、1.0mbit/s 的峰值速率、5 KB 的缓冲区附加 TBF,并计算预存储队列大小限制,因此 TBF 最多会导致 70 毫秒的延迟,并具有完美的峰值速率行为, 问题:
# tc qdisc add dev eth0 root tbf rate 0.5mbit \ burst 5kb latency 70ms peakrate 1mbit \ minburst 1540
Run Code Online (Sandbox Code Playgroud)
另一个使用 tc 和 netem 的例子如下(在http://www.linuxfoundation.org/collaborate/workgroups/networking/netem中找到):
netem 学科没有内置速率控制,而是使用其他进行速率控制的学科之一。在本例中,我们使用令牌桶过滤器 (TBF) 来限制输出。
添加通过接口 eth0 的每个数据包的延迟
# tc qdisc add dev eth0 root handle 1:0 netem delay 100ms
Run Code Online (Sandbox Code Playgroud)
以 tbf 为单位添加数据速率、数据包缓冲区大小和最大突发限制
# tc qdisc add dev eth0 parent 1:1 handle 10: tbf rate 256kbit buffer 1600 limit 3000
Run Code Online (Sandbox Code Playgroud)
查看 tc 中为接口 eth0 分配的规则列表
# tc -s qdisc ls dev eth0
Run Code Online (Sandbox Code Playgroud)
上述命令的输出如下
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 )
Run Code Online (Sandbox Code Playgroud)
检查缓冲区和限制的选项,因为您可能会发现需要比这些更大的默认值(它们以字节为单位)