抑郁症健康,内容丰富有趣,生活中的好帮手!
抑郁症健康 > iperf 服务端发送数据_iperf网络测试工具

iperf 服务端发送数据_iperf网络测试工具

时间:2021-12-24 05:45:03

相关推荐

1、简介

Iperf3 是一个网络性能测试工具。Iperf可以测试最大TCP和UDP带宽性能,具有多种参数和UDP特性,可以根据需要调整,可以报告带宽、延迟抖动和数据包丢失.对于每个测试,它都会报告带宽,丢包和其他参数,可在Windows、Mac OS X、Linux、FreeBSD等各种平台使用,是一个简单又实用的小工具。

软件下载地址:https://iperf.fr/iperf-download.php

2、Iperf3的主要功能

TCP方面

1. 测试网络带宽。

2. 支持多线程,在客户端与服务端支持多重连接。

3. 报告MSS/MTU值的大小。

4.支持TCP窗口值自定义并可通过套接字缓冲。

UDP方面

1. 可以设置指定带宽的UDP数据流。

2. 可以测试网络抖动值、丢包数。

3. 支持多播测试。

4. 支持多线程,在客户端与服务端支持多重连接。

3、安装lperf3

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

# yum install iperf3

在ubuntu 上使用下列命令安装:

# apt-get install iperf3

windows端安装:

#下载解压安装包,进入dos切换到iperf3解压目录,执行iperf3即可运行.

4、Iperf应用实例

要使用iperf,首先要启用一个服务端,这里假定服务端的IP地址为172.17.120.13,在此服务器上运行“iperf3 -s”即可开启iperf的服务器模式。在默认情况下,iperf3将在服务端打开一个5201监听端口,此时就可以将另一台服务器作为客户端执行iperf功能测试了。

[root@serverb ~]# iperf3 -s

warning: this system does not seem to support IPv6 -trying IPv4

-----------------------------------------------------------

Server listening on 5201

-----------------------------------------------------------

5、测试TCP吞吐量

1.为了确定网卡的最大吞吐量,可以在任意客户端运行iperf命令,iperf将尝试从客户端尽可能快地向服务端发送数据请求,并且会输出发送的数据量和网卡平均带宽值。图1是一个最简单的带宽测试命令。

[root@servera ~]# iperf3 -c 172.17.120.13

Connecting to host 172.17.120.13, port 5201

[ 4] local 172.17.120.12 port 33842connected to 172.17.120.13 port 5201

[ ID] Interval Transfer Bandwidth Retr Cwnd

[ 4] 0.00-1.00 sec 212MBytes 1.78 Gbits/sec 258 234KBytes

[ 4] 1.00-2.00 sec 213MBytes 1.79 Gbits/sec 275 178KBytes

[ 4] 2.00-3.00 sec 216MBytes 1.81 Gbits/sec 237 198KBytes

[ 4] 3.00-4.00 sec 219MBytes 1.84 Gbits/sec 246 327KBytes

[ 4] 4.00-5.00 sec 220MBytes 1.85 Gbits/sec 220 262KBytes

[ 4] 5.00-6.00 sec 218MBytes 1.83 Gbits/sec 217 334KBytes

[ 4] 6.00-7.00 sec 218MBytes 1.83 Gbits/sec 374 271KBytes

[ 4] 7.00-8.00 sec 217MBytes 1.82 Gbits/sec 249 231KBytes

[ 4] 8.00-9.00 sec 217MBytes 1.82 Gbits/sec 316 224KBytes

[ 4] 9.00-10.00 sec 218MBytes 1.83 Gbits/sec 238 278KBytes

-------------------------

[ ID] Interval Transfer Bandwidth Retr

[ 4] 0.00-10.00 sec 2.12 GBytes 1.82 Gbits/sec 2630 sender

[ 4] 0.00-10.00 sec 2.12 GBytes 1.82 Gbits/sec receiver

iperf Done.

--------------------------------------------------------------------------

##可以看出,iperf默认的运行时间是10秒钟,每隔一秒钟输出一次传输状态,同时还可以看到每秒钟传输的数据量在218MB左右,刚好与“Bandwidth”列的值对应起来,网卡的带宽速率维持在1.82 Gbits/sec左右,而测试的服务器是千兆网卡,这个测试值也基本合理。在输出的最后,iperf还给出了总的数据发送、接收量,并给出了带宽速率平均值,通过这些值,基本可以判断网络带宽是否正常,网络传输状态是否稳定。

