Iperf 是一个网络性能测试工具。Iperf可以测试最大TCP和UDP带宽性能,具有多种参数和UDP特性,可以根据需要调整,可以报告带宽、延迟抖动和数据包丢失。下载地址:https://iperf.fr/iperf-download.php#fedora
用户文档地址:https://iperf.fr/iperf-doc.php
用于输出数据包的服务类型。(许多路由器忽略了TOS字段。)您可以使用“0x”前缀指定十六进制值,在八进制中使用“0”前缀,或在十进制中。例如,'0x10'十六进制='020'八进制='16'小数。RFC 1349中指定的图号是:
IPTOS_LOWDELAY minimize delay 0x10
IPTOS_THROUGHPUT maximize throughput 0x08
IPTOS_RELIABILITY maximize reliability 0x04
IPTOS_LOWCOST minimize cost 0x02
-L, --flowlabel n设置IPv6流标签(目前仅在Linux上支持)。-Z, --zerocopy使用“零拷贝”发送数据的方法,例如sendfile(2),而不是通常的写入(2)。这使用了更少的CPU。-O, --omit n忽略测试的前n秒,跳过TCP TCP慢启动周期。-T, --title str在每个输出行前面加上这个字符串。-C, --linux-congestion algo设置拥塞控制算法(Linux只针对iPerf 3.0、Linux和FreeBSD为iPerf 3.1)。
带宽测试通常采用UDP模式,因为能测出极限带宽、时延抖动、丢包率。在进行测试时,首先以链路理论带宽作为数据发送速率进行测试,例如,从客户端到服务器之间的链路的理论带宽为100Mbps,先用-b 100M进行测试,然后根据测试结果(包括实际带宽,时延抖动和丢包率),再以实际带宽作为数据发送速率进行测试,会发现时延抖动和丢包率比第一次好很多,重复测试几次,就能得出稳定的实际带宽。
server:
[root@server-A ~]# iperf3 -s -V iperf 3.1.3 Linux server-A 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 ----------------------------------------------------------- Server listening on 5201 ----------------------------------------------------------- Time: Wed, 20 Sep 2017 16:10:18 GMT Accepted connection from 192.168.1.120, port 41138 Cookie: client-B.1505859092.776727.2dfae62a4 [ 5] local 192.168.1.130 port 5201 connected to 192.168.1.120 port 51883 Starting Test: protocol: UDP, 1 streams, 8192 byte blocks, omitting 0 seconds, 2 second test [ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams [ 5] 0.00-1.00 sec 120 KBytes 982 Kbits/sec 1638910.193 ms 0/15 (0%) [ 5] 1.00-2.00 sec 128 KBytes 1.05 Mbits/sec 583573.766 ms 0/16 (0%) [ 5] 2.00-2.05 sec 0.00 Bytes 0.00 bits/sec 583573.766 ms 0/0 (0%) - - - - - - - - - - - - - - - - - - - - - - - - - Test Complete. Summary Results: [ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams [ 5] 0.00-2.05 sec 0.00 Bytes 0.00 bits/sec 583573.766 ms 0/31 (0%) CPU Utilization: local/receiver 0.0% (0.0%u/0.0%s), remote/sender 0.0% (0.0%u/0.0%s) iperf 3.1.3 Linux server-A 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 ----------------------------------------------------------- Server listening on 5201 -----------------------------------------------------------
client:
#设置传输时间为2秒 [root@client-B ~]# iperf3 -c 192.168.1.130 -t 2 -u Connecting to host 192.168.1.130, port 5201 [ 4] local 192.168.1.120 port 51883 connected to 192.168.1.130 port 5201 [ ID] Interval Transfer Bandwidth Total Datagrams [ 4] 0.00-1.01 sec 128 KBytes 1.04 Mbits/sec 16 [ 4] 1.01-2.00 sec 128 KBytes 1.05 Mbits/sec 16 - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams [ 4] 0.00-2.00 sec 256 KBytes 1.05 Mbits/sec 583573.766 ms 0/31 (0%) [ 4] Sent 31 datagrams iperf Done.
#客户端同时向服务器端发起30个连接线程,以5Mbps为数据发送速率。 [root@client-B ~]# iperf3 -u -c 192.168.1.130 -b 5M -P 30 -t 60
#以100M为数据发送速率,进行上下行带宽测试。 #上传带宽测试 [root@client-B ~]# iperf3 -u -c 192.168.1.130 -b 100M -t 60 #下载带宽测试,使用-R选项 [root@client-B ~]# iperf3 -u -c 192.168.1.130 -b 100M -R -t 60
server:
[root@server-A ~]# iperf3 -s -V iperf 3.1.3 Linux server-A 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 ----------------------------------------------------------- Server listening on 5201 ----------------------------------------------------------- Time: Wed, 20 Sep 2017 16:30:44 GMT Accepted connection from 192.168.1.120, port 41158 Cookie: client-B.1505860318.231455.1c28c3a96 TCP MSS: 1448 (default) [ 5] local 192.168.1.130 port 5201 connected to 192.168.1.120 port 41160 Starting Test: protocol: TCP, 1 streams, 131072 byte blocks, omitting 0 seconds, 2 second test [ ID] Interval Transfer Bandwidth [ 5] 0.00-1.00 sec 499 MBytes 4.18 Gbits/sec [ 5] 1.00-2.00 sec 499 MBytes 4.19 Gbits/sec [ 5] 2.00-2.04 sec 17.8 MBytes 3.79 Gbits/sec - - - - - - - - - - - - - - - - - - - - - - - - - Test Complete. Summary Results: [ ID] Interval Transfer Bandwidth [ 5] 0.00-2.04 sec 0.00 Bytes 0.00 bits/sec sender [ 5] 0.00-2.04 sec 1016 MBytes 4.18 Gbits/sec receiver CPU Utilization: local/receiver 5.4% (0.0%u/5.4%s), remote/sender 0.0% (0.0%u/0.0%s)
client:
#在tcp模式下,客户端到服务器192.168.1.1上传带宽测试,测试时间为60秒。 [root@client-B ~]# iperf3 -c 192.168.1.130 -t 60 Connecting to host 192.168.1.130, port 5201 [ 4] local 192.168.1.120 port 41226 connected to 192.168.1.130 port 5201 [ ID] Interval Transfer Bandwidth Retr Cwnd [ 4] 0.00-1.00 sec 497 MBytes 4.17 Gbits/sec 0 2.03 MBytes [ 4] 1.00-2.00 sec 464 MBytes 3.89 Gbits/sec 0 2.49 MBytes [ 4] 2.00-3.00 sec 508 MBytes 4.25 Gbits/sec 71 1.80 MBytes [ 4] 3.00-4.00 sec 532 MBytes 4.47 Gbits/sec 0 1.88 MBytes [ 4] 4.00-5.00 sec 520 MBytes 4.36 Gbits/sec 0 1.97 MBytes [ 4] 5.00-6.00 sec 475 MBytes 3.98 Gbits/sec 0 2.04 MBytes [ 4] 6.00-7.00 sec 519 MBytes 4.36 Gbits/sec 59 1.48 MBytes ... - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bandwidth Retr [ 4] 0.00-7.52 sec 3.69 GBytes 4.22 Gbits/sec 130 sender [ 4] 0.00-7.52 sec 0.00 Bytes 0.00 bits/sec receiver iperf3: interrupt - the client has terminated
#客户端同时向服务器端发起30个连接线程。 [root@client-B ~]# iperf3 -c 192.168.1.130 -P 30 -t 60
#进行上下行带宽测试。 #上传带宽测试 [root@client-B ~]# iperf3 -c 192.168.1.130 -t 60 #下载带宽测试,使用-R选项 [root@client-B ~]# iperf3 -c 192.168.1.130 -R -t 60
iperf3介绍到此结束;有兴趣的朋友可以看下用户文档,其中也有iperf版本2的详细介绍
***********************************************************
学习永远不晚。——高尔基
***********************************************************
转载于:https://www.cnblogs.com/chengd/p/7572066.html
相关资源:JAVA上百实例源码以及开源项目