網路效能測試工具iperf的使用

crazy_baoli發表於2019-03-09

測試環境:

在vmware上執行兩臺Ubuntu虛擬機器。

Ubuntu1:Ubuntu14.04,IP:192.168.0.108

Ubuntu2:Ubuntu16.04,gnome版,IP:192.168.0.106


 

iperf命令是一個網路效能測試工具。

iperf可以測試TCP和UDP頻寬質量,iperf可以測量最大TCP頻寬,具有多種引數和UDP特性。iperf可以報告頻寬,延遲抖動和資料包丟失。利用iperf這一特性,可以用來測試一些網路裝置如路由器,防火牆,交換機等的效能。

iperf分為兩種版本,Unix/Linux版和Windows版,Unix/Linux版更新比較快,版本最新。Windows版更新慢。Windows版的iperf叫jperf,或者xjperf。jperf是在iperf基礎上開發了更好的UI和新的功能。

 

1. 安裝

sudo apt-get install iperf3

Ubuntu1和Ubuntu2都要安裝。

 

2. 效能測試

頻寬測試通常採用UDP模式,因為能測出極限頻寬、時延抖動、丟包率。在進行測試時,首先以鏈路理論頻寬作為資料傳送速率進行測試,例如,從客戶端到伺服器之間的鏈路的理論頻寬為100Mbps,先用-b 100M進行測試,然後根據測試結果(包括實際頻寬,時延抖動和丟包率),再以實際頻寬作為資料傳送速率進行測試,會發現時延抖動和丟包率比第一次好很多,重複測試幾次,就能得出穩定的實際頻寬。

 

常用選項:

  • -c:客戶端模式,後接伺服器ip
  • -s:伺服器模式
  • -t:設定測試的時長,單位為秒
  • -u:指定為UDP模式,預設為TCP模式
  • -b:指定傳送速率,單位Mbits/sec
  • -p:多執行緒傳送,接執行緒數量
  • -R:反向測速,伺服器之客戶端的下行速率,預設上行速率

 

2.1 UDP模式

Ubuntu1作為客戶端,Ubuntu2作為伺服器。

1)server端執行:iperf3 -s

2)client端執行:iperf3 -u -c 192.168.0.106 -b 10M -t 10

在udp模式下,以10Mbps為資料傳送速率,客戶端到伺服器上傳頻寬測試,測試時間為10秒。

baoli@ubuntu:~$ iperf3 -u -c 192.168.0.106 -b 10M -t 10
Connecting to host 192.168.0.106, port 5201
[  4] local 192.168.0.108 port 49073 connected to 192.168.0.106 port 5201
[ ID] Interval           Transfer     Bandwidth       Total Datagrams
[  4]   0.00-1.00   sec  1.13 MBytes  9.49 Mbits/sec  145  
[  4]   1.00-2.00   sec  1.15 MBytes  9.64 Mbits/sec  147  
[  4]   2.00-3.00   sec  1.25 MBytes  10.5 Mbits/sec  160  
[  4]   3.00-4.00   sec  1.19 MBytes  9.96 Mbits/sec  152  
[  4]   4.00-5.00   sec  1.14 MBytes  9.57 Mbits/sec  146  
[  4]   5.00-6.00   sec  1.28 MBytes  10.7 Mbits/sec  164  
[  4]   6.00-7.00   sec  1.16 MBytes  9.70 Mbits/sec  148  
[  4]   7.00-8.00   sec  1.13 MBytes  9.50 Mbits/sec  145  
[  4]   8.00-9.00   sec  1.24 MBytes  10.4 Mbits/sec  159  
[  4]   9.00-10.00  sec  1.19 MBytes  9.97 Mbits/sec  152  
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Jitter    Lost/Total Datagrams
[  4]   0.00-10.00  sec  11.9 MBytes  9.95 Mbits/sec  0.747 ms  0/1518 (0%)  
[  4] Sent 1518 datagrams

iperf Done.

可以看到最後生成測試報告:

[ ID] Interval           Transfer     Bandwidth       Jitter    Lost/Total Datagrams
[  4]   0.00-10.00  sec  11.9 MBytes  9.95 Mbits/sec  0.747 ms  0/1518 (0%)  
[  4] Sent 1518 datagrams