2.iperf提供很多参数,可以多角度、全方位地测试网络带宽利用率,例如,要改变iperf运行的时间和输出频率,可以通过“-t”和“-i”参数来实现。

[root@servera ~]# iperf3 -c 172.17.120.13 -t 20 -i 5

Connecting to host 172.17.120.13, port 5201

[ 4] local 172.17.120.12 port 33846connected to 172.17.120.13 port 5201

[ ID] Interval Transfer Bandwidth Retr Cwnd

[ 4] 0.00-5.00 sec 1.05 GBytes 1.80 Gbits/sec 1192 250KBytes

[ 4] 5.00-10.00 sec 1.06 GBytes 1.82 Gbits/sec 1219 182KBytes

[ 4] 10.00-15.00 sec 1.06 GBytes 1.83 Gbits/sec 1012 191KBytes

[ 4] 15.00-20.00 sec 1.06 GBytes 1.82 Gbits/sec 1237 254KBytes

-------------------------

[ ID] Interval Transfer Bandwidth Retr

[ 4] 0.00-20.00 sec 4.23 GBytes 1.82 Gbits/sec 4660 sender

[ 4] 0.00-20.00 sec 4.23 GBytes 1.82 Gbits/sec receiver

iperf Done.

--------------------------------------------------------------------------

##可以看出,输出状态的间隔变为每5秒钟一次,总共执行测试时间为20秒,测试的带宽速率仍然保持在1.82 Gbits/sec左右,唯一变化的是失败重传次数增加了。

3.为了模拟大量的数据传输,也可以指定要发送的数据量,这可以通过“-n”参数来实现。在指定“-n”参数后,“-t”参数失效,iperf在传输完毕指定大小的数据包后,自动结束。

[root@servera ~]# iperf3 -c 172.17.120.13 -i 10 -n 5000000000

Connecting to host 172.17.120.13, port 5201

[ 4] local 172.17.120.12 port 33850connected to 172.17.120.13 port 5201

[ ID] Interval Transfer Bandwidth Retr Cwnd

[ 4] 0.00-10.00 sec 2.11 GBytes 1.81 Gbits/sec 2308 250KBytes

[ 4] 10.00-20.00 sec 2.11 GBytes 1.81 Gbits/sec 2471 240KBytes

[ 4] 20.00-22.08 sec 448MBytes 1.81 Gbits/sec 560 212KBytes

-------------------------

[ ID] Interval Transfer Bandwidth Retr

[ 4] 0.00-22.08 sec 4.66 GBytes 1.81 Gbits/sec 5339 sender

[ 4] 0.00-22.08 sec 4.65 GBytes 1.81 Gbits/sec receiver

iperf Done.

--------------------------------------------------------------------------

##iperf客户端通过“-n”参数指定要传输的数据量。指定发送一个5GB左右的数据包,并且每隔10秒钟输出一次传输状态,从这个输出可以看出,当失败重传次数较多时,传输速率急速下降。

4.有时候,为了模拟更真实的TCP应用,iperf客户端允许从一个特定的文件发送数据,这可以通过“-F”参数实现。

[root@servera opt]# iperf3 -c 172.17.120.13 -F jdk-8u91-linux-x64.tar.gz -i 5 -t 20

Connecting to host 172.17.120.13, port 5201

[ 4] local 172.17.120.12 port 33874connected to 172.17.120.13 port 5201

[ ID] Interval Transfer Bandwidth Retr Cwnd

[ 4] 0.00-0.36 sec 73.6 MBytes 1.72 Gbits/sec 84 225KBytes

-------------------------

[ ID] Interval Transfer Bandwidth Retr

[ 4] 0.00-0.36 sec 73.6 MBytes 1.72 Gbits/sec 84 sender

Sent 73.6 MByte / 173MByte (42%) of jdk-8u91-linux-x64.tar.gz

[ 4] 0.00-0.36 sec 72.3 MBytes 1.69 Gbits/sec receiver

iperf Done.

--------------------------------------------------------------------------

