iperf网络新能评估
什么是网络性能评估
网络新能评估是指检测网络带宽的使用率,最大化利用网络带宽,由于网络设计不合理、网络安全存在漏洞,会导致网络利用率低。iperf正是发现这种问题的网络测试工具。
iperf简介
iperf是一款基于TCP/IP和UDP/IP的网络性能测试工具。可以用来测量网络带宽和网络质量,提供网络延迟抖动、数据包丢失、最大传输单元等统计信息,可以根据这些统计信息判断网络性能问题,定位网络瓶颈。
iperf的主要功能
(1)TCP方面
测试网络带宽
支持多线程,在客户端与服务器端支持多连接
报告MSS/MTU值
支持TCP窗口值得定义并通过套接字缓冲
(2)UDP方面
可以设置指定带宽的UDP数据流
可以测试网络抖动、丢包数
支持多播测试
支持多线程,在客户端与服务器端支持多连接
[root@node2 ~]# yum install -y iperf3
参数
服务器端参数
命令行参数 | 参数含义 |
-s | 以服务端模式启动,默认启动监听端口为5201,可以通过-p选项指定监听端口 |
-D | 以守护进程启动,与-s选项联用 |
客户端参数
客户端参数 | 参数含义 |
-c | 以客户端模式启动iperf,例如:iperf -c 10.0.0.10,其中10.0.0.10位服务器端地址 |
-u | 使用UDP协议 |
-b[kmgKMG] | 指定UDP模式使用的带宽。单位bit/sec,与-u选项相关,默认是1Mbit/sec |
-t | 指定数据包传输的总时间,iperf在指定时间内,重复发送指定长度的数据包 |
-n[kmgKMG] | 指定传输数据包的字节数,例如:iperf -c 10.0.0.10 -n 100M |
-l | 指定读写缓冲区长度。 TCP方式默认128K UDP方式默认大小1470 |
-P,--parallel | 指定客户端和服务端之间使用的线程数,默认1个线程。 需要客户端和服务端同时使用此参数 |
-R | 切换数据发送,接收模式 例如,客户端发送,服务端接收,设置此参数后,变为服务端发送,客户端接收 |
-w[KM] | 指定套接字缓冲区大小 在TCP模式下,此设置为TCP窗口的大小。 在UDP模式下,此参数为接受UDP数据包的缓冲大小,用来限制可以接收数据包的最大值 |
-B | 绑定一个主机地址或接口,此参数仅用于具有多个网络接口的主机。 在UDP模式下,此参数用于绑定和加入一个多播组 |
-M | 设置TCP最大信息段的值 |
-N | 设置TCP无延迟 |
公共参数
命令行参数 | 参数含义 |
-f,[kmgKMG] | 指定带宽输出单位,分别表示为Kbits, Mbits, KBytes, MBytes,GBytes,默认是MBytes 例如:iperf -c 10.0.0.10 -f M |
-p |
指定服务端使用的端口或客户端连接的端口,如: iperf -c 10.0.0.10 -p 9527 |
-i | 指定每次报告生成的时间间隔。单位:秒 |
-F |
指定文件作为数据源进行带宽测试,例如: iperf -c 10.0.0.10 -F web-ixdba.tar.gz |
应用举例
服务端启动iperf3
[root@node2 ~]# iperf3 -s 10.0.0.52 ----------------------------------------------------------- Server listening on 5201 -----------------------------------------------------------
测试tcp吞吐量
在任意客户端执行iperf命令,将从客户端发送数据到服务端。输出发送的数据量和网卡平均带宽。
客户端运行结果
[root@node03 ~]# iperf3 -c 10.0.0.52 Connecting to host 10.0.0.52, port 5201 [ 4] local 10.0.0.53 port 33524 connected to 10.0.0.52 port 5201 [ ID] Interval Transfer Bandwidth Retr Cwnd [ 4] 0.00-1.00 sec 362 MBytes 3.04 Gbits/sec 0 1.29 MBytes [ 4] 1.00-2.00 sec 342 MBytes 2.87 Gbits/sec 73 1.41 MBytes [ 4] 2.00-3.00 sec 421 MBytes 3.53 Gbits/sec 0 1.55 MBytes [ 4] 3.00-4.00 sec 411 MBytes 3.45 Gbits/sec 0 1.69 MBytes [ 4] 4.00-5.00 sec 429 MBytes 3.59 Gbits/sec 0 1.82 MBytes [ 4] 5.00-6.00 sec 432 MBytes 3.64 Gbits/sec 20 1.38 MBytes [ 4] 6.00-7.00 sec 442 MBytes 3.71 Gbits/sec 0 1.57 MBytes [ 4] 7.00-8.00 sec 446 MBytes 3.74 Gbits/sec 0 1.71 MBytes [ 4] 8.00-9.00 sec 436 MBytes 3.66 Gbits/sec 0 1.82 MBytes [ 4] 9.00-10.00 sec 405 MBytes 3.40 Gbits/sec 22 1.39 MBytes - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bandwidth Retr [ 4] 0.00-10.00 sec 4.03 GBytes 3.46 Gbits/sec 115 sender [ 4] 0.00-10.00 sec 4.03 GBytes 3.46 Gbits/sec receiver iperf Done.
服务端结果
[root@node2 ~]# iperf3 -s 10.0.0.52 ----------------------------------------------------------- Server listening on 5201 ----------------------------------------------------------- Accepted connection from 10.0.0.53, port 33522 [ 5] local 10.0.0.52 port 5201 connected to 10.0.0.53 port 33524 [ ID] Interval Transfer Bandwidth [ 5] 0.00-1.00 sec 345 MBytes 2.89 Gbits/sec [ 5] 1.00-2.00 sec 344 MBytes 2.89 Gbits/sec [ 5] 2.00-3.00 sec 417 MBytes 3.50 Gbits/sec [ 5] 3.00-4.00 sec 416 MBytes 3.49 Gbits/sec [ 5] 4.00-5.00 sec 425 MBytes 3.56 Gbits/sec [ 5] 5.00-6.00 sec 435 MBytes 3.65 Gbits/sec [ 5] 6.00-7.00 sec 441 MBytes 3.70 Gbits/sec [ 5] 7.00-8.00 sec 445 MBytes 3.72 Gbits/sec [ 5] 8.00-9.00 sec 438 MBytes 3.68 Gbits/sec [ 5] 9.00-10.00 sec 408 MBytes 3.43 Gbits/sec [ 5] 10.00-10.04 sec 13.6 MBytes 2.74 Gbits/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 4.03 GBytes 3.45 Gbits/sec receiver
运行结果说明
第一行说明了服务器端地址和端口 第二行为客户端连接服务端使用的地址和端口 第三行之后: Interval 表示传输数据的时间间隔 Transfer 每秒传输的数据量 Bandwidth 传输数据使用的网络带宽 Retr 重传次数 Cwnd 不清楚干嘛的 分割线之后的说明了本次测试的发送端和接收端概要 本次测试结果说明:10秒内,客户端发送了4.03 GBytes数据,服务端接收了4.03 GBytes,客户端重发了115次?总带宽3.46 Gbits/sec
修改测试频率 -t -i
[root@node03 ~]# iperf3 -c 10.0.0.52 -t 20 -i 5 Connecting to host 10.0.0.52, port 5201 [ 4] local 10.0.0.53 port 33532 connected to 10.0.0.52 port 5201 [ ID] Interval Transfer Bandwidth Retr Cwnd [ 4] 0.00-5.00 sec 2.14 GBytes 3.67 Gbits/sec 62 1.76 MBytes [ 4] 5.00-10.00 sec 2.19 GBytes 3.77 Gbits/sec 47 1.83 MBytes [ 4] 10.00-15.00 sec 2.20 GBytes 3.78 Gbits/sec 27 1.82 MBytes [ 4] 15.00-20.00 sec 2.18 GBytes 3.74 Gbits/sec 52 1.76 MBytes - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bandwidth Retr [ 4] 0.00-20.00 sec 8.71 GBytes 3.74 Gbits/sec 188 sender [ 4] 0.00-20.00 sec 8.71 GBytes 3.74 Gbits/sec receiver iperf Done. 20秒内,没5秒输出一次结果,可以看到唯一变化的是重传次数增加了
使用-n参数指定传输数据量
[root@node03 ~]# iperf3 -c 10.0.0.52 -n 5000000000 -i 10 Connecting to host 10.0.0.52, port 5201 [ 4] local 10.0.0.53 port 33544 connected to 10.0.0.52 port 5201 [ ID] Interval Transfer Bandwidth Retr Cwnd [ 4] 0.00-10.00 sec 3.85 GBytes 3.31 Gbits/sec 67 1.80 MBytes [ 4] 10.00-12.01 sec 828 MBytes 3.46 Gbits/sec 22 1.45 MBytes - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bandwidth Retr [ 4] 0.00-12.01 sec 4.66 GBytes 3.33 Gbits/sec 89 sender [ 4] 0.00-12.01 sec 4.66 GBytes 3.33 Gbits/sec receiver
可以看到,当一次传输5G数据的时候,失败重传次数增多了,传输速率下降
-P选项开启多线程处理
默认的iperf使用单线程传输数据,下面通过例子进行对比单线程和多线程
(1)单线程
[root@node2 ~]# iperf3 -s ----------------------------------------------------------- Server listening on 5201 ----------------------------------------------------------- Accepted connection from 10.0.0.53, port 39656 [ 5] local 10.0.0.52 port 5201 connected to 10.0.0.53 port 39658 [ ID] Interval Transfer Bandwidth [ 5] 0.00-1.00 sec 347 MBytes 2.91 Gbits/sec [ 5] 1.00-2.00 sec 410 MBytes 3.44 Gbits/sec [ 5] 2.00-3.00 sec 368 MBytes 3.09 Gbits/sec [ 5] 3.00-4.00 sec 367 MBytes 3.08 Gbits/sec [ 5] 4.00-5.00 sec 425 MBytes 3.57 Gbits/sec [ 5] 5.00-6.00 sec 393 MBytes 3.30 Gbits/sec [ 5] 6.00-7.00 sec 385 MBytes 3.23 Gbits/sec [ 5] 7.00-8.00 sec 360 MBytes 3.02 Gbits/sec [ 5] 8.00-9.00 sec 400 MBytes 3.36 Gbits/sec [ 5] 9.00-10.00 sec 371 MBytes 3.11 Gbits/sec [ 5] 10.00-11.00 sec 335 MBytes 2.81 Gbits/sec [ 5] 11.00-12.00 sec 379 MBytes 3.18 Gbits/sec [ 5] 12.00-12.59 sec 227 MBytes 3.22 Gbits/sec - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bandwidth [ 5] 0.00-12.59 sec 0.00 Bytes 0.00 bits/sec sender [ 5] 0.00-12.59 sec 4.66 GBytes 3.18 Gbits/sec receiver
[root@node03 ~]# iperf3 -c 10.0.0.52 -i 10 -f M -n 5000000000 Connecting to host 10.0.0.52, port 5201 [ 4] local 10.0.0.53 port 39658 connected to 10.0.0.52 port 5201 [ ID] Interval Transfer Bandwidth Retr Cwnd [ 4] 0.00-10.00 sec 3.75 GBytes 384 MBytes/sec 80 1.64 MBytes [ 4] 10.00-12.55 sec 928 MBytes 364 MBytes/sec 53 1.56 MBytes - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bandwidth Retr [ 4] 0.00-12.55 sec 4.66 GBytes 380 MBytes/sec 133 sender [ 4] 0.00-12.55 sec 4.66 GBytes 380 MBytes/sec receiver iperf Done.
我们使用-f选项指定了传输结果以MBytes/sec来展示,从上面结果可以看出传输5GB数据用了12.55秒,平均带宽速率为380 MBytes/sec,下面为多线程时iperf的总体概览:
服务端 ----------------------------------------------------------- Server listening on 5201 ----------------------------------------------------------- Accepted connection from 10.0.0.53, port 39660 [ 5] local 10.0.0.52 port 5201 connected to 10.0.0.53 port 39662 [ 7] local 10.0.0.52 port 5201 connected to 10.0.0.53 port 39664 [ ID] Interval Transfer Bandwidth [ 5] 0.00-1.00 sec 207 MBytes 1.74 Gbits/sec [ 7] 0.00-1.00 sec 187 MBytes 1.57 Gbits/sec [SUM] 0.00-1.00 sec 394 MBytes 3.30 Gbits/sec - - - - - - - - - - - - - - - - - - - - - - - - - [ 5] 1.00-2.00 sec 198 MBytes 1.66 Gbits/sec [ 7] 1.00-2.00 sec 223 MBytes 1.87 Gbits/sec [SUM] 1.00-2.00 sec 420 MBytes 3.53 Gbits/sec - - - - - - - - - - - - - - - - - - - - - - - - - [ 5] 2.00-3.00 sec 221 MBytes 1.85 Gbits/sec [ 7] 2.00-3.00 sec 229 MBytes 1.92 Gbits/sec [SUM] 2.00-3.00 sec 449 MBytes 3.76 Gbits/sec - - - - - - - - - - - - - - - - - - - - - - - - - [ 5] 3.00-4.00 sec 201 MBytes 1.69 Gbits/sec [ 7] 3.00-4.00 sec 244 MBytes 2.05 Gbits/sec [SUM] 3.00-4.00 sec 445 MBytes 3.73 Gbits/sec - - - - - - - - - - - - - - - - - - - - - - - - - [ 5] 4.00-5.00 sec 242 MBytes 2.03 Gbits/sec [ 7] 4.00-5.00 sec 218 MBytes 1.83 Gbits/sec [SUM] 4.00-5.00 sec 460 MBytes 3.87 Gbits/sec - - - - - - - - - - - - - - - - - - - - - - - - - [ 5] 5.00-6.00 sec 254 MBytes 2.13 Gbits/sec [ 7] 5.00-6.00 sec 196 MBytes 1.65 Gbits/sec [SUM] 5.00-6.00 sec 450 MBytes 3.78 Gbits/sec - - - - - - - - - - - - - - - - - - - - - - - - - [ 5] 6.00-7.00 sec 213 MBytes 1.79 Gbits/sec [ 7] 6.00-7.00 sec 217 MBytes 1.82 Gbits/sec [SUM] 6.00-7.00 sec 431 MBytes 3.61 Gbits/sec - - - - - - - - - - - - - - - - - - - - - - - - - [ 5] 7.00-8.00 sec 206 MBytes 1.73 Gbits/sec [ 7] 7.00-8.00 sec 237 MBytes 1.99 Gbits/sec [SUM] 7.00-8.00 sec 443 MBytes 3.72 Gbits/sec - - - - - - - - - - - - - - - - - - - - - - - - - [ 5] 8.00-9.00 sec 183 MBytes 1.53 Gbits/sec [ 7] 8.00-9.00 sec 204 MBytes 1.71 Gbits/sec [SUM] 8.00-9.00 sec 387 MBytes 3.24 Gbits/sec - - - - - - - - - - - - - - - - - - - - - - - - - [ 5] 9.00-10.00 sec 195 MBytes 1.64 Gbits/sec [ 7] 9.00-10.00 sec 243 MBytes 2.04 Gbits/sec [SUM] 9.00-10.00 sec 439 MBytes 3.67 Gbits/sec - - - - - - - - - - - - - - - - - - - - - - - - - [ 5] 10.00-10.98 sec 209 MBytes 1.80 Gbits/sec [ 7] 10.00-10.98 sec 237 MBytes 2.04 Gbits/sec [SUM] 10.00-10.98 sec 446 MBytes 3.84 Gbits/sec - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bandwidth [ 5] 0.00-10.98 sec 0.00 Bytes 0.00 bits/sec sender [ 5] 0.00-10.98 sec 2.27 GBytes 1.78 Gbits/sec receiver [ 7] 0.00-10.98 sec 0.00 Bytes 0.00 bits/sec sender [ 7] 0.00-10.98 sec 2.38 GBytes 1.86 Gbits/sec receiver [SUM] 0.00-10.98 sec 0.00 Bytes 0.00 bits/sec sender [SUM] 0.00-10.98 sec 4.65 GBytes 3.64 Gbits/sec receiver 客户端 [root@node03 ~]# iperf3 -c 10.0.0.52 -i 10 -f M -n 5000000000 -P 2 Connecting to host 10.0.0.52, port 5201 [ 4] local 10.0.0.53 port 39662 connected to 10.0.0.52 port 5201 [ 6] local 10.0.0.53 port 39664 connected to 10.0.0.52 port 5201 [ ID] Interval Transfer Bandwidth Retr Cwnd [ 4] 0.00-10.00 sec 2.08 GBytes 213 MBytes/sec 245 641 KBytes [ 6] 0.00-10.00 sec 2.16 GBytes 221 MBytes/sec 248 819 KBytes [SUM] 0.00-10.00 sec 4.24 GBytes 434 MBytes/sec 493 - - - - - - - - - - - - - - - - - - - - - - - - - [ 4] 10.00-10.94 sec 201 MBytes 215 MBytes/sec 0 834 KBytes [ 6] 10.00-10.94 sec 229 MBytes 244 MBytes/sec 0 997 KBytes [SUM] 10.00-10.94 sec 430 MBytes 460 MBytes/sec 0 - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bandwidth Retr [ 4] 0.00-10.94 sec 2.28 GBytes 213 MBytes/sec 245 sender [ 4] 0.00-10.94 sec 2.27 GBytes 213 MBytes/sec receiver [ 6] 0.00-10.94 sec 2.38 GBytes 223 MBytes/sec 248 sender [ 6] 0.00-10.94 sec 2.38 GBytes 223 MBytes/sec receiver [SUM] 0.00-10.94 sec 4.66 GBytes 436 MBytes/sec 493 sender [SUM] 0.00-10.94 sec 4.65 GBytes 436 MBytes/sec receiver iperf Done.
可以看到传输时间减少了2s,传输速率上也提高到436 MBytes/sec
测试UDP传输丢包和延迟
iperf可以用于UDP协议的数据包传输测试,但由于UDP协议是非面向连接协议,不提供可靠的传输服务,对UDP传输不关注传输速度,只关注丢包率和延迟。
使用-u选项测试UDP协议
客户端结果展示
[root@node03 ~]# iperf3 -c 10.0.0.52 -u -b 100M -f M -i 3 Connecting to host 10.0.0.52, port 5201 [ 4] local 10.0.0.53 port 52036 connected to 10.0.0.52 port 5201 [ ID] Interval Transfer Bandwidth Total Datagrams [ 4] 0.00-3.00 sec 34.8 MBytes 11.6 MBytes/sec 25210 [ 4] 3.00-6.00 sec 35.9 MBytes 12.0 MBytes/sec 25962 [ 4] 6.00-9.00 sec 35.6 MBytes 11.9 MBytes/sec 25814 [ 4] 9.00-10.00 sec 12.0 MBytes 12.0 MBytes/sec 8658
- - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams [ 4] 0.00-10.00 sec 118 MBytes 11.8 MBytes/sec 0.103 ms 0/85644 (0%) [ 4] Sent 85644 datagrams iperf Done.
我们重点关注虚线以下内容
Jitter 表示抖动时间或者网络延迟
Lost/Total 分别表示丢包数量和总数据包数量,百分数表示平均丢包比率
Datagrams 总的数据包数量
下面是服务端结果
Server listening on 5201 ----------------------------------------------------------- Accepted connection from 10.0.0.53, port 39666 [ 5] local 10.0.0.52 port 5201 connected to 10.0.0.53 port 52036 [ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams [ 5] 0.00-1.00 sec 11.1 MBytes 92.9 Mbits/sec 0.018 ms 0/8021 (0%) [ 5] 1.00-2.00 sec 11.8 MBytes 99.4 Mbits/sec 0.119 ms 0/8581 (0%) [ 5] 2.00-3.00 sec 11.9 MBytes 99.7 Mbits/sec 0.018 ms 0/8608 (0%) [ 5] 3.00-4.00 sec 11.9 MBytes 100 Mbits/sec 0.018 ms 0/8635 (0%) [ 5] 4.00-5.00 sec 12.0 MBytes 101 Mbits/sec 0.098 ms 0/8702 (0%) [ 5] 5.00-6.00 sec 11.9 MBytes 100 Mbits/sec 0.017 ms 0/8625 (0%) [ 5] 6.00-7.00 sec 11.8 MBytes 99.1 Mbits/sec 0.094 ms 0/8562 (0%) [ 5] 7.00-8.00 sec 12.0 MBytes 101 Mbits/sec 0.018 ms 0/8710 (0%) [ 5] 8.00-9.00 sec 11.8 MBytes 99.0 Mbits/sec 0.020 ms 0/8542 (0%) [ 5] 9.00-10.00 sec 12.0 MBytes 100 Mbits/sec 0.103 ms 0/8658 (0%) [ 5] 10.00-10.04 sec 0.00 Bytes 0.00 bits/sec 0.103 ms 0/0 (0%) - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams [ 5] 0.00-10.04 sec 0.00 Bytes 0.00 bits/sec 0.103 ms 0/85644 (0%) ----------------------------------------------------------- Server listening on 5201 -----------------------------------------------------------
对于丢包和延迟可以通过改变应用程序来缓解,通过增加缓存的方式可以容忍更大的延迟。
posted on 2020-03-30 11:43 hopeless-dream 阅读(1144) 评论(0) 编辑 收藏 举报