网速测试利器-iperf3

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010096900/article/details/82468482

简介

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                  receiver

iperf 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                  receiver

iperf Done.

6. 选择使用的传输协议

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

7. 反向传输

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

猜你喜欢

转载自blog.csdn.net/u010096900/article/details/82468482