网速测试利器-iperf3

news/2025/2/21 18:36:55/

简介

iperf3是一个网络速度测试工具,支持IPv4与IPv6,支持TCP、UDP、SCTP传输协议,可在Windows、Mac OS X、Linux、FreeBSD等各种平台使用,是一个简单又实用的小工具。 本文介绍安装、使用iperf3 网速测试工具。

安装iperf3

iperf3本身是以C++所开发的小程序,在官网https://iperf.fr/iperf-download.php上有提供各种平台的预编译二进制文件,解压缩后即可使用。

在CentOS 7上使用下列命令即可安装:

yum install iperf3

MAC OS X上使用下列命令即可安装:

brew  install iperf3

网络带宽测试

在使用iperf3测试时,要同时在server端与client端都各执行一个程序,让它们互相传送报文进行测试。下面的例子是在CentOS7上进行的测试。

首先在10.23.5.66机器启动server端的程序:

iperf3 -s

接着在10.23.5.65服务器上执行client 端的程序:

iperf3 -c 10.23.5.66

在测试时server端与client端都会出现测试的数据,client端以下是测试的结果:

[jinguang1@localhost ~]$ iperf3 -c 10.23.5.66
Connecting to host 10.23.5.66, port 5201
[  4] local 10.23.5.65 port 10412 connected to 10.23.5.66 port 5201
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-1.00   sec   114 MBytes   953 Mbits/sec    0   95.5 KBytes
[  4]   1.00-2.00   sec   113 MBytes   948 Mbits/sec    0   95.5 KBytes
[  4]   2.00-3.00   sec   113 MBytes   950 Mbits/sec    0   95.5 KBytes
[  4]   3.00-4.00   sec   113 MBytes   948 Mbits/sec    0   95.5 KBytes
[  4]   4.00-5.00   sec   113 MBytes   950 Mbits/sec    0   95.5 KBytes
[  4]   5.00-6.00   sec   113 MBytes   948 Mbits/sec    0   95.5 KBytes
[  4]   6.00-7.00   sec   113 MBytes   948 Mbits/sec    0   95.5 KBytes
[  4]   7.00-8.00   sec   113 MBytes   950 Mbits/sec    0   95.5 KBytes
[  4]   8.00-9.00   sec   113 MBytes   948 Mbits/sec    0   95.5 KBytes
[  4]   9.00-10.00  sec   113 MBytes   950 Mbits/sec    0   95.5 KBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-10.00  sec  1.10 GBytes   949 Mbits/sec    0             sender
[  4]   0.00-10.00  sec  1.10 GBytes   949 Mbits/sec                  receiveriperf Done.

从打印的内容看,缺省参数下,Client将连接Server端的5201端口,持续向Server端发送数据,并统计出每秒传输的字节数、带宽、出现报文重传的次数、拥塞窗口(Congestion Window)大小,整个测试将持续10秒钟;最后将汇总10秒的平均数据,并给出发送和接收端的统计。

接下来分析一下Server的测试输出结果:

[jinguang1@localhost ~]$ iperf3 -s
warning: this system does not seem to support IPv6 - trying IPv4
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------
Accepted connection from 10.23.5.65, port 10410
[  5] local 10.23.5.66 port 5201 connected to 10.23.5.65 port 10412
[ ID] Interval           Transfer     Bandwidth
[  5]   0.00-1.00   sec   109 MBytes   913 Mbits/sec
[  5]   1.00-2.00   sec   113 MBytes   948 Mbits/sec
[  5]   2.00-3.00   sec   113 MBytes   949 Mbits/sec
[  5]   3.00-4.00   sec   113 MBytes   949 Mbits/sec
[  5]   4.00-5.00   sec   113 MBytes   949 Mbits/sec
[  5]   5.00-6.00   sec   113 MBytes   949 Mbits/sec
[  5]   6.00-7.00   sec   113 MBytes   949 Mbits/sec
[  5]   7.00-8.00   sec   113 MBytes   949 Mbits/sec
[  5]   8.00-9.00   sec   113 MBytes   949 Mbits/sec
[  5]   9.00-10.00  sec   113 MBytes   949 Mbits/sec
[  5]  10.00-10.04  sec  4.29 MBytes   947 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  1.10 GBytes   945 Mbits/sec                  receiver
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------

