我正在尝试使用限制带宽,tc
并使用检查结果iperf
。我开始是这样的:
# iperf -c 192.168.2.1
------------------------------------------------------------
Client connecting to 192.168.2.1, TCP port 5001
TCP window size: 23.5 KByte (default)
------------------------------------------------------------
[ 3] local 192.168.2.7 port 35213 connected with 192.168.2.1 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-10.0 sec 830 MBytes 696 Mbits/sec
这两个实例通过以太网直接连接。
然后,我htb
qdisc
用一个默认类设置一个将带宽限制为1mbit / sec:
# tc qdisc add dev bond0 root handle 1: htb default 12
# tc class add dev bond0 parent 1: classid 1:12 htb rate 1mbit
但是我没有得到我所期望的:
# iperf -c 192.168.2.1
------------------------------------------------------------
Client connecting to 192.168.2.1, TCP port 5001
TCP window size: 23.5 KByte (default)
------------------------------------------------------------
[ 3] local 192.168.2.7 port 35217 connected with 192.168.2.1 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-12.8 sec 768 KBytes 491 Kbits/sec
如果将速率提高一倍,则测得的带宽不会改变。我想念什么?为什么测量的带宽不对应于rate
参数中的1mbit ?我需要设置哪些参数以将带宽限制为确切的给定速率?
但是,man
页面上说这tbf
应该是qdisc
此任务的选择:
令牌桶过滤器适用于将流量降低到精确配置的速率。可以很好地扩展到大带宽。
tbf
需要的参数rate
,burst
和(limit
| latency
)。因此,我尝试了以下操作,但不了解burst
和(limit
| latency
)如何影响可用带宽:
# tc qdisc add dev bond0 root tbf rate 1mbit limit 10k burst 10k
这为我提供了113 Kbits / sec的测量带宽。玩弄那些参数并没有太大的改变,直到我注意到为值添加一个值mtu
会大幅度改变:
# tc qdisc add dev bond0 root tbf rate 1mbit limit 10k burst 10k mtu 5000
导致测得的带宽为1.00 Mbits / sec。
我需要设置哪些参数以将带宽限制为确切的给定速率?
我应该为此使用htb
or tbf
排队规则吗?
编辑:
基于这些资源,我进行了一些测试:
- https://help.ubuntu.com/community/UbuntuBonding
- https://help.ubuntu.com/community/LinkAggregation
- /usr/share/doc/ifenslave-2.6/README.Debian.gz http://lartc.org/
我尝试了以下设置。
在物理机器上
/etc/network/interfaces
:
auto lo
iface lo inet loopback
auto br0
iface br0 inet dhcp
bridge_ports eth0
测量iperf
:
# tc qdisc add dev eth0 root handle 1: htb default 12
# tc class add dev eth0 parent 1: classid 1:12 htb rate 1mbit
# iperf -c 192.168.2.1
------------------------------------------------------------
Client connecting to 192.168.2.1, TCP port 5001
TCP window size: 23.5 KByte (default)
------------------------------------------------------------
[ 3] local 192.168.2.4 port 51804 connected with 192.168.2.1 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-11.9 sec 1.62 MBytes 1.14 Mbits/sec
而iperf
服务器计算了不同的带宽:
[ 4] local 192.168.2.1 port 5001 connected with 192.168.2.4 port 51804
[ 4] 0.0-13.7 sec 1.62 MBytes 993 Kbits/sec
在没有绑定的虚拟机上
/etc/network/interfaces
:
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
测量iperf
:
# tc qdisc add dev eth0 root handle 1: htb default 12
# tc class add dev eth0 parent 1: classid 1:12 htb rate 1mbit
# iperf -c 192.168.2.1
------------------------------------------------------------
Client connecting to 192.168.2.1, TCP port 5001
TCP window size: 23.5 KByte (default)
------------------------------------------------------------
[ 3] local 192.168.2.7 port 34347 connected with 192.168.2.1 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-11.3 sec 1.62 MBytes 1.21 Mbits/sec
而iperf
服务器计算了不同的带宽:
[ 4] local 192.168.2.1 port 5001 connected with 192.168.2.7 port 34347
[ 4] 0.0-14.0 sec 1.62 MBytes 972 Kbits/sec
在具有绑定的虚拟机上(在eth0上配置了tc)
/etc/network/interfaces
:
auto lo
iface lo inet loopback
auto eth0
allow-bond0 eth0
iface eth0 inet manual
bond-master bond0
bond-primary eth0 eth1
auto eth1
allow-bond0 eth1
iface eth1 inet manual
bond-master bond0
bond-primary eth0 eth1
auto bond0
iface bond0 inet dhcp
bond-slaves none
bond-mode 1
# bond-arp-interval 250
# bond-arp-ip-target 192.168.2.1
# bond-arp-validate 3
测量iperf
:
# tc qdisc add dev eth0 root handle 1: htb default 12
# tc class add dev eth0 parent 1: classid 1:12 htb rate 1mbit
# iperf -c 192.168.2.1
------------------------------------------------------------
Client connecting to 192.168.2.1, TCP port 5001
TCP window size: 23.5 KByte (default)
------------------------------------------------------------
[ 3] local 192.168.2.9 port 49054 connected with 192.168.2.1 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-11.9 sec 1.62 MBytes 1.14 Mbits/sec
而iperf
服务器计算了不同的带宽:
[ 4] local 192.168.2.1 port 5001 connected with 192.168.2.9 port 49054
[ 4] 0.0-14.0 sec 1.62 MBytes 972 Kbits/sec
在具有绑定的虚拟机上(在bond0上配置了tc)
/etc/network/interfaces
:
auto lo
iface lo inet loopback
auto eth0
allow-bond0 eth0
iface eth0 inet manual
bond-master bond0
bond-primary eth0 eth1
auto eth1
allow-bond0 eth1
iface eth1 inet manual
bond-master bond0
bond-primary eth0 eth1
auto bond0
iface bond0 inet dhcp
bond-slaves none
bond-mode 1
# bond-arp-interval 250
# bond-arp-ip-target 192.168.2.1
# bond-arp-validate 3
测量iperf
:
# tc qdisc add dev bond0 root handle 1: htb default 12
# tc class add dev bond0 parent 1: classid 1:12 htb rate 1mbit
# iperf -c 192.168.2.1
------------------------------------------------------------
Client connecting to 192.168.2.1, TCP port 5001
TCP window size: 23.5 KByte (default)
------------------------------------------------------------
[ 3] local 192.168.2.9 port 49055 connected with 192.168.2.1 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-13.3 sec 768 KBytes 475 Kbits/sec
而iperf
服务器计算了不同的带宽:
[ 4] local 192.168.2.1 port 5001 connected with 192.168.2.9 port 49055
[ 4] 0.0-14.1 sec 768 KBytes 446 Kbits/sec
如果我eth1
从绑定中删除(被动接口),结果不会改变。
结论
绑定接口上的流量控制不起作用,或者至少不符合预期。我将不得不进一步调查。
作为一种解决方法,可以将排队规则直接添加到属于绑定的接口中。
tc filter
将数据包放入类中。您可能还需要更改一些htb参数(像tbf一样对其进行调整)。我建议研究tcng
,这是tc的前端。(这些是快速指点...)