##iperf客户端通过“-F”参数指定文件来发送数据。通过“-F”参数指定了一个jdk-8u91-linux-x64.tar.gz文件作为iperf要传输的数据,在使用此参数时,需要同时指定一个“-t”参数来设置要测试传输的时间,这个时间尽量设置长一些,因为在默认传输时间10秒内,这个文件可能还没有传完。

5.在使用iperf进行网络带宽测试时,如果没有指定发送方式,iperf客户端只会使用一个单一的线程,而iperf是支持多线程的,可以使用iperf提供的“-P”参数来设置多线程的数目,通过使用多线程,可以在一定程度上增加网络的吞吐量。

[root@servera opt]# iperf3 -c 172.17.120.13 -n 2000000000 -i 5 -f M

Connecting to host 172.17.120.13, port 5201

[ 4] local 172.17.120.12 port 33878connected to 172.17.120.13 port 5201

[ ID] Interval Transfer Bandwidth Retr Cwnd

[ 4] 0.00-5.00 sec 1.05 GBytes 216MBytes/sec 2370 272KBytes

[ 4] 5.00-8.84 sec 830MBytes 216MBytes/sec 886 207KBytes

-------------------------

[ ID] Interval Transfer Bandwidth Retr

[ 4] 0.00-8.84 sec 1.86 GBytes 216MBytes/sec 3256 sender

[ 4] 0.00-8.84 sec 1.86 GBytes 215MBytes/sec receiver

iperf Done.

--------------------------------------------------------------------------

##为了速率单位统一,这里使用“-f”参数将输出结果都通过MBytes来显示。传输1.86GBytes的数据消耗了8.84秒的时间,平均带宽速率为216 MBytes/sec(注意单位)。

6.使用多线程后,iperf传输同样大小数据量所消耗的时间和平均带宽速率。

[root@servera opt]# iperf3 -c 172.17.120.13 -n 2000000000 -i 5 -P 2 -f M

Connecting to host 172.17.120.13, port 5201

[ 4] local 172.17.120.12 port 33882connected to 172.17.120.13 port 5201

[ 6] local 172.17.120.12 port 33884connected to 172.17.120.13 port 5201

[ ID] Interval Transfer Bandwidth Retr Cwnd

[ 4] 0.00-5.00 sec 531MBytes 106MBytes/sec 804 195KBytes

[ 6] 0.00-5.00 sec 560MBytes 112MBytes/sec 846 265KBytes

[SUM] 0.00-5.00 sec 1.07 GBytes 218MBytes/sec 1650

-------------------------

[ 4] 5.00-8.71 sec 407MBytes 110MBytes/sec 639 170KBytes

[ 6] 5.00-8.71 sec 410MBytes 111MBytes/sec 634 202KBytes

[SUM] 5.00-8.71 sec 817MBytes 220MBytes/sec 1273

-------------------------

[ ID] Interval Transfer Bandwidth Retr

[ 4] 0.00-8.71 sec 938MBytes 108MBytes/sec 1443 sender

[ 4] 0.00-8.71 sec 936MBytes 108MBytes/sec receiver

[ 6] 0.00-8.71 sec 970MBytes 111MBytes/sec 1480 sender

[ 6] 0.00-8.71 sec 968MBytes 111MBytes/sec receiver

[SUM] 0.00-8.71 sec 1.86 GBytes 219MBytes/sec 2923 sender

[SUM] 0.00-8.71 sec 1.86 GBytes 219MBytes/sec receiver

iperf Done.

--------------------------------------------------------------------------

##这里通过“-P”参数开启了2个多线程,从传输时间上看,传输1.86GBytes的数据,消耗时间为8.71秒,比之前单线程的传输时间少了近0.07秒钟,在平均带宽速率上,从之前单线程的216 MBytes/sec提高到219 MBytes/sec,从这个结果可以看出,多线程对网络传输性能的提高不小。

6、测试UDP丢包和延迟

1.iperf也可以用于UDP数据包吞吐量、丢包率和延迟指标,但是由于UDP协议是一个非面向连接的轻量级传输协议,并且不提供可靠的数据传输服务,因此对UDP应用的关注点不是传输数据有多快,而是它的丢包率和延时指标。通过iperf的“-u”参数即可测试UDP应用的传输性能。