Server端缺省监听IPv6地址和端口,如果未配置IPv6,会尝试IPv4。日志显示接收了来自10.23.5.65,源端口未10410的测试请求。Client端连续进行了10秒的测试,并显示了每秒传输的字节数,带宽信息;测试结束后会汇总发送和接收的统计信息。在Client连接关闭之后会继续侦听5201端口。

iperf3 进阶指令

iperf3 所提供的选项非常多,以下介绍一些常用的参数。

1. 测试时间和输出统计数据间隔

-t参数可以指定传输测试的持续时间,而-i可以指定统计输出的间隔时间,如需要持续测试一个小时,每10秒钟打印一次输出结果:

iperf3 -c server_ip -i 10 -t 3600

2. 储存测试结果

--logfile参数可以将输出的测试结果储存至文件中:

iperf3 -c server_ip --logfile stats.txt

3. 设定侦听端口

iperf3缺省使用5201端口,如果需要指定,可以使用-p参数。这需要在Server和Client侧都需要进行指定,如使用12345端口:

#server侧
iperf3 -s -p 12345
#client侧
iperf3 -c server_ip -p 12345

4. JSON 格式输出

如果需要做一些自动化方面测试和管理工作,需要读取格式化的测试结果,那可以选择-J参数,来输出JSON格式测试结果。

[jinguang1@localhost ~]$ iperf3 -c 10.23.5.66 -J -t 2
{"start":	{"connected":	[{"socket":	4,"local_host":	"10.23.5.65","local_port":	13346,"remote_host":	"10.23.5.66","remote_port":	5201}],"version":	"iperf 3.1.7","system_info":	"Linux localhost.localdomain 3.10.0-862.9.1.el7.x86_64 #1 SMP Mon Jul 16 16:29:36 UTC 2018 x86_64","timestamp":	{"time":	"Fri, 07 Sep 2018 01:31:45 GMT","timesecs":	1536283905},"connecting_to":	{"host":	"10.23.5.66","port":	5201},"cookie":	"localhost.localdomain.1536283905.522","tcp_mss_default":	1460,"test_start":	{"protocol":	"TCP","num_streams":	1,"blksize":	131072,"omit":	0,"duration":	2,"bytes":	0,"blocks":	0,"reverse":	0}},"intervals":	[{"streams":	[{"socket":	4,"start":	0,"end":	1.000059,"seconds":	1.000059,"bytes":	118546160,"bits_per_second":	948313208.319058,"retransmits":	0,"snd_cwnd":	97820,"rtt":	508,"omitted":	false}],"sum":	{"start":	0,"end":	1.000059,"seconds":	1.000059,"bytes":	118546160,"bits_per_second":	948313208.319058,"retransmits":	0,"omitted":	false}}, {"streams":	[{"socket":	4,"start":	1.000059,"end":	2.000063,"seconds":	1.000004,"bytes":	117912520,"bits_per_second":	943296336.710671,"retransmits":	0,"snd_cwnd":	97820,"rtt":	499,"omitted":	false}],"sum":	{"start":	1.000059,"end":	2.000063,"seconds":	1.000004,"bytes":	117912520,"bits_per_second":	943296336.710671,"retransmits":	0,"omitted":	false}}],"end":	{"streams":	[{"sender":	{"socket":	4,"start":	0,"end":	2.000063,"seconds":	2.000063,"bytes":	236458680,"bits_per_second":	945804841.588347,"retransmits":	0,"max_snd_cwnd":	97820,"max_rtt":	508,"min_rtt":	499,"mean_rtt":	503},"receiver":	{"socket":	4,"start":	0,"end":	2.000063,"seconds":	2.000063,"bytes":	235998780,"bits_per_second":	943965299.700324}}],"sum_sent":	{"start":	0,"end":	2.000063,"seconds":	2.000063,"bytes":	236458680,"bits_per_second":	945804841.588347,"retransmits":	0},"sum_received":	{"start":	0,"end":	2.000063,"seconds":	2.000063,"bytes":	235998780,"bits_per_second":	943965299.700324},"cpu_utilization_percent":	{"host_total":	3.365885,"host_user":	0.294900,"host_system":	3.447099,"remote_total":	0.054653,"remote_user":	0.003388,"remote_system":	0.049958},"sender_tcp_congestion":	"cubic","receiver_tcp_congestion":	"cubic"}
}

5. 使用多条连接进行测试

-P参数可以指定同时连接测试的数量,缺省使用一条连接。

