主要功能
TCP
- 测量网络带宽
- 报告MSS/MTU值的大小和观测值
- 支持TCP窗口值通过套接字缓冲
- 当P线程或Win32线程可用时,支持多线程。客户端与服务端支持同时多重连接
UDP
- 客户端可以创建指定带宽的UDP流
- 测量丢包
- 测量延迟
- 支持多播
使用方法
安装
官网下载,地址:iPerf - The TCP, UDP and SCTP network bandwidth measurement tool
cmd进入iperf所在目录后执行
指令及其含义
-help返回内容:
Usage: iperf3 [-s|-c host] [options]
iperf3 [-h|--help] [-v|--version]
Server or Client:
-p, --port # server port to listen on/connect to
-f, --format [kmgtKMGT] format to report: Kbits, Mbits, Gbits, Tbits
-i, --interval # seconds between periodic throughput reports
-I, --pidfile file write PID file
-F, --file name xmit/recv the specified file
-A, --affinity n/n,m set CPU affinity
-B, --bind <host> bind to the interface associated with the address <host>
-V, --verbose more detailed output
-J, --json output in JSON format
--logfile f send output to a log file
--forceflush force flushing output at every interval
--timestamps<=format> emit a timestamp at the start of each output line
(optional "=" and format string as per strftime(3))
--rcv-timeout # idle timeout for receiving data (default 120000 ms)
-d, --debug[=#] emit debugging output
(optional optional "=" and debug level: 1-4. Default is 4 - all messages)
-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
-1, --one-off handle one client connection then exit
--server-bitrate-limit #[KMG][/#] server's total bit rate limit (default 0 = no limit)
(optional slash and number of secs interval for averaging
total data rate. Default is 5 seconds)
--idle-timeout # restart idle server after # seconds in case it
got stuck (default - no timeout)
--rsa-private-key-path path to the RSA private key used to decrypt
authentication credentials
--authorized-users-path path to the configuration file containing user
credentials
--time-skew-threshold time skew threshold (in seconds) between the server
and client during the authentication process
Client specific:
-c, --client <host>[%<dev>] run in client mode, connecting to <host>
(option <dev> equivalent to `--bind-dev <dev>`)
-u, --udp use UDP rather than TCP
--connect-timeout # timeout for control connection setup (ms)
-b, --bitrate #[KMG][/#] target bitrate in bits/sec (0 for unlimited)
(default 1 Mbit/sec for UDP, unlimited for TCP)
(optional slash and packet count for burst mode)
--pacing-timer #[KMG] set the timing for pacing, in microseconds (default 1000)
-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, --length #[KMG] length of buffer to read or write
(default 128 KB for TCP, dynamic or 1460 for UDP)
--cport <port> 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)
--bidir run in bidirectional mode.
Client and server send and receive data.
-w, --window #[KMG] set send/receive socket buffer sizes
(indirectly sets TCP window size)
-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, 0-255.
The usual prefixes for octal and hex can be used,
i.e. 52, 064 and 0x34 all specify the same value.
--dscp N or --dscp val set the IP dscp value, either 0-63 or symbolic.
Numeric values can be specified in decimal,
octal and hex (see --tos above).
-Z, --zerocopy use a 'zero copy' method of sending data
-O, --omit N perform pre-test for N seconds and omit the pre-test statistics
-T, --title str prefix every output line with this string
--extra-data str data string to include in client and server JSON
--get-server-output get results from server
--udp-counters-64bit use 64-bit counters in UDP test packets
--repeating-payload use repeating pattern in payload, instead of
randomized payload (like in iperf2)
--dont-fragment set IPv4 Don't Fragment flag
--username username for authentication
--rsa-public-key-path path to the RSA public key used to encrypt
authentication credentials
[KMG] indicates options that support a K/M/G suffix for kilo-, mega-, or giga-
iperf3 homepage at: https://software.es.net/iperf/
Report bugs to: https://github.com/esnet/iperf
汇总后
命令行选项 | 描述 |
客户端与服务器共用选项 | |
-f, --format [bkmaBKMA] | 格式化带宽数输出。支持的格式有: |
-i, --interval # | 设置每次报告之间的时间间隔,单位为秒。如果设置为非零值,就会按照此时间间隔输出测试报告。默认值为零。 |
-l, --len #[KM] | 设置读写缓冲区的长度。TCP方式默认为8KB,UDP方式默认为1470字节。 |
-m, --print_mss | 输出TCP MSS值(通过TCP_MAXSEG支持)。MSS值一般比MTU值小40字节。通常情况 |
-p, --port # | 设置端口,与服务器端的监听端口一致。默认是5001端口,与ttcp的一样。 |
-u, --udp | 使用UDP方式而不是TCP方式。参看-b选项。 |
-w, --window #[KM] | 设置套接字缓冲区为指定大小。对于TCP方式,此设置为TCP窗口大小。对于UDP方式,此设置为接受UDP数据包的缓冲区大小,限制可以接受数据包的最大值。 |
-B, --bind host | 绑定到主机的多个地址中的一个。对于客户端来 说,这个参数设置了出栈接口。对于服务器端来说,这个参数设置入栈接口。这个参数只用于具有多网络接口的主机。在Iperf的UDP模式下,此参数用于绑 定和加入一个多播组。使用范围在224.0.0.0至239.255.255.255的多播地址。参考-T参数。 |
-C, --compatibility | 与低版本的Iperf使用时,可以使用兼容模式。不需要两端同时使用兼容模式,但是强烈推荐两端同时使用兼容模式。某些情况下,使用某些数据流可以引起1.7版本的服务器端崩溃或引起非预期的连接尝试。 |
-M, --mss #[KM} | 通过TCP_MAXSEG选项尝试设置TCP最大信息段的值。MSS值的大小通常是TCP/IP头减去40字节。在以太网中,MSS值 为1460字节(MTU1500字节)。许多操作系统不支持此选项。 |
-N, --nodelay | 设置TCP无延迟选项,禁用Nagle's运算法则。通常情况此选项对于交互程序,例如telnet,是禁用的。 |
-V (from v1.6 or higher) | 绑定一个IPv6地址。 |
服务器端专用选项 | |
-s, --server | Iperf服务器模式 |
-D (v1.2或更高版本) | Unix平台下Iperf作为后台守护进程运行。在Win32平台下,Iperf将作为服务运行。 |
-R(v1.2或更高版本,仅用于Windows) | 卸载Iperf服务(如果它在运行)。 |
-o(v1.2或更高版本,仅用于Windows) | 重定向输出到指定文件 |
-c, --client host | 如果Iperf运行在服务器模式,并且用-c参数指定一个主机,那么Iperf将只接受指定主机的连接。此参数不能工作于UDP模式。 |
-P, --parallel # | 服务器关闭之前保持的连接数。默认是0,这意味着永远接受连接。 |
客户端专用选项 | |
-b, --bandwidth #[KM] | UDP模式使用的带宽,单位bits/sec。此选项与-u选项相关。默认值是1 Mbit/sec。 |
-c, --client host | 运行Iperf的客户端模式,连接到指定的Iperf服务器端。 |
-d, --dualtest | 运行双测试模式。这将使服务器端反向连接到客户端,使用-L 参数中指定的端口(或默认使用客户端连接到服务器端的端口)。这些在操作的同时就立即完成了。如果你想要一个交互的测试,请尝试-r参数。 |
-n, --num #[KM] | 传送的缓冲器数量。通常情况,Iperf按照10秒钟发送数据。-n参数跨越此限制,按照指定次数发送指定长度的数据,而不论该操作耗费多少时间。参考-l与-t选项。 |
-r, --tradeoff | 往复测试模式。当客户端到服务器端的测试结束时,服务器端通过-l选项指定的端口(或默认为客户端连接到服务器端的端口),反向连接至客户端。当客户端连接终止时,反向连接随即开始。如果需要同时进行双向测试,请尝试-d参数。 |
-t, --time # | 设置传输的总时间。Iperf在指定的时间内,重复的发送指定长度的数据包。默认是10秒钟。参考-l与-n选项。 |
-L, --listenport # | 指定服务端反向连接到客户端时使用的端口。默认使用客户端连接至服务端的端口。 |
-P, --parallel # | 线程数。指定客户端与服务端之间使用的线程数。默认是1线程。需要客户端与服务器端同时使用此参数。 |
-S, --tos # | 出栈数据包的服务类型。许多路由器忽略TOS字段。你可以指定这个值,使用以"0x"开始的16进制数,或以"0"开始的8进制数或10进制数。 |
-T, --ttl # | 出栈多播数据包的TTL值。这本质上就是数据通过路由器的跳数。默认是1,链接本地。 |
-F (from v1.2 or higher) | 使用特定的数据流测量带宽,例如指定的文件。 |
-I (from v1.2 or higher) | 与-F一样,由标准输入输出文件输入数据。 |
杂项 | |
-h, --help | 显示命令行参考并退出 。 |
-v, --version | 显示版本信息和编译信息并退出。 |
示例
测试单线程TCP
在服务端运行iperf,输入命令iperf –s –p 12345 –i 1 –M 以在本机端口12345上启用iperf
在客户端运行iperf,输入命令iperf –c server-ip –p server-port –i 1 –t 10 –w 20K
客户端:
服务端
测试多线程TCP
在客户端添加-P N即可测试多线程的TCP性能,如下为使用两个线程的测试情况
客户端
服务端
测试单线程UDP
在服务端运行iperf,输入命令iperf –s -u –p 12345 –i 1 以在本机端口12345上启用iperf
在客户端运行iperf,输入命令iperf -c server-ip -p server-port -i 1 -t 10 -u -b
测试多线程UDP
在客户端添加-P N,同TCP