网络性能测试工具iperf的使用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012247418/article/details/88367077

测试环境:

在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模式可以测试丢包率等。

猜你喜欢

转载自blog.csdn.net/u012247418/article/details/88367077