[jinguang1@localhost ~]$ iperf3 -c 10.23.5.66 -P 2 -t 2
Connecting to host 10.23.5.66, port 5201
[  4] local 10.23.5.65 port 13652 connected to 10.23.5.66 port 5201
[  6] local 10.23.5.65 port 13654 connected to 10.23.5.66 port 5201
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-1.00   sec  56.8 MBytes   477 Mbits/sec    0   65.6 KBytes
[  6]   0.00-1.00   sec  56.9 MBytes   478 Mbits/sec    0   67.0 KBytes
[SUM]   0.00-1.00   sec   114 MBytes   954 Mbits/sec    0
- - - - - - - - - - - - - - - - - - - - - - - - -
[  4]   1.00-2.00   sec  56.5 MBytes   474 Mbits/sec    0   65.6 KBytes
[  6]   1.00-2.00   sec  56.5 MBytes   474 Mbits/sec    0   67.0 KBytes
[SUM]   1.00-2.00   sec   113 MBytes   948 Mbits/sec    0
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-2.00   sec   113 MBytes   475 Mbits/sec    0             sender
[  4]   0.00-2.00   sec   113 MBytes   474 Mbits/sec                  receiver
[  6]   0.00-2.00   sec   113 MBytes   476 Mbits/sec    0             sender
[  6]   0.00-2.00   sec   113 MBytes   474 Mbits/sec                  receiver
[SUM]   0.00-2.00   sec   227 MBytes   951 Mbits/sec    0             sender
[SUM]   0.00-2.00   sec   226 MBytes   949 Mbits/sec                  receiveriperf Done.

6. 选择使用的传输协议

iperf3缺省使用TCP作为传输协议,如果使用UDP则使用-u参数,使用SCTP 则使用--sctp参数。

7. 反向传输

缺省iperf3使用上传模式:Client负责发送数据,Server负责接收;如果需要测试下载速度,则在Client侧使用-R参数即可。


http://www.ppmy.cn/news/368184.html

相关文章

网络工具之网速测试

一、需求说明 我们开通互联网带宽后,我们需要做的第一件事情就是网速测试,在网速异常慢的情况下,我们也需要进行网速测试。在Windows环境下网速测试相对方便,可以使用的工具也更多一些,360卫士等都具有网速测试功能。本…

【转】局域网速度测试 三款软件轻松搞定

局域网络可谓随处可见,我们也十分关注其实际运行速度如何,比如两台计算机间的文件传输、访问对方计算机的快慢等。而决定局域网络速度的因素很多,又不可能通过简单的操作检测出速度的大小;同时也希望能有一些软件能帮助我们治理局…

Go Map 的 11 连问

目录 文章目录 1\. Map 使用时需要注意哪些问题?2\. Map 扩容是怎么实现的?3\. Map 的 panic 能被 recover 吗?4\. 并发使用 Map 除了加锁还有什么其他方案吗?5\. sync.Map 和加锁的区别是什么?6\. Map 的查询时间复杂度?8\. Ma…

Java IO 学习总结(二)File 类

Java IO 学习总结(一)输入流/输出流 Java IO 学习总结(二)File 类 前言: 学习IO流,记录并分享。文章如有错误,恳请指正。 Java IO 学习总结(二) 1.什么是 Java File …

Pycharm 配置Django 框架(详解篇)

首先你必须具备pycharm 专业版 / 社区版也可以 打开pycharm专业版 找到在最下方菜单栏找到 Terminal 第二步:检查自己的python版本 python --version 第三步: 寻找和自己python版本匹配的django版本 (图片来源: 化雨随风 …

【数据库原理与应用 - 第六章】T-SQL 在SQL Server的使用

目录 一、数据库定义语言DDL 1、数据库的定义 (1)创建数据库 (2)管理数据库 2、基本表的定义 (1)创建基本表 (2)修改基本表 3、索引的定义 (1)创建索…

AT24C02、DS1302、DS18B20等中文手册

资料 这是这几个月收集的有关单片机内部资源设备的一些中文资料,包含24C02、蓝桥杯指导手册、DS1302等等在这里提供给大家(免费的,不像其他博主还收费),希望大家利用好这些资料,在今后的比赛以及学习中取得…

西门子200smart与东元Teco N310变频器通讯实战程序

西门子200smart与东元Teco N310变频器通讯实战程序 器件:西门子s7 200 smart PLC,东元Teco N310变频器,昆仑通态触摸屏(带以太网),中途可以加路由器 控制方式:触摸屏与plc以太网通讯,PLC与变频器通讯485口相…