为什么要使用iperf3
当存在大文件下载,音视频传输的场景时,经常会遇到下载的文件不对,音视频卡顿等问题,此时需要有工具测试网络的传输速率,丢包率,已确保底层网络是OK的
使用方法
iperf3在android,ios,windows,mac和linux下均可以使用,以下介绍命令行的使用方式。
服务端
服务器端执行命令
iperf3 -s
客户端
UDP测试
iperf3 -c @ip -u -b 1000M
客户端执行结果
127|rk3588_hertz_t:/ $ iperf3 -c 10.88.254.85 -u -b 1000M
Connecting to host 10.88.254.85, port 5201
[ 5] local 10.88.254.148 port 45047 connected to 10.88.254.85 port 5201
[ ID] Interval Transfer Bitrate Total Datagrams
[ 5] 0.00-1.00 sec 114 MBytes 957 Mbits/sec 82578
[ 5] 1.00-2.00 sec 114 MBytes 955 Mbits/sec 82455
[ 5] 2.00-3.00 sec 114 MBytes 955 Mbits/sec 82410
[ 5] 3.00-4.00 sec 114 MBytes 955 Mbits/sec 82460
[ 5] 4.00-5.00 sec 114 MBytes 956 Mbits/sec 82567
[ 5] 5.00-6.00 sec 113 MBytes 948 Mbits/sec 81842
[ 5] 6.00-7.00 sec 114 MBytes 955 Mbits/sec 82416
[ 5] 7.00-8.00 sec 114 MBytes 956 Mbits/sec 82564
[ 5] 8.00-9.00 sec 114 MBytes 955 Mbits/sec 82414
[ 5] 9.00-10.00 sec 114 MBytes 956 Mbits/sec 82562
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bitrate Jitter Lost/Total Datagrams
[ 5] 0.00-10.00 sec 1.11 GBytes 955 Mbits/sec 0.000 ms 0/824268 (0%) sender
[ 5] 0.00-10.00 sec 1.10 GBytes 947 Mbits/sec 0.017 ms 6496/824268 (0.79%) receiver
iperf Done.
服务端执行结果
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------
Accepted connection from 10.88.254.148, port 49762
[ 5] local 10.88.254.85 port 5201 connected to 10.88.254.148 port 45047
[ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams
[ 5] 0.00-1.00 sec 113 MBytes 951 Mbits/sec 0.031 ms 354/82484 (0.43%)
[ 5] 1.00-2.00 sec 113 MBytes 949 Mbits/sec 0.015 ms 575/82461 (0.7%)
[ 5] 2.00-3.00 sec 113 MBytes 946 Mbits/sec 0.016 ms 728/82411 (0.88%)
[ 5] 3.00-4.00 sec 112 MBytes 943 Mbits/sec 0.014 ms 1022/82465 (1.2%)
[ 5] 4.00-5.00 sec 113 MBytes 947 Mbits/sec 0.015 ms 838/82567 (1%)
[ 5] 5.00-6.00 sec 112 MBytes 942 Mbits/sec 0.014 ms 501/81844 (0.61%)
[ 5] 6.00-7.00 sec 114 MBytes 954 Mbits/sec 0.020 ms 61/82410 (0.074%)
[ 5] 7.00-8.00 sec 112 MBytes 943 Mbits/sec 0.016 ms 1138/82573 (1.4%)
[ 5] 8.00-9.00 sec 113 MBytes 948 Mbits/sec 0.014 ms 553/82418 (0.67%)
[ 5] 9.00-10.00 sec 113 MBytes 948 Mbits/sec 0.016 ms 726/82566 (0.88%)
[ 5] 10.00-10.00 sec 97.6 KBytes 930 Mbits/sec 0.017 ms 0/69 (0%)
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams
[ 5] 0.00-10.00 sec 0.00 Bytes 0.00 bits/sec 0.017 ms 6496/824268 (0.79%)
结果分析
- 发送和接收数据不是一对一,服务器最后有一个10.00-10.00补充,总的数据包都是一致的824268
- Total中的是数据包,不是字节数,udp默认一个数据包是1472,可以通过-l参数修改
- 真正传输的数据量是Transfer,Bandwidth只代表1s中可以传输多少字节,真实的传输数据量较1s有波动
- jitter反应波动程度,值越小代表传输越稳定
上述日志是正常传输,client发送数据给server的丢包率,如果希望测试server发送数据给client,只需要在client的终端添加-R参数
iperf3 -c @ip -u -R -b 1000M
TCP测试
客户端执行命令
iperf3 -c @ip -b 1000M
客户端执行结果
rk3588_hertz_t:/ $ iperf3 -c 10.88.254.85 -b 1000M
Connecting to host 10.88.254.85, port 5201
[ 5] local 10.88.254.148 port 51938 connected to 10.88.254.85 port 5201
[ ID] Interval Transfer Bitrate Retr Cwnd
[ 5] 0.00-1.01 sec 88.8 MBytes 741 Mbits/sec 0 915 KBytes
[ 5] 1.01-2.00 sec 96.1 MBytes 809 Mbits/sec 0 1.11 MBytes
[ 5] 2.00-3.00 sec 106 MBytes 896 Mbits/sec 0 1.11 MBytes
[ 5] 3.00-4.00 sec 98.4 MBytes 823 Mbits/sec 0 1.24 MBytes
[ 5] 4.00-5.00 sec 105 MBytes 882 Mbits/sec 0 1.24 MBytes
[ 5] 5.00-6.02 sec 90.9 MBytes 750 Mbits/sec 0 1.30 MBytes
[ 5] 6.02-7.01 sec 72.6 MBytes 617 Mbits/sec 0 1.36 MBytes
[ 5] 7.01-8.00 sec 99.5 MBytes 838 Mbits/sec 0 1.36 MBytes
[ 5] 8.00-9.00 sec 80.8 MBytes 677 Mbits/sec 0 1.36 MBytes
[ 5] 9.00-10.02 sec 82.1 MBytes 680 Mbits/sec 0 1.43 MBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bitrate Retr
[ 5] 0.00-10.02 sec 921 MBytes 771 Mbits/sec 0 sender
[ 5] 0.00-10.02 sec 920 MBytes 771 Mbits/sec receiver
iperf Done.
服务端执行结果
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------
Accepted connection from 10.88.254.148, port 51936
[ 5] local 10.88.254.85 port 5201 connected to 10.88.254.148 port 51938
[ ID] Interval Transfer Bandwidth
[ 5] 0.00-1.00 sec 88.6 MBytes 743 Mbits/sec
[ 5] 1.00-2.00 sec 94.8 MBytes 795 Mbits/sec
[ 5] 2.00-3.00 sec 107 MBytes 894 Mbits/sec
[ 5] 3.00-4.00 sec 98.6 MBytes 827 Mbits/sec
[ 5] 4.00-5.00 sec 106 MBytes 888 Mbits/sec
[ 5] 5.00-6.00 sec 90.1 MBytes 756 Mbits/sec
[ 5] 6.00-7.00 sec 73.5 MBytes 616 Mbits/sec
[ 5] 7.00-8.00 sec 99.0 MBytes 831 Mbits/sec
[ 5] 8.00-9.00 sec 81.4 MBytes 683 Mbits/sec
[ 5] 9.00-10.00 sec 81.5 MBytes 683 Mbits/sec
[ 5] 10.00-10.02 sec 386 KBytes 171 Mbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bandwidth
[ 5] 0.00-10.02 sec 0.00 Bytes 0.00 bits/sec sender
[ 5] 0.00-10.02 sec 920 MBytes 771 Mbits/sec receiver
结果分析
- 设置为1000M,但是实际没有跑到1000M,和网络质量,CPU等有关,本次测试将CPU跑满,出现了BandWidth只有6-700M的情况
- TCP没有丢包率,只有Retr次数