傳送了11.9MB資料,頻寬9.95M,總共傳送1518個資料包,無丟包。

3)client端執行:iperf3 -u -c 192.168.0.106 -b 100M -t 10

在udp模式下,以100Mbps為資料傳送速率,客戶端到伺服器上傳頻寬測試,測試時間為10秒。

baoli@ubuntu:~$ iperf3 -u -c 192.168.0.106 -b 100M -t 10
Connecting to host 192.168.0.106, port 5201
[  4] local 192.168.0.108 port 38152 connected to 192.168.0.106 port 5201
[ ID] Interval           Transfer     Bandwidth       Total Datagrams
[  4]   0.00-1.00   sec  7.60 MBytes  63.7 Mbits/sec  973  
[  4]   1.00-2.00   sec  9.38 MBytes  78.7 Mbits/sec  1201  
[  4]   2.00-3.00   sec  12.2 MBytes   102 Mbits/sec  1562  
[  4]   3.00-4.00   sec  9.23 MBytes  77.4 Mbits/sec  1182  
[  4]   4.00-5.00   sec  8.72 MBytes  73.1 Mbits/sec  1116  
[  4]   5.00-6.00   sec  8.30 MBytes  69.7 Mbits/sec  1063  
[  4]   6.00-7.00   sec  8.71 MBytes  73.0 Mbits/sec  1115  
[  4]   7.00-8.00   sec  8.55 MBytes  71.7 Mbits/sec  1094  
[  4]   8.00-9.00   sec  8.91 MBytes  74.8 Mbits/sec  1141  
[  4]   9.00-10.00  sec  8.73 MBytes  73.1 Mbits/sec  1118  
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Jitter    Lost/Total Datagrams
[  4]   0.00-10.00  sec  90.4 MBytes  75.8 Mbits/sec  0.606 ms  153/11564 (1.3%)  
[  4] Sent 11564 datagrams

iperf Done.

可以知道兩臺Ubuntu之間最大速率102M,平均頻寬75.8M,丟包率1.3%。

4)iperf3 -u -c 192.168.0.106 -b 50M -P 3 -t 2

在udp模式下,同時開啟3個執行緒,以50Mbps為資料傳送速率,客戶端到伺服器上傳頻寬測試,測試時間為2秒。

baoli@ubuntu:~$ iperf3 -u -c 192.168.0.106 -b 50M -P 3 -t 2
Connecting to host 192.168.0.106, port 5201
[  4] local 192.168.0.108 port 50851 connected to 192.168.0.106 port 5201
[  6] local 192.168.0.108 port 59320 connected to 192.168.0.106 port 5201
[  8] local 192.168.0.108 port 58309 connected to 192.168.0.106 port 5201
[ ID] Interval           Transfer     Bandwidth       Total Datagrams
[  4]   0.00-1.00   sec  2.48 MBytes  20.8 Mbits/sec  318  
[  6]   0.00-1.00   sec  2.48 MBytes  20.8 Mbits/sec  318  
[  8]   0.00-1.00   sec  2.47 MBytes  20.7 Mbits/sec  316  
[SUM]   0.00-1.00   sec  7.44 MBytes  62.3 Mbits/sec  952  
- - - - - - - - - - - - - - - - - - - - - - - - -
[  4]   1.00-2.00   sec  2.43 MBytes  20.4 Mbits/sec  311  
[  6]   1.00-2.00   sec  2.43 MBytes  20.4 Mbits/sec  311  
[  8]   1.00-2.00   sec  2.43 MBytes  20.4 Mbits/sec  311  
[SUM]   1.00-2.00   sec  7.29 MBytes  61.1 Mbits/sec  933  
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Jitter    Lost/Total Datagrams
[  4]   0.00-2.00   sec  4.91 MBytes  20.6 Mbits/sec  1.075 ms  0/629 (0%)  
[  4] Sent 629 datagrams
[  6]   0.00-2.00   sec  4.91 MBytes  20.6 Mbits/sec  0.960 ms  0/629 (0%)  
[  6] Sent 629 datagrams
[  8]   0.00-2.00   sec  4.90 MBytes  20.5 Mbits/sec  0.713 ms  0/626 (0%)  
[  8] Sent 626 datagrams
[SUM]   0.00-2.00   sec  14.7 MBytes  61.7 Mbits/sec  0.916 ms  0/1884 (0%)  

