iperf3 网络带宽性能测试工具

iperf3网络测试工具
Iperf 是一款基于TCP/IP和UDP/IP的网络性能测试工具。可以用来测试网络带宽和网络质量,还能提供网络延迟抖动、数据丢包率,最大传输单元统计信息,可以根据这些信息判断网络性能问题从而定位网络瓶颈解决网络故障。

工具下载地址:https://iperf.fr/download/source/iperf-3.1.3-source.tar.gz

1、安装iperf3
(1)上传工具包
下载工具包至本地后上传到服务器,我使用的是lrzsz直接拉上去 很方便

[root@redhat7 tools]# pwd
/root/tools
[root@redhat7 tools]# ls
iperf-3.1.3-source.tar.gz

(2)解压后进入目录下

[root@redhat7 tools]# tar zxf iperf-3.1.3-source.tar.gz
[root@redhat7 tools]# cd iperf-3.1.3
[root@redhat7 iperf-3.1.3]# ls
aclocal.m4    config.log     configure.ac  examples     iperf3.spec.in  Makefile     make_release   src
bootstrap.sh  config.status  contrib       INSTALL      libtool         Makefile.am  README.md      test_commands.sh
config        configure      docs          iperf3.spec  LICENSE         Makefile.in  RELEASE_NOTES

(3)编译安装

./configure
#可自行选择是否设置安装路径./configure --prefix=/app/iperf-3.1.3
make && make install

(4)查看是否存在命令iperf3
可以使用Tab补齐键测试是否存在该命令

2、iperf3 --help 参数详解

通用参数:
  -p, --port          #        ## 侦听/连接到的服务器端口 定义端口号
  -f, --format        [kmgKMG] ## 报告格式:Kbits,Mbits,KB,MBytes
  -i, --interval      #        ## 定期带宽报告之间的秒数
  -F, --file name              ## xmit / recv指定的文件
  -A, --affinity      n/n,m    ## n / n,m设置CPU亲和力
  -B, --bind             ## <主机>绑定到特定接口
  -V, --verbose                ## 更详细的输出
  -J, --json                   ## 以JSON格式输出
  --logfile f                  ## 将输出发送到日志文件
  -d, --debug                  ## 发出调试输出
  -v, --version                ## 显示版本信息并退出
  -h, --help                   ## 显示此消息并退出
服务端:
  -s, --server                 ## 在服务器模式下运行
  -D, --daemon                 ## 将服务器作为守护程序运行
  -I, --pidfile file           ## 文件写入PID文件
  -1, --one-off                ## 处理一个客户端连接,然后退出

客户端:
  -c, --client           ## 在客户端模式下运行,连接到<主机>
  -u, --udp                    ## 使用UDP而不是TCP
  -b, --bandwidth #[KMG][/#]   ## 目标带宽,以位/秒为单位(0表示无限制)
                               ## (对于UDP,默认为1 Mbit / sec,对于TCP,为无限)
                               ## (突发模式的可选斜杠和数据包计数)
  -t, --time      #            ## 传输时间(以秒为单位)(默认为10秒)
  -n, --bytes     #[KMG]       ## 要传输的字节数(而不是-t)
  -k, --blockcount #[KMG]      ## 要传输的块(数据包)数(而不是-t或-n)
  -l, --len       #[KMG]       ## 读取或写入的缓冲区长度
                               ## (TCP的默认值为128 KB,UDP的默认值为8 KB)
  --cport                ## 绑定到特定的客户端端口(TCP和UDP,默认:临时端口)
  -P, --parallel  #            ## 要运行的并行客户端流的数量
  -R, --reverse                ## 以反向模式运行(服务器发送,客户端接收)
  -w, --window    #[KMG]       ## 设置窗口大小/套接字缓冲区大小
  -C, --congestion       ## 设置TCP拥塞控制算法(仅Linux和FreeBSD)
  -M, --set-mss   #            ## 设置TCP / SCTP最大段大小(MTU-40字节)
  -N, --no-delay               ## 设置TCP / SCTP无延迟,禁用Nagle的算法
  -4, --version4               ## 仅使用IPv4
  -6, --version6               ## 仅使用IPv6
  -S, --tos N                  ## 设置IP“服务类型”
  -L, --flowlabel N            ## 设置IPv6流标签(仅在Linux上受支持)
  -Z, --zerocopy               ## 使用发送数据的“零复制”方法
  -O, --omit N                 ## 省略前n秒
  -T, --title str              ## 在此字符串的每个输出行之前加上前缀
  --get-server-output          ## 从服务器获取结果
  --udp-counters-64bit         ## 在UDP测试数据包中使用64位计数器
  --no-fq-socket-pacing        ## 禁用基于公平队列的套接字步调 

