這里我們簡單描述下如何通過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-4701-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 : 14 ingress_policing_burst: 0 ingress_policing_rate: 0 lacp_current : [] link_resets : 1 link_speed : 10000000 link_state : up mac : [] mac_in_use : "fe:54:00:f9:b6:b1" mtu : 1500 name : "tap1" ofport : 8 ofport_request : [] options : {} other_config : {} statistics : {collisions=0, rx_bytes=39024162452, rx_crc_err=0, rx_dropped=0, rx_errors=0, rx_frame_err=0, rx_over_err=0, rx_packets=608632, tx_bytes=24416546, tx_dropped=0, tx_errors=0, tx_packets=369535} 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=100 ◄► sudo ovs-vsctl set interface tap1 ingress_policing_rate=1000 ◄► sudo ovs-vsctl list Interface tap1 _uuid : aa4b7e2b-44b9-4701-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 : 14 ingress_policing_burst: 100 ingress_policing_rate: 1000 lacp_current : [] link_resets : 1 link_speed : 10000000 link_state : up mac : [] mac_in_use : "fe:54:00:f9:b6:b1" mtu : 1500 name : "tap1" ofport : 8 ofport_request : [] options : {} other_config : {} statistics : {collisions=0, rx_bytes=24983931502, rx_crc_err=0, rx_dropped=0, rx_errors=0, rx_frame_err=0, rx_over_err=0, rx_packets=389089, tx_bytes=14487246, tx_dropped=0, tx_errors=0, tx_packets=219351} 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。