Iperf介绍
iperf是一个基于TCP/IP和UDP/IP的网络性能测试工具,用于检测网络带宽使用率和网络质量,能测试最大TCP和UDP带宽性能,可以报告带宽、网络延迟抖动、数据包丢失率和最大传输单元等统计信息等。如测试服务器和网络设备如路由器,交换机,防火墙等的网络性能。
Iperf的主要功能
1、TCP方面
测试网络带宽
支持多线程,在客户端与服务端支持多重连接
报告MSS/MTU值大小
支持TCP窗口值自定义并可通过套接字缓冲
2、UDP方面
可以设置指定带宽的UDP数据流
可以测试网络抖动值、丢包数
支持多播测试
支持多线程,在客户端与服务器端支持多重连接
Iperf的安装
1、下载源码包,官方地址:https://iperf.fr/iperf-download.php
2、安装
[root@web1 ~]# tar zxf iperf-3.1.2-source.tar.gz [root@web1 ~]# cd iperf-3.1.2 [root@web1 iperf-3.1.2]# ./configure [root@web1 iperf-3.1.2]# make && make install
3、参数(iperf3 -h)
[root@web1 ~]# iperf3 -h Usage: iperf [-s|-c host] [options] iperf [-h|--help] [-v|--version] Server or Client: -p, --port # server port to listen on/connect to -f, --format [kmgKMG] format to report: Kbits, Mbits, KBytes, MBytes -i, --interval # seconds between periodic bandwidth reports -F, --file name xmit/recv the specified file -A, --affinity n/n,m set CPU affinity -B, --bindbind to a specific interface -V, --verbose more detailed output -J, --json output in JSON format --logfile f send output to a log file -d, --debug emit debugging output -v, --version show version information and quit -h, --help show this message and quit Server specific: -s, --server run in server mode -D, --daemon run the server as a daemon -I, --pidfile file write PID file -1, --one-off handle one client connection then exit Client specific: -c, --client run in client mode, connecting to -u, --udp use UDP rather than TCP -b, --bandwidth #[KMG][/#] target bandwidth in bits/sec (0 for unlimited) (default 1 Mbit/sec for UDP, unlimited for TCP) (optional slash and packet count for burst mode) -t, --time # time in seconds to transmit for (default 10 secs) -n, --bytes #[KMG] number of bytes to transmit (instead of -t) -k, --blockcount #[KMG] number of blocks (packets) to transmit (instead of -t or -n) -l, --len #[KMG] length of buffer to read or write (default 128 KB for TCP, 8 KB for UDP) --cport bind to a specific client port (TCP and UDP, default: ephemeral port) -P, --parallel # number of parallel client streams to run -R, --reverse run in reverse mode (server sends, client receives) -w, --window #[KMG] set window size / socket buffer size -C, --congestion set TCP congestion control algorithm (Linux and FreeBSD only) -M, --set-mss # set TCP/SCTP maximum segment size (MTU - 40 bytes) -N, --no-delay set TCP/SCTP no delay, disabling Nagle's Algorithm -4, --version4 only use IPv4 -6, --version6 only use IPv6 -S, --tos N set the IP 'type of service' -L, --flowlabel N set the IPv6 flow label (only supported on Linux) -Z, --zerocopy use a 'zero copy' method of sending data -O, --omit N omit the first n seconds -T, --title str prefix every output line with this string --get-server-output get results from server --udp-counters-64bit use 64-bit counters in UDP test packets [KMG] indicates options that support a K/M/G suffix for kilo-, mega-, or giga- iperf3 homepage at: http://software.es.net/iperf/ Report bugs to: https://github.com/esnet/iperf
Iperf应用实例
iperf是以C/S模式工作,运行于服务端和客户端下。服务端主要用于监听到达的测试请求,而客户端主要用于发起连接会话。因此要使用iperf,需要两台服务器,一台运行在服务器模式下,一台运行在客户端模式下。
1、测试TCP吞吐量
启动一个服务器端,使用iperf -s命令,默认监听5201端口,在客户端使用iperf -c +服务端ip,运行测试(这里使用web1作为服务端,web2作为客户端)
由输出结果看出,iperf默认输出10s的状态,Transfer列输出每秒的数量量在370MB左右,Bandwidth列显示网卡的速率
2、指定iperf的运行时间(-t参数)和输出速率(-i参数)
##指定20秒内每隔5秒输出一次结果 [root@web2 ~]# iperf3 -c 192.168.1.250 -t 20 -i 5 Connecting to host 192.168.1.250, port 5201 [ 4] local 192.168.1.209 port 55780 connected to 192.168.1.250 port 5201 [ ID] Interval Transfer Bandwidth Retr Cwnd [ 4] 0.00-5.00 sec 1.79 GBytes 3.07 Gbits/sec 0 1.07 MBytes [ 4] 5.00-10.00 sec 1.85 GBytes 3.18 Gbits/sec 0 1.16 MBytes [ 4] 10.00-15.00 sec 1.83 GBytes 3.14 Gbits/sec 0 1.20 MBytes [ 4] 15.00-20.00 sec 1.78 GBytes 3.06 Gbits/sec 0 1.24 MBytes - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bandwidth Retr [ 4] 0.00-20.00 sec 7.25 GBytes 3.11 Gbits/sec 0 sender [ 4] 0.00-20.00 sec 7.24 GBytes 3.11 Gbits/sec receiver iperf Done.
3、指定发送数据量(-n参数)
#指定发送一个5GB左右的数据包,并且每隔2秒输出状态结果 [root@web2 ~]# iperf3 -c 192.168.1.250 -i 2 -n 5000000000 Connecting to host 192.168.1.250, port 5201 [ 4] local 192.168.1.209 port 56432 connected to 192.168.1.250 port 5201 [ ID] Interval Transfer Bandwidth Retr Cwnd [ 4] 0.00-2.00 sec 758 MBytes 3.18 Gbits/sec 0 952 KBytes [ 4] 2.00-4.00 sec 769 MBytes 3.23 Gbits/sec 0 984 KBytes [ 4] 4.00-6.00 sec 757 MBytes 3.17 Gbits/sec 0 1.01 MBytes [ 4] 6.00-8.00 sec 684 MBytes 2.87 Gbits/sec 0 1.05 MBytes [ 4] 8.00-10.00 sec 734 MBytes 3.08 Gbits/sec 0 1.08 MBytes [ 4] 10.00-12.00 sec 754 MBytes 3.16 Gbits/sec 0 1.11 MBytes [ 4] 12.00-12.88 sec 313 MBytes 2.99 Gbits/sec 0 1.12 MBytes - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bandwidth Retr [ 4] 0.00-12.88 sec 4.66 GBytes 3.11 Gbits/sec 0 sender [ 4] 0.00-12.88 sec 4.65 GBytes 3.10 Gbits/sec receiver iperf Done.
##指定一个文件传输(-F) [root@web2 ~]# du -sh ntopng-2.2.tar.gz 88M ntopng-2.2.tar.gz [root@web2 ~]# iperf3 -c 192.168.1.250 -F ntopng-2.2.tar.gz -t 20-i 2 Connecting to host 192.168.1.250, port 5201 [ 4] local 192.168.1.209 port 56948 connected to 192.168.1.250 port 5201 [ ID] Interval Transfer Bandwidth Retr Cwnd [ 4] 0.00-0.12 sec 36.7 MBytes 2.47 Gbits/sec 0 420 KBytes - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bandwidth Retr [ 4] 0.00-0.12 sec 36.7 MBytes 2.47 Gbits/sec 0 sender Sent 36.7 MByte / 87.1 MByte (42%) of ntopng-2.2.tar.gz [ 4] 0.00-0.12 sec 34.9 MBytes 2.36 Gbits/sec receiver iperf Done.
4、指定多线程网络传输测试(-P),同时可以使用-f M参数将结果通过MBytes/sec来显示
#使用单线程传输,传输10GB的数据一共消耗了27.36秒,平均速率为350 MBytes/sec [root@web2 ~]# iperf3 -c 192.168.1.250 -n 10000000000 -i 5 -f M Connecting to host 192.168.1.250, port 5201 [ 4] local 192.168.1.209 port 57348 connected to 192.168.1.250 port 5201 [ ID] Interval Transfer Bandwidth Retr Cwnd [ 4] 0.00-5.00 sec 1.58 GBytes 324 MBytes/sec 0 1.11 MBytes [ 4] 5.00-10.00 sec 1.62 GBytes 333 MBytes/sec 0 1.21 MBytes [ 4] 10.00-15.00 sec 1.65 GBytes 339 MBytes/sec 0 1.27 MBytes [ 4] 15.00-20.00 sec 1.76 GBytes 361 MBytes/sec 0 1.31 MBytes [ 4] 20.00-25.00 sec 1.82 GBytes 373 MBytes/sec 37 1.32 MBytes [ 4] 25.00-27.36 sec 886 MBytes 376 MBytes/sec 0 1.35 MBytes - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bandwidth Retr [ 4] 0.00-27.36 sec 9.31 GBytes 349 MBytes/sec 37 sender [ 4] 0.00-27.36 sec 9.31 GBytes 348 MBytes/sec receiver iperf Done.
[root@web2 ~]# iperf3 -c 192.168.1.250 -n 10000000000 -i 5 Connecting to host 192.168.1.250, port 5201 [ 4] local 192.168.1.209 port 57585 connected to 192.168.1.250 port 5201 [ ID] Interval Transfer Bandwidth Retr Cwnd [ 4] 0.00-5.00 sec 1.87 GBytes 3.21 Gbits/sec 0 990 KBytes [ 4] 5.00-10.00 sec 1.87 GBytes 3.22 Gbits/sec 0 1.04 MBytes [ 4] 10.00-15.00 sec 1.81 GBytes 3.12 Gbits/sec 0 1.12 MBytes [ 4] 15.00-20.00 sec 1.75 GBytes 3.01 Gbits/sec 0 1.20 MBytes [ 4] 20.00-25.00 sec 1.76 GBytes 3.03 Gbits/sec 14 1.37 MBytes [ 4] 25.00-25.81 sec 245 MBytes 2.53 Gbits/sec 0 1.38 MBytes - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bandwidth Retr [ 4] 0.00-25.81 sec 9.31 GBytes 3.10 Gbits/sec 14 sender [ 4] 0.00-25.81 sec 9.31 GBytes 3.10 Gbits/sec receiver iperf Done.
5、指定多线程传输
[root@web2 ~]# iperf3 -c 192.168.1.250 -n 10000000000 -i 5 -P 2 -f M Connecting to host 192.168.1.250, port 5201 [ 4] local 192.168.1.209 port 57751 connected to 192.168.1.250 port 5201 [ 6] local 192.168.1.209 port 57752 connected to 192.168.1.250 port 5201 [ ID] Interval Transfer Bandwidth Retr Cwnd [ 4] 0.00-5.00 sec 905 MBytes 181 MBytes/sec 0 585 KBytes [ 6] 0.00-5.00 sec 903 MBytes 181 MBytes/sec 0 602 KBytes [SUM] 0.00-5.00 sec 1.77 GBytes 362 MBytes/sec 0 - - - - - - - - - - - - - - - - - - - - - - - - - [ 4] 5.00-10.00 sec 917 MBytes 183 MBytes/sec 0 687 KBytes [ 6] 5.00-10.00 sec 917 MBytes 183 MBytes/sec 0 704 KBytes [SUM] 5.00-10.00 sec 1.79 GBytes 367 MBytes/sec 0 - - - - - - - - - - - - - - - - - - - - - - - - - [ 4] 10.00-15.00 sec 929 MBytes 186 MBytes/sec 0 723 KBytes [ 6] 10.00-15.00 sec 929 MBytes 186 MBytes/sec 0 735 KBytes [SUM] 10.00-15.00 sec 1.81 GBytes 372 MBytes/sec 0 - - - - - - - - - - - - - - - - - - - - - - - - - [ 4] 15.00-20.00 sec 921 MBytes 184 MBytes/sec 0 745 KBytes [ 6] 15.00-20.00 sec 920 MBytes 184 MBytes/sec 0 759 KBytes [SUM] 15.00-20.00 sec 1.80 GBytes 368 MBytes/sec 0 - - - - - - - - - - - - - - - - - - - - - - - - - [ 4] 20.00-25.00 sec 919 MBytes 184 MBytes/sec 0 782 KBytes [ 6] 20.00-25.00 sec 919 MBytes 184 MBytes/sec 0 802 KBytes [SUM] 20.00-25.00 sec 1.79 GBytes 368 MBytes/sec 0 - - - - - - - - - - - - - - - - - - - - - - - - - [ 4] 25.00-25.97 sec 179 MBytes 184 MBytes/sec 0 785 KBytes [ 6] 25.00-25.97 sec 180 MBytes 185 MBytes/sec 0 803 KBytes [SUM] 25.00-25.97 sec 359 MBytes 369 MBytes/sec 0 - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bandwidth Retr [ 4] 0.00-25.97 sec 4.66 GBytes 184 MBytes/sec 0 sender [ 4] 0.00-25.97 sec 4.65 GBytes 183 MBytes/sec receiver [ 6] 0.00-25.97 sec 4.66 GBytes 184 MBytes/sec 0 sender [ 6] 0.00-25.97 sec 4.65 GBytes 183 MBytes/sec receiver [SUM] 0.00-25.97 sec 9.31 GBytes 367 MBytes/sec 0 sender [SUM] 0.00-25.97 sec 9.30 GBytes 367 MBytes/sec receiver iperf Done.
6、测试UDP丢包和延迟,使用-u参数指定UDP协议,-b(K|M|G)参数指定UD式使用的带宽模式
[root@web2 ~]# iperf3 -c 192.168.1.250 -u -b 1G -f M -i 2 Connecting to host 192.168.1.250, port 5201 [ 4] local 192.168.1.209 port 45424 connected to 192.168.1.250 port 5201 [ ID] Interval Transfer Bandwidth Total Datagrams [ 4] 0.00-2.00 sec 81.1 MBytes 40.5 MBytes/sec 10377 [ 4] 2.00-4.00 sec 94.5 MBytes 47.3 MBytes/sec 12102 [ 4] 4.00-6.00 sec 94.6 MBytes 47.3 MBytes/sec 12107 [ 4] 6.00-8.00 sec 103 MBytes 51.5 MBytes/sec 13192 [ 4] 8.00-10.00 sec 93.6 MBytes 46.8 MBytes/sec 11983 - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams [ 4] 0.00-10.00 sec 467 MBytes 46.7 MBytes/sec 0.037 ms 435/59760 (0.73%) [ 4] Sent 59760 datagrams iperf Done.
由输出结果显示,Jitter表示抖动时间,或者称为传输延迟,Lost/Total表示丢失的数据包和总的数据包数量,Datagrams表示总共传输数据包的数量
#在服务端的输出 Accepted connection from 192.168.1.209, port 58179 [ 5] local 192.168.1.250 port 5201 connected to 192.168.1.209 port 45424 [ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams [ 5] 0.00-1.00 sec 35.6 MBytes 299 Mbits/sec 0.054 ms 29/4590 (0.63%) [ 5] 1.00-2.00 sec 43.0 MBytes 361 Mbits/sec 0.071 ms 30/5533 (0.54%) [ 5] 2.00-3.00 sec 48.4 MBytes 406 Mbits/sec 0.154 ms 29/6225 (0.47%) [ 5] 3.00-4.00 sec 45.6 MBytes 382 Mbits/sec 0.026 ms 6/5837 (0.1%) [ 5] 4.00-5.00 sec 47.3 MBytes 397 Mbits/sec 0.168 ms 124/6183 (2%) [ 5] 5.00-6.00 sec 46.1 MBytes 387 Mbits/sec 0.023 ms 40/5941 (0.67%) [ 5] 6.00-7.00 sec 49.0 MBytes 411 Mbits/sec 0.022 ms 48/6322 (0.76%) [ 5] 7.00-8.00 sec 53.1 MBytes 446 Mbits/sec 0.037 ms 67/6867 (0.98%) [ 5] 8.00-9.00 sec 44.9 MBytes 376 Mbits/sec 0.163 ms 26/5769 (0.45%) [ 5] 9.00-10.00 sec 48.4 MBytes 406 Mbits/sec 0.015 ms 36/6232 (0.58%) [ 5] 10.00-10.04 sec 2.04 MBytes 426 Mbits/sec 0.037 ms 0/261 (0%) - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams [ 5] 0.00-10.04 sec 0.00 Bytes 0.00 bits/sec 0.037 ms 435/59760 (0.73%) ----------------------------------------------------------- Server listening on 5201 -----------------------------------------------------------