3、简单使用示例
服务端与客户端均进行工具的安装,两台主机均可做为服务端或客户端

服务端运行命令:

[root@redhat7 iperf-3.1.3]# iperf -s
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------

客户端运行命令:
(1)iperf3 测试网络带宽利用率

默认运行时间是10秒 每隔一秒输出一次传输状态,同时还能看到每秒钟的传输数据量在200MB左右,与Bandwidth值对应起来网卡的带宽速率维持在1.68 Gbits/sec左右,网卡为千兆网卡这个值也基本合理。

在输出最后还给出了总的数据发送、接收量,并给出了网络带宽的平均值 通过这些值基本可以判断网络带宽和网络传输状态是否稳定。

[root@redhat7 ~]# iperf3 -c 172.20.10.4
Connecting to host 172.20.10.4, port 5201
[  4] local 172.20.10.2 port 33706 connected to 172.20.10.4 port 5201
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-1.00   sec   164 MBytes  1.38 Gbits/sec    0   1.48 MBytes       
[  4]   1.00-2.00   sec   200 MBytes  1.68 Gbits/sec   13   1.46 MBytes       
[  4]   2.00-3.00   sec   200 MBytes  1.68 Gbits/sec    0   1.58 MBytes       
[  4]   3.00-4.00   sec   212 MBytes  1.78 Gbits/sec    0   1.68 MBytes       
[  4]   4.00-5.00   sec   214 MBytes  1.80 Gbits/sec    0   1.76 MBytes       
[  4]   5.00-6.00   sec   194 MBytes  1.63 Gbits/sec    0   1.81 MBytes       
[  4]   6.00-7.00   sec   194 MBytes  1.62 Gbits/sec    4   1.33 MBytes       
[  4]   7.00-8.00   sec   191 MBytes  1.61 Gbits/sec    0   1.43 MBytes       
[  4]   8.00-9.00   sec   192 MBytes  1.61 Gbits/sec    0   1.52 MBytes       
[  4]   9.00-10.00  sec   189 MBytes  1.58 Gbits/sec    0   1.61 MBytes       
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-10.00  sec  1.90 GBytes  1.64 Gbits/sec   17             sender
[  4]   0.00-10.00  sec  1.90 GBytes  1.63 Gbits/sec                  receiver

iperf Done.

(2)iperf3 改变运行时间和输出频率 “-t” “-i” 参数实现

输出状态更改为5秒一次,共测试30秒,测试速率基本也能维持在1.68 Gbits/sec左右,失败重传次数增加了。

[root@redhat7 ~]# iperf3 -c 172.20.10.4 -i 5 -t 30
Connecting to host 172.20.10.4, port 5201
[  4] local 172.20.10.2 port 33750 connected to 172.20.10.4 port 5201
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-5.00   sec  1.00 GBytes  1.72 Gbits/sec   13   1.77 MBytes       
[  4]   5.00-10.00  sec  1000 MBytes  1.68 Gbits/sec    8   1.58 MBytes       
[  4]  10.00-15.00  sec  1.02 GBytes  1.76 Gbits/sec   21   1.54 MBytes       
[  4]  15.00-20.00  sec   982 MBytes  1.65 Gbits/sec   14   1.37 MBytes       
[  4]  20.00-25.00  sec   999 MBytes  1.68 Gbits/sec    0   1.81 MBytes       
[  4]  25.00-30.00  sec   959 MBytes  1.61 Gbits/sec    3   1.68 MBytes       
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-30.00  sec  5.87 GBytes  1.68 Gbits/sec   59             sender
[  4]   0.00-30.00  sec  5.87 GBytes  1.68 Gbits/sec                  receiver

iperf Done.

(3)iperf3 指定数据量模拟大量数据传输 "-n 字节"

以下是传输5G数据包 每隔5秒输出一次传输状态,可以看出失败重传次数较多时传输速率下降

[root@redhat7 ~]# iperf3 -c 172.20.10.4 -i 5 -n 5368709120
Connecting to host 172.20.10.4, port 5201
[  4] local 172.20.10.2 port 33778 connected to 172.20.10.4 port 5201
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-5.00   sec   982 MBytes  1.65 Gbits/sec   22   1.76 MBytes       
[  4]   5.00-10.00  sec  1.00 GBytes  1.73 Gbits/sec    9   1.64 MBytes       
[  4]  10.00-15.00  sec  1.16 GBytes  2.00 Gbits/sec    7   1.64 MBytes       
[  4]  15.00-20.00  sec  1.01 GBytes  1.74 Gbits/sec    3   1.59 MBytes       
[  4]  20.00-24.28  sec   884 MBytes  1.73 Gbits/sec   27   1.38 MBytes       
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-24.28  sec  5.00 GBytes  1.77 Gbits/sec   68             sender
[  4]   0.00-24.28  sec  5.00 GBytes  1.77 Gbits/sec                  receiver

