做网络app经常我们会发现一些诡异的问题,以下介绍用iperf 做网络测速的方法与解说(AI)希望能对你有所帮助.
iperf 网络测速工具
下载链接
iperf 官网CentOS 7 RPM 安装包openEuler-24.03-LTS RPM 安装包Ubuntu DEB 安装包
在线安装说明
CentOS/openEuler
$sudo yum install iperf3 -y
Ubuntu/Debain 安装
$sudo apt install iperf3 -y
离线安装说明(没网络时)
CentOS / openEuler 安装
- 下载对应的 RPM 包
- 使用以下命令安装:
sudo yum install -y iperf3-*.rpm
或sudo rpm -ivh iperf3-*.rpm
Ubuntu 安装
- 下载 DEB 包
- 使用以下命令安装:
sudo dpkg -i iperf3_*.deb
- 如果出现依赖问题,运行:
sudo apt-get install -f
使用方法
- 启动服务器端:
iperf3 -s
- 在防火墙中开放 5201 端口(如果需要):
sudo firewall-cmd --add-port=5201/tcp --permanent
sudo firewall-cmd --reload
- 在客户端运行测试:
iperf3 -c <服务器IP地址>
测试示例
服务器端输出
[root@icc-mcu centos]# iperf3 -s ----------------------------------------------------------- Server listening on 5201 ----------------------------------------------------------- Accepted connection from 192.168.2.181, port 48424 [ 5] local 192.168.2.88 port 5201 connected to 192.168.2.181 port 48426 [ ID] Interval Transfer Bandwidth [ 5] 0.00-1.00 sec 10.8 MBytes 90.9 Mbits/sec [ 5] 1.00-2.00 sec 11.2 MBytes 94.1 Mbits/sec [ 5] 2.00-3.00 sec 11.2 MBytes 93.8 Mbits/sec [ 5] 3.00-4.00 sec 11.2 MBytes 94.1 Mbits/sec [ 5] 4.00-5.00 sec 10.2 MBytes 85.5 Mbits/sec [ 5] 5.00-6.00 sec 9.45 MBytes 79.3 Mbits/sec [ 5] 6.00-7.00 sec 9.39 MBytes 78.8 Mbits/sec [ 5] 7.00-8.00 sec 10.7 MBytes 90.2 Mbits/sec [ 5] 8.00-9.00 sec 11.2 MBytes 94.1 Mbits/sec [ 5] 9.00-10.00 sec 11.2 MBytes 93.6 Mbits/sec [ 5] 10.00-10.04 sec 406 KBytes 93.9 Mbits/sec - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bandwidth [ 5] 0.00-10.04 sec 0.00 Bytes 0.00 bits/sec sender [ 5] 0.00-10.04 sec 107 MBytes 89.5 Mbits/sec receiver ----------------------------------------------------------- Server listening on 5201 -----------------------------------------------------------
客户端输出
[root@localhost ~]# iperf3 -c 192.168.2.88 Connecting to host 192.168.2.88, port 5201 [ 4] local 192.168.2.181 port 48426 connected to 192.168.2.88 port 5201 [ ID] Interval Transfer Bandwidth Retr Cwnd [ 4] 0.00-1.00 sec 11.3 MBytes 94.4 Mbits/sec 126 12.7 KBytes [ 4] 1.00-2.00 sec 11.2 MBytes 94.2 Mbits/sec 122 12.7 KBytes [ 4] 2.00-3.00 sec 11.2 MBytes 93.9 Mbits/sec 119 12.7 KBytes [ 4] 3.00-4.00 sec 11.2 MBytes 94.1 Mbits/sec 117 12.7 KBytes [ 4] 4.00-5.00 sec 10.2 MBytes 85.5 Mbits/sec 137 12.7 KBytes [ 4] 5.00-6.00 sec 9.39 MBytes 78.8 Mbits/sec 125 12.7 KBytes [ 4] 6.00-7.00 sec 9.39 MBytes 78.8 Mbits/sec 128 14.1 KBytes [ 4] 7.00-8.00 sec 10.8 MBytes 90.7 Mbits/sec 116 12.7 KBytes [ 4] 8.00-9.00 sec 11.2 MBytes 94.1 Mbits/sec 130 12.7 KBytes [ 4] 9.00-10.00 sec 11.2 MBytes 93.6 Mbits/sec 121 12.7 KBytes - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bandwidth Retr [ 4] 0.00-10.00 sec 107 MBytes 89.8 Mbits/sec 1241 sender [ 4] 0.00-10.00 sec 107 MBytes 89.8 Mbits/sec receiver iperf Done.
测试结果分析
总体性能
根据测试结果,我们可以看到客户端和服务器之间的网络连接平均带宽约为 89.8 Mbits/sec(兆比特每秒)。这个速度相当于约 11.2 MB/s(兆字节每秒)的数据传输率。
带宽波动
从每秒的数据来看,带宽在 78.8 Mbits/sec 到 94.4 Mbits/sec 之间波动。这种波动是正常的,可能是由于网络拥塞、其他网络流量或硬件限制造成的。
重传(Retransmissions)
客户端输出显示总共有 1241 次重传(Retr 列)。这表明网络连接可能不太稳定,或者存在一些干扰。高重传率可能会影响实际的吞吐量。
拥塞窗口(Congestion Window)
Cwnd(拥塞窗口)大小保持在 12.7 KBytes 左右,这表明 TCP 协议正在有效地管理网络拥塞。
结论
总的来说,这个网络连接的性能还算不错,但存在一些不稳定性。平均 89.8 Mbits/sec 的带宽足以支持大多数日常应用,如高清视频流或大文件传输。然而,较高的重传率表明可能存在一些网络问题,这可能会影响实时应用程序的性能。
为了改善网络性能,可以考虑以下几点:
- 检查网络硬件,如网线、交换机或路由器,确保它们工作正常。
- 排查可能的网络干扰源,如其他高带宽应用或设备。
- 考虑升级网络设备或增加带宽,特别是如果这是一个关键的业务网络。