[root@servera opt]# iperf3 -c 172.17.120.13 -u -b 100M -f M -i 3

Connecting to host 172.17.120.13, port 5201

[ 4] local 172.17.120.12 port 50680connected to 172.17.120.13 port 5201

[ ID] Interval Transfer Bandwidth Total Datagrams

[ 4] 0.00-3.00 sec 34.6 MBytes 11.5 MBytes/sec 24875

[ 4] 3.00-6.00 sec 35.8 MBytes 11.9 MBytes/sec 25738

[ 4] 6.00-9.00 sec 35.7 MBytes 11.9 MBytes/sec 25633

[ 4] 9.00-10.00 sec 11.9 MBytes 11.9 MBytes/sec 8561

-------------------------

[ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams

[ 4] 0.00-10.00 sec 118MBytes 11.8 MBytes/sec 0.053 ms 26431/84807 (31%)

[ 4] Sent 84807datagrams

iperf Done.

--------------------------------------------------------------------------

##iperf传输100MB的UDP数据包的输出结果。重点关注虚线下的一段内容,在这段输出中,“Jitter”列表示抖动时间,或者称为传输延迟,“Lost/Total”列表示丢失的数据报和总的数据报数量,后面的31%是平均丢包的比率,“Datagrams”列显示的是总共传输数据报的数量。

2.这个输出结果过于简单,要了解更详细的UDP丢包和延时信息,可以在iperf服务端查看,因为在客户端执行传输测试的同时,服务端也会同时显示传输状态。

[root@serverb ~]# iperf3 -s -i 3

iperf3: OUT OF ORDER -incoming packet =84786and received packet =84793AND SP =5

iperf3: OUT OF ORDER -incoming packet =84788and received packet =84793AND SP =5

iperf3: OUT OF ORDER -incoming packet =84790and received packet =84793AND SP =5

iperf3: OUT OF ORDER -incoming packet =84792and received packet =84793AND SP =5

[ 5] 9.00-10.04 sec 11.9 MBytes 96.1 Mbits/sec 0.009 ms 3682/8550 (43%)

-------------------------

[ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams

[ 5] 0.00-10.04 sec 0.00 Bytes 0.00 bits/sec 0.009 ms 31126/84793 (37%)

[SUM] 0.0-10.0 sec 31126datagrams received out-of-order

-----------------------------------------------------------

Server listening on 5201

-----------------------------------------------------------

--------------------------------------------------------------------------

##在这个输出中,详细记录了在传输过程中,每个阶段的传输延时和丢包率,在UDP应用中随着传输数据的增大,丢包率和延时也随之增加。对于延时和丢包可以通过改变应用程序来缓解或修复,例如视频流应用,可以通过缓存数据的方式而可以容忍更大的延时。

7、JSON 格式输出

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

[root@servera opt]# iperf3 -c 172.17.120.13 -J -t 2

{

"start":{

"connected":[{

"socket":4,

"local_host":"172.17.120.12",

"local_port":33892,

"remote_host":"172.17.120.13",

"remote_port":5201

}],

"version":"iperf 3.1.7",

"system_info":"Linux servera 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC x86_64",

"timestamp":{

"time":"Mon, 18 Nov 14:57:35 GMT",

"timesecs":1574089055

},

"connecting_to":{

"host":"172.17.120.13",

"port":5201

},

"cookie":"servera.1574089055.168685.57df3fda7b",

"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.000089,

"seconds":1.000089,

"bytes":223387300,

"bits_per_second":1.786939e+09,

"retransmits":219,

"snd_cwnd":309520,

"rtt":1287,

"omitted":false

}],

"sum":{

"start":0,

"end":1.000089,

"seconds":1.000089,

"bytes":223387300,

"bits_per_second":1.786939e+09,

"retransmits":219,

"omitted":false

}

}, {

"streams":[{

"socket":4,

"start":1.000089,

"end":2.000118,

"seconds":1.000029,

"bytes":223362480,

"bits_per_second":1.786848e+09,

"retransmits":254,

"snd_cwnd":194180,

"rtt":757,

"omitted":false

}]

如果觉得《iperf 服务端发送数据_iperf网络测试工具》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。