iperf Done.

5)iperf3 -u -c 192.168.0.106 -b 100M -R -t 5

使用-R選項,測試伺服器到客戶端的下行頻寬。

baoli@ubuntu:~$ iperf3 -u -c 192.168.0.106 -b 100M -R -t 5
Connecting to host 192.168.0.106, port 5201
Reverse mode, remote host 192.168.0.106 is sending
[  4] local 192.168.0.108 port 34164 connected to 192.168.0.106 port 5201
[ ID] Interval           Transfer     Bandwidth       Jitter    Lost/Total Datagrams
[  4]   0.00-1.00   sec  9.85 MBytes  82.6 Mbits/sec  0.303 ms  219/1480 (15%)  
[  4]   1.00-2.01   sec  9.31 MBytes  77.6 Mbits/sec  2.548 ms  260/1452 (18%)  
[  4]   2.01-3.00   sec  7.48 MBytes  63.1 Mbits/sec  0.854 ms  26/983 (2.6%)  
[  4]   3.00-4.00   sec  8.03 MBytes  67.4 Mbits/sec  0.466 ms  0/1028 (0%)  
[  4]   4.00-5.00   sec  7.73 MBytes  64.8 Mbits/sec  0.402 ms  10/1000 (1%)  
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Jitter    Lost/Total Datagrams
[  4]   0.00-5.00   sec  46.4 MBytes  77.9 Mbits/sec  0.385 ms  515/5944 (8.7%)  
[  4] Sent 5944 datagrams

iperf Done.

注:iperf3(3.x版本)不支援雙向測速,只有iperf(2.x版本)支援。

 

2.2 TCP模式

1)server端執行:iperf3 -s

2)client端執行:iperf3 -c 192.168.0.106 -b 100M -t 5

Connecting to host 192.168.0.106, port 5201
[  4] local 192.168.0.108 port 49730 connected to 192.168.0.106 port 5201
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-1.01   sec  11.1 MBytes  92.4 Mbits/sec    0    173 KBytes       
[  4]   1.01-2.00   sec  11.6 MBytes  98.1 Mbits/sec    0    232 KBytes       
[  4]   2.00-3.00   sec  12.0 MBytes   101 Mbits/sec    0    314 KBytes       
[  4]   3.00-4.00   sec  11.9 MBytes  99.6 Mbits/sec    0    327 KBytes       
[  4]   4.00-5.00   sec  12.0 MBytes   101 Mbits/sec    0    338 KBytes       
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-5.00   sec  58.6 MBytes  98.3 Mbits/sec    0             sender
[  4]   0.00-5.00   sec  58.6 MBytes  98.3 Mbits/sec                  receiver

iperf Done.

3)client端執行:iperf3 -c 192.168.0.106 -b 1000M -t 5

baoli@ubuntu:~$ iperf3 -c 192.168.0.106 -b 1000M -t 5
Connecting to host 192.168.0.106, port 5201
[  4] local 192.168.0.108 port 49734 connected to 192.168.0.106 port 5201
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-1.00   sec  82.8 MBytes   694 Mbits/sec    0    411 KBytes       
[  4]   1.00-2.00   sec  79.1 MBytes   662 Mbits/sec    0    583 KBytes       
[  4]   2.00-3.00   sec  63.8 MBytes   535 Mbits/sec    0    751 KBytes       
[  4]   3.00-4.00   sec  62.2 MBytes   522 Mbits/sec    0   1.11 MBytes       
[  4]   4.00-5.01   sec  77.1 MBytes   645 Mbits/sec    0   1.22 MBytes       
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-5.01   sec   365 MBytes   612 Mbits/sec    0             sender
[  4]   0.00-5.01   sec   364 MBytes   610 Mbits/sec                  receiver

iperf Done.

TCP模式下速率可以達到600M!!!

 

TCP模式適合測頻寬大小,UDP模式可以測試丟包率等。

 

 

 

 

相關文章