这里我们简单描述下如何通过Open vSwitch给虚拟机限流(出流量),同时测试限流效果。测试环境继续复用《整合Open vSwitch与DNSmasq为虚拟机提供DHCP功能》一文中描述的。
测试工具:假设两台虚拟机VM1、VM2都已经安装好 netperf
1、事先在VM1中启动 netserver:
2、由于VM2的虚拟网卡是tap1,这里先查看下当前tap1网卡的情况:
◄► sudo ovs-vsctl list interface tap1
_uuid : aa4b7e2b-44b9--ab02-909d66fc4333
admin_state : up
bfd : {}
bfd_status : {}
cfm_fault : []
cfm_fault_status : []
cfm_health : []
cfm_mpid : []
cfm_remote_mpids : []
cfm_remote_opstate : []
duplex : full
external_ids : {attached-mac="52:54:00:f9:b6:b1", iface-id="0c9430f2-87ca-4ca2-92c8-2968ddfb2947", iface-status=active, vm-id="8d910a8b-726b-833d-3420-7da607486336"}
ifindex :
ingress_policing_burst: 0
ingress_policing_rate: 0
lacp_current : []
link_resets :
link_speed :
link_state : up
mac : []
mac_in_use : "fe:54:00:f9:b6:b1"
mtu :
name : "tap1"
ofport :
ofport_request : []
options : {}
other_config : {}
statistics : {collisions=, rx_bytes=, rx_crc_err=, rx_dropped=, rx_errors=, rx_frame_err=, rx_over_err=, rx_packets=, tx_bytes=, tx_dropped=, tx_errors=, tx_packets=}
status : {driver_name=tun, driver_version="1.6", firmware_version=""}
type : ""
这里的 ingress_policing_rate 和 ingress_policing_burst 值全为0,则表示 不限流。
3、在 不限流 的情况下,从VM2中通过 netperf 测试的情况如下:
从上面的Throughput来看,出流量差不多打到了 11Gbps。
4、此时,我们通过 ovs 将 tap1 的带宽限制在 1M:
◄► sudo ovs-vsctl set interface tap1 ingress_policing_burst=
◄► sudo ovs-vsctl set interface tap1 ingress_policing_rate=
◄► sudo ovs-vsctl list Interface tap1
_uuid : aa4b7e2b-44b9--ab02-909d66fc4333
admin_state : up
bfd : {}
bfd_status : {}
cfm_fault : []
cfm_fault_status : []
cfm_health : []
cfm_mpid : []
cfm_remote_mpids : []
cfm_remote_opstate : []
duplex : full
external_ids : {attached-mac="52:54:00:f9:b6:b1", iface-id="0c9430f2-87ca-4ca2-92c8-2968ddfb2947", iface-status=active, vm-id="8d910a8b-726b-833d-3420-7da607486336"}
ifindex :
ingress_policing_burst:
ingress_policing_rate:
lacp_current : []
link_resets :
link_speed :
link_state : up
mac : []
mac_in_use : "fe:54:00:f9:b6:b1"
mtu :
name : "tap1"
ofport :
ofport_request : []
options : {}
other_config : {}
statistics : {collisions=, rx_bytes=, rx_crc_err=, rx_dropped=, rx_errors=, rx_frame_err=, rx_over_err=, rx_packets=, tx_bytes=, tx_dropped=, tx_errors=, tx_packets=}
status : {driver_name=tun, driver_version="1.6", firmware_version=""}
type : ""
注意,ingress_policing_rate 和 ingress_policing_burst 的默认单位是 Kbps,这里我们将tap1的带宽限制在了1M。
5、在 带宽为1M 的情况下,从VM2中通过 netperf 测试的情况如下:
这次从上面的Throughput来看,出流量也就最大打到了 1Mbps。
6、我们再次将带宽调增到10M,测试情况:
这次从上面的Throughput来看,出流量最大打到了 10Mbps。