如果想要测试网络带宽性能,可以使用iperf这个工具。Iperf在使用时,分为服务端和客户端两部分,通过运行iperf命令,可以得到两个终端设备之间的网络带宽性能数据 [1]。
安装和使用
Iperf3
是从头重写的 iperf,目的是创建一个更小、更简洁的代码库 [2],不同操作系统下都可以比较方便安装它:
- Termux:
pkg install iperf3
- Ubuntu:
apt install iperf3
- MacOS:
brew install iperf3
- Windows: 在 https://files.budman.pw/ 下载解压
iperf3
二进制可执行文件
完整的官网使用说明文档见此:https://iperf.fr/iperf-doc.php
启动服务端
iperf3 -s
将会启动iperf3服务,默认监听端口5201
。
开始测试
iperf3 -c < 服务端IP地址 > -t 30
在客户端运行上面的命令,终端命令行将显示从客户端到服务器的网络带宽,包括吞吐量、丢包等信息,测试时间30s。服务端的终端也会同时相应输出测试数据。
如果想要将带宽速率单位展示为 MB/s
可以加上参数 -f M
,例如:
iperf3 -c 10.7.0.1 -t 30 -f M
结果解读
🟢 服务端 iperf3 -s -f M
输出:
----------------------------------------------------------- Server listening on 5201 (test #1) ----------------------------------------------------------- Accepted connection from 192.168.128.3, port 58816 [ 5] local 192.168.128.1 port 5201 connected to 192.168.128.3 port 58828 [ ID] Interval Transfer Bitrate [ 5] 0.00-1.00 sec 643 MBytes 641 MBytes/sec [ 5] 1.00-2.00 sec 676 MBytes 677 MBytes/sec [ 5] 2.00-3.00 sec 682 MBytes 682 MBytes/sec [ 5] 3.00-4.00 sec 682 MBytes 683 MBytes/sec [ 5] 4.00-5.00 sec 688 MBytes 686 MBytes/sec [ 5] 5.00-6.00 sec 684 MBytes 684 MBytes/sec [ 5] 6.00-7.00 sec 678 MBytes 679 MBytes/sec [ 5] 7.00-8.00 sec 682 MBytes 682 MBytes/sec [ 5] 8.00-9.00 sec 681 MBytes 681 MBytes/sec [ 5] 9.00-10.00 sec 680 MBytes 681 MBytes/sec [ 5] 10.00-11.00 sec 683 MBytes 683 MBytes/sec [ 5] 11.00-12.00 sec 688 MBytes 687 MBytes/sec [ 5] 12.00-13.00 sec 685 MBytes 686 MBytes/sec [ 5] 13.00-14.00 sec 687 MBytes 684 MBytes/sec [ 5] 14.00-15.00 sec 682 MBytes 684 MBytes/sec [ 5] 15.00-16.00 sec 684 MBytes 683 MBytes/sec [ 5] 16.00-17.00 sec 682 MBytes 682 MBytes/sec [ 5] 17.00-18.00 sec 672 MBytes 671 MBytes/sec [ 5] 18.00-19.00 sec 683 MBytes 682 MBytes/sec [ 5] 19.00-20.00 sec 627 MBytes 629 MBytes/sec [ 5] 20.00-21.00 sec 583 MBytes 581 MBytes/sec [ 5] 21.00-22.00 sec 679 MBytes 679 MBytes/sec [ 5] 22.00-23.00 sec 683 MBytes 684 MBytes/sec [ 5] 23.00-24.00 sec 680 MBytes 682 MBytes/sec [ 5] 24.00-25.00 sec 679 MBytes 679 MBytes/sec [ 5] 25.00-26.00 sec 660 MBytes 661 MBytes/sec [ 5] 26.00-27.00 sec 682 MBytes 680 MBytes/sec [ 5] 27.00-28.00 sec 679 MBytes 680 MBytes/sec [ 5] 28.00-29.00 sec 682 MBytes 681 MBytes/sec [ 5] 29.00-30.00 sec 672 MBytes 671 MBytes/sec - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bitrate [ 5] 0.00-30.00 sec 19.8 GBytes 674 MBytes/sec receiver ----------------------------------------------------------- Server listening on 5201 (test #2) -----------------------------------------------------------
可以看到服务端收到了IP地址为 192.168.128.3
设备的连接请求,往下就是测试的结果数据:第一列 [ID]
表示连接的流ID,第二列 Interval
表示测试时间间隔,第三列 Transfer
表示该时间段(1s)内传输的数据量(单位MB),第四列 Bitrate
表示此时间段的传输速率。再往下,就是在以上整个测试期间内的总体性能。
🔴 客户端 运行命令 iperf3 -c 192.168.128.1 -t 30 -f M
输出:
Connecting to host 192.168.128.1, port 5201 [ 5] local 192.168.128.3 port 58828 connected to 192.168.128.1 port 5201 [ ID] Interval Transfer Bitrate Retr Cwnd [ 5] 0.00-1.00 sec 653 MBytes 652 MBytes/sec 179 1.44 MBytes [ 5] 1.00-2.00 sec 674 MBytes 674 MBytes/sec 0 1.41 MBytes [ 5] 2.00-3.00 sec 682 MBytes 682 MBytes/sec 0 1.72 MBytes [ 5] 3.00-4.00 sec 676 MBytes 675 MBytes/sec 40 2.12 MBytes [ 5] 4.00-5.00 sec 690 MBytes 690 MBytes/sec 212 2.31 MBytes [ 5] 5.00-6.00 sec 681 MBytes 681 MBytes/sec 0 1.43 MBytes [ 5] 6.00-7.00 sec 677 MBytes 678 MBytes/sec 81 1.72 MBytes [ 5] 7.00-8.00 sec 681 MBytes 681 MBytes/sec 44 2.05 MBytes [ 5] 8.00-9.00 sec 674 MBytes 674 MBytes/sec 0 1.84 MBytes [ 5] 9.00-10.00 sec 678 MBytes 677 MBytes/sec 0 1.44 MBytes [ 5] 10.00-11.00 sec 687 MBytes 688 MBytes/sec 0 1.33 MBytes [ 5] 11.00-12.00 sec 680 MBytes 681 MBytes/sec 0 1.28 MBytes [ 5] 12.00-13.00 sec 686 MBytes 686 MBytes/sec 0 1.98 MBytes [ 5] 13.00-14.01 sec 679 MBytes 676 MBytes/sec 0 1.75 MBytes [ 5] 14.01-15.00 sec 679 MBytes 681 MBytes/sec 32 1.43 MBytes [ 5] 15.00-16.00 sec 684 MBytes 685 MBytes/sec 0 1.73 MBytes [ 5] 16.00-17.00 sec 684 MBytes 682 MBytes/sec 23 1.82 MBytes [ 5] 17.00-18.00 sec 672 MBytes 672 MBytes/sec 0 2.02 MBytes [ 5] 18.00-19.00 sec 679 MBytes 680 MBytes/sec 0 1.77 MBytes [ 5] 19.00-20.01 sec 629 MBytes 628 MBytes/sec 0 5.66 KBytes [ 5] 20.01-21.00 sec 578 MBytes 580 MBytes/sec 89 1.72 MBytes [ 5] 21.00-22.01 sec 681 MBytes 678 MBytes/sec 0 1.62 MBytes [ 5] 22.01-23.00 sec 675 MBytes 678 MBytes/sec 0 1.65 MBytes [ 5] 23.00-24.00 sec 681 MBytes 680 MBytes/sec 0 1.33 MBytes [ 5] 24.00-25.00 sec 672 MBytes 672 MBytes/sec 0 1.22 MBytes [ 5] 25.00-26.00 sec 646 MBytes 645 MBytes/sec 0 1.87 MBytes [ 5] 26.00-27.00 sec 689 MBytes 691 MBytes/sec 66 1.41 MBytes [ 5] 27.00-28.00 sec 681 MBytes 681 MBytes/sec 85 1.83 MBytes [ 5] 28.00-29.00 sec 681 MBytes 681 MBytes/sec 0 1.44 MBytes [ 5] 29.00-30.00 sec 672 MBytes 671 MBytes/sec 43 1.19 MBytes - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bitrate Retr [ 5] 0.00-30.00 sec 19.8 GBytes 675 MBytes/sec 894 sender [ 5] 0.00-30.00 sec 19.8 GBytes 674 MBytes/sec receiver iperf Done.
上方客户端输出的数据,前4列代表的意义和服务端的一致,只不过客户端这边是作为数据发送的角色;后面的 Retr
一列表示在此时间间隔内的TCP重传次数(或者出错次数);之后的 Cwnd
(Congestion Window,拥塞窗口),表示当前的TCP拥塞窗口大小。