iperf Done.

(4)iperf3 测试UDP丢包和延迟 ”-u“

iperf3可以用于测试UDP数据包吞吐量、丢包率和延迟指标 UDP是一个非面向连接的轻量级传输协议不提供可靠的数据传输服务,应该关注的点是它的丢包率和延时指标。

以下为传输100MB UDP数据包的传输结果,主要关注虚线以下内容

”Jitter“ 表示抖动时间也可称为传输延迟

”Lost/Total“表示丢失的数据包和数据包数量,%号后面是平均丢包的比率

”Datagrams“表示总共传输数据包的数量

[root@redhat7 ~]# iperf3 -c 172.20.10.4 -u -b 100M  -i 2
Connecting to host 172.20.10.4, port 5201
[  4] local 172.20.10.2 port 49755 connected to 172.20.10.4 port 5201
[ ID] Interval           Transfer     Bandwidth       Total Datagrams
[  4]   0.00-2.00   sec  23.0 MBytes  96.3 Mbits/sec  2941  
[  4]   2.00-4.00   sec  23.9 MBytes   100 Mbits/sec  3062  
[  4]   4.00-6.00   sec  23.9 MBytes   100 Mbits/sec  3062  
[  4]   6.00-8.00   sec  23.9 MBytes   100 Mbits/sec  3055  
[  4]   8.00-10.00  sec  23.8 MBytes  99.9 Mbits/sec  3050  
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Jitter    Lost/Total Datagrams
[  4]   0.00-10.00  sec   119 MBytes  99.4 Mbits/sec  0.097 ms  0/15170 (0%)  
[  4] Sent 15170 datagrams

iperf Done.

可以通过查看服务端输出状态查看详细UDP丢包和延时指标,如下

[root@centos7 ~]# /app/iperf-3.1.3/bin/iperf3  -s #路径为我自己的安装路径 忽略
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------
Accepted connection from 172.20.10.2, port 33784
[  5] local 172.20.10.4 port 5201 connected to 172.20.10.2 port 49755
[ ID] Interval           Transfer     Bandwidth       Jitter    Lost/Total Datagrams
[  5]   0.00-1.00   sec  11.1 MBytes  93.2 Mbits/sec  0.075 ms  0/1423 (0%)  
[  5]   1.00-2.00   sec  11.9 MBytes  99.4 Mbits/sec  0.081 ms  0/1517 (0%)  
[  5]   2.00-3.00   sec  11.9 MBytes  99.9 Mbits/sec  0.048 ms  0/1524 (0%)  
[  5]   3.00-4.00   sec  12.0 MBytes   101 Mbits/sec  0.098 ms  0/1538 (0%)  
[  5]   4.00-5.00   sec  11.8 MBytes  99.3 Mbits/sec  0.024 ms  0/1516 (0%)  
[  5]   5.00-6.00   sec  12.1 MBytes   101 Mbits/sec  0.054 ms  0/1546 (0%)  
[  5]   6.00-7.00   sec  11.8 MBytes  99.3 Mbits/sec  0.076 ms  0/1516 (0%)  
[  5]   7.00-8.00   sec  12.0 MBytes   101 Mbits/sec  0.053 ms  0/1539 (0%)  
[  5]   8.00-9.00   sec  11.9 MBytes   100 Mbits/sec  0.042 ms  0/1526 (0%)  
[  5]   9.00-10.00  sec  11.9 MBytes  99.9 Mbits/sec  0.033 ms  0/1524 (0%)  
[  5]  10.00-10.04  sec  8.00 KBytes  1.53 Mbits/sec  0.097 ms  0/1 (0%)  
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Jitter    Lost/Total Datagrams
[  5]   0.00-10.04  sec  0.00 Bytes  0.00 bits/sec  0.097 ms  0/15170 (0%)  

 

以上为我使用的自己的虚拟机 对该工具的测试,个人觉得还是非常简单实用的,如果大家觉得不准确或者哪里理解错误还希望大家指正,谢谢!

 

你可能感兴趣的:(命令类,基础类,问题类,linux,网络)