Iperf 是一个 TCP/IP 和 UDP/IP 的性能测量工具,通过调谐各种参数可以测试TCP的最大带宽,并报告带宽、延迟,最大段和最大传输单元大小等统计信息。Iperf可以运行于Linux/BSD、Unix及Windows等操作系统。
root@ubuntu:/home/totosun/Desktop/iperf-3.2-STABLE/iperf-3.2-STABLE/src# ./iperf3 -h
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
-F, --file name xmit/recv the specified file
-A, --affinity n/n,m set CPU affinity
-B, --bind <host> bind to a specific interface
-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
-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
--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
Client specific:
-c, --client <host> run in client mode, connecting to <host>
-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)
--fq-rate #[KMG] enable fair-queuing based socket pacing in
bits/sec (Linux only)
-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, dynamic or 1 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)
-w, --window #[KMG] set window size / socket buffer size
-C, --congestion <algo> 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, 0-255
--dscp N or --dscp val set the IP dscp value, either 0-63 or symbolic
-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
--username username for authentication
--rsa-public-key-path path to the RSA public key used to encrypt
authentication credentials
window:
iperf3.exe -s
iperf3 -c 192.168.208.200 -t 60 -P 6
#指定窗口大小
iperf3 -c 192.168.208.200 -t 60 -P 6 -w 8K
iperf3相关命令实现原理函数
setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt))
setsockopt(s, IPPROTO_TCP, TCP_MAXSEG, &opt, sizeof(opt))
setsockopt(s, SOL_SOCKET, SO_RCVBUF, &opt, sizeof(opt))
setsockopt(s, SOL_SOCKET, SO_SNDBUF, &opt, sizeof(opt))
setsockopt(s, SOL_SOCKET, SO_MAX_PACING_RATE, &fqrate, sizeof(fqrate))
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt))
setsockopt(s, IPPROTO_IP, IP_TOS, &opt, sizeof(opt)
setsockopt(s, IPPROTO_TCP, TCP_CONGESTION, test->congestion, strlen(test->congestion))
客户端与服务器互换,要分清server和客户端读写方向,两者差异比较大。
Server listening on 5201
-----------------------------------------------------------
Accepted connection from 192.168.208.200, port 22238
[ 5] local 192.168.208.209 port 5201 connected to 192.168.208.200 port 22239
[ ID] Interval Transfer Bandwidth
[ 5] 0.00-1.00 sec 106 MBytes 892 Mbits/sec
[ 5] 1.00-2.00 sec 105 MBytes 880 Mbits/sec
[ 5] 2.00-3.00 sec 114 MBytes 954 Mbits/sec
[ 5] 3.00-4.00 sec 114 MBytes 956 Mbits/sec
[ 5] 4.00-5.00 sec 106 MBytes 895 Mbits/sec
[ 5] 5.00-6.00 sec 113 MBytes 950 Mbits/sec
[ 5] 6.00-7.00 sec 105 MBytes 882 Mbits/sec
[ 5] 7.00-8.00 sec 98.1 MBytes 822 Mbits/sec
[ 5] 8.00-9.00 sec 111 MBytes 930 Mbits/sec
[ 5] 9.00-10.00 sec 109 MBytes 918 Mbits/sec
[ 5] 10.00-10.04 sec 3.93 MBytes 958 Mbits/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 1.06 GBytes 908 Mbits/sec receiver
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------