0. Analysis of iperf principle
The iperf tool can be used to measure the network throughput of TCP or UDP, i.e. bandwidth test.
The main goal of the iPerf is to help adjust TCP connections on specific paths. As we all know, the most basic adjustment problem of TCP is to adjust the size of TCP window, which controls how much data can be in the network at any point. If it is too small, the sender will be idle for a period of time, thus affecting the performance of sending TCP. The theoretical value of TCP window size is the product of bottleneck bandwidth and round trip delay, that is:
bottleneck bandwidth * round trip time
For example, the bottleneck link is 45 Mbit/sec, and the round trip delay measured by using ping command is 42 Ms. So the theoretical value of the TCP window is
45 Mbit/sec * 42 ms = (45e6) * (42e-3) = 1890000 bits= 230 KByte
In the actual test, the calculated TCP window can be used as a benchmark. On the basis of this value (such as 230KByte above), increasing or decreasing the size of the TCP window can achieve a performance improvement.
Bandwidth testing generally uses UDP mode because it can measure the limit bandwidth, path delay and packet loss rate. These test items will be printed in the bandwidth test report. For example, the theoretical bandwidth of the link between the client and the server is 1000Mbps. First, it is tested with -b 1000M. Then, it is tested with the actual bandwidth (including actual bandwidth, delay jitter and packet loss rate) and then with the actual bandwidth as the data transmission rate. Delay jitter can be found. And the loss rate is much better than the first one. Repeated tests can lead to stable actual bandwidth.
Iperf works in server-client mode, so to use iperf to test bandwidth, it is necessary to establish a server (for discarding traffic) and a client (for generating traffic). Iperf servers or clients use the same command, but the options for starting the command are different.
1. iperf service startup mode
Look at how the server and client start up.
- Server
iperf -s
- Client
iperf -c
Note: The default test for iperf is the bandwidth of TCP protocol. If you need to test the bandwidth of UDP, you need to add the - u option.
2. Common options for iperf
The iperf options are divided into general options, server-specific options and client-specific options
- General Options
- f < kmKM > report output format. [kmKM] format to report: Kbits, Mbits, KBytes, MBytes - i < sec > pauses n seconds between periodic reporting bandwidth. If the period is 10 seconds, then - i is specified as 2, then bandwidth testing is reported every 2 seconds, and a total of 5 times are reported. - p Sets the port that the server listens on, default is 5001 - u uses UDP protocol testing - W n < K/M > Specify TCP window size - m Output MTU Size - M Sets MTU Size - O < filename > output to file
- Server-side options
- s iperf server mode - d Running Server in Background Mode - U runs a one-way UDP model
- Client option
- b, - - bandwidth n [KM] specifies the bandwidth (bit/s) of data sent by the client through UDP protocol. The default is 1Mbit/s - C < ServerIP > runs iperf in client mode and connects to server host ServerIP. Eg: iperf-c < server_ip > - d bidirectional testing - t specifies the iperf bandwidth test time, default is 10s. Eg: iperf-c < server_ip > - t 20 - P specifies the number of concurrent threads on the client side, and only one thread is run by default. eg, specify three threads: iperf-c < server_ip > - P 3 - T Specifies TTL Value
3. Examples
master serves
minion is the client
Note: iperf server must be run first
- 2 seconds return bandwidth test report
[root@master ~]# iperf -s -i 2
------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
[ 4] local 192.168.159.135 port 5001 connected with 192.168.159.136 port 57065
[ ID] Interval Transfer Bandwidth
[ 4] 0.0- 2.0 sec 907 MBytes 3.80 Gbits/sec
[ 4] 2.0- 4.0 sec 870 MBytes 3.65 Gbits/sec
[ 4] 4.0- 6.0 sec 864 MBytes 3.62 Gbits/sec
[ 4] 6.0- 8.0 sec 949 MBytes 3.98 Gbits/sec
[ 4] 8.0-10.0 sec 813 MBytes 3.41 Gbits/sec
[ 4] 0.0-10.0 sec 4.31 GBytes 3.69 Gbits/sec
[root@minion ~]# iperf -c 192.168.159.135 -i 2
------------------------------------------------------------
Client connecting to 192.168.159.135, TCP port 5001
TCP window size: 19.3 KByte (default)
------------------------------------------------------------
[ 3] local 192.168.159.136 port 57065 connected with 192.168.159.135 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0- 2.0 sec 912 MBytes 3.82 Gbits/sec
[ 3] 2.0- 4.0 sec 872 MBytes 3.66 Gbits/sec
[ 3] 4.0- 6.0 sec 863 MBytes 3.62 Gbits/sec
[ 3] 6.0- 8.0 sec 949 MBytes 3.98 Gbits/sec
[ 3] 8.0-10.0 sec 814 MBytes 3.41 Gbits/sec
[ 3] 0.0-10.0 sec 4.31 GBytes 3.70 Gbits/sec
The above two tests are simple, but it should be noted that the above tests are client-to-server upstream bandwidth tests. If downlink testing is required, we can use two-way testing directly, as follows:
- Bidirectional testing
[root@master ~]# iperf -s
------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
[ 4] local 192.168.159.135 port 5001 connected with 192.168.159.136 port 56617
------------------------------------------------------------
Client connecting to 192.168.159.136, TCP port 5001
TCP window size: 19.3 KByte (default)
------------------------------------------------------------
[ 5] local 192.168.159.135 port 48055 connected with 192.168.159.136 port 5001
[ ID] Interval Transfer Bandwidth
[ 4] 0.0- 2.0 sec 528 MBytes 2.20 Gbits/sec
[ 5] 0.0- 2.0 sec 425 MBytes 1.78 Gbits/sec
[root@minion ~]# iperf -c 192.168.159.135 -t 2 -d
------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
------------------------------------------------------------
Client connecting to 192.168.159.135, TCP port 5001
TCP window size: 174 KByte (default)
------------------------------------------------------------
[ 5] local 192.168.159.136 port 56617 connected with 192.168.159.135 port 5001
[ 4] local 192.168.159.136 port 5001 connected with 192.168.159.135 port 48055
[ ID] Interval Transfer Bandwidth
[ 5] 0.0- 2.0 sec 528 MBytes 2.21 Gbits/sec
[ 4] 0.0- 2.0 sec 425 MBytes 1.77 Gbits/sec
Note the following two lines:
[ 5] local 192.168.159.136 port 56617 connected with 192.168.159.135 port 5001
[ 4] local 192.168.159.136 port 5001 connected with 192.168.159.135 port 48055
[5] The sign begins with the upstream test, because the server port is 5001. Correspondingly, [4] marks the beginning of the downlink test. Later bandwidth test prints are marked with [5], [4] to distinguish between upstream and downstream.
-
UDP testing
In this test, the theoretical bandwidth is 10,000 Mbits/s (intranet, 10,000 Mbps switch, 10,000 Mbps network card). So I first test the theoretical bandwidth of 10 000 Mbits/sec, and then test it repeatedly according to the test report, and get the limit bandwidth of 815 Mbits/sec.
The test report is as follows:
[root@master ~]# iperf -s -u
------------------------------------------------------------
Server listening on UDP port 5001
Receiving 1470 byte datagrams
UDP buffer size: 122 KByte (default)
------------------------------------------------------------
[ 3] local 10.65.14.43 port 5001 connected with 10.65.14.42 port 5586
[ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams
[ 3] 0.0-60.0 sec 4.11 GBytes 588 Mbits/sec 0.000 ms 1158071/4158943 (28%)
[ 3] 0.0-60.0 sec 1 datagrams received out-of-order
[ 4] local 10.65.14.43 port 5001 connected with 10.65.14.42 port 39851
[ 4] 0.0-60.0 sec 5.33 GBytes 763 Mbits/sec 0.014 ms 264719/4158695 (6.4%)
[ 4] 0.0-60.0 sec 1 datagrams received out-of-order
[ 3] local 10.65.14.43 port 5001 connected with 10.65.14.42 port 56885
[ 3] 0.0-60.0 sec 5.48 GBytes 784 Mbits/sec 0.017 ms 49/3999977 (0.0012%)
[ 3] 0.0-60.0 sec 1 datagrams received out-of-order
[ 4] local 10.65.14.43 port 5001 connected with 10.65.14.42 port 30343
[ 4] 0.0-60.0 sec 5.69 GBytes 815 Mbits/sec 0.013 ms 727/4157413 (0.017%)
[ 4] 0.0-60.0 sec 1 datagrams received out-of-order
[ 3] local 10.65.14.43 port 5001 connected with 10.65.14.42 port 17417
[ 3] 0.0-60.0 sec 5.69 GBytes 815 Mbits/sec 0.013 ms 2061/4158792 (0.05%)
[ 3] 0.0-60.0 sec 1 datagrams received out-of-order
[root@minion ~]# iperf -c 10.65.14.43 -u -m -t 60 -i 10 -b 10000M
------------------------------------------------------------
Client connecting to 10.65.14.43, UDP port 5001
Sending 1470 byte datagrams
UDP buffer size: 122 KByte (default)
------------------------------------------------------------
[ 3] local 10.65.14.42 port 5586 connected with 10.65.14.43 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-10.0 sec 972 MBytes 815 Mbits/sec
[ 3] 10.0-20.0 sec 972 MBytes 815 Mbits/sec
[ 3] 20.0-30.0 sec 972 MBytes 815 Mbits/sec
[ 3] 30.0-40.0 sec 972 MBytes 815 Mbits/sec
[ 3] 40.0-50.0 sec 972 MBytes 815 Mbits/sec
[ 3] 0.0-60.0 sec 5.69 GBytes 815 Mbits/sec
[ 3] Sent 4158944 datagrams
[ 3] Server Report:
[ 3] 0.0-60.0 sec 4.11 GBytes 588 Mbits/sec 0.000 ms 1158071/4158943 (28%)
[ 3] 0.0-60.0 sec 1 datagrams received out-of-order
[root@minion ~]# iperf -c 10.65.14.43 -u -m -t 60 -i 10 -b 1000M
------------------------------------------------------------
Client connecting to 10.65.14.43, UDP port 5001
Sending 1470 byte datagrams
UDP buffer size: 122 KByte (default)
------------------------------------------------------------
[ 3] local 10.65.14.42 port 39851 connected with 10.65.14.43 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-10.0 sec 972 MBytes 815 Mbits/sec
[ 3] 10.0-20.0 sec 972 MBytes 815 Mbits/sec
[ 3] 20.0-30.0 sec 972 MBytes 815 Mbits/sec
[ 3] 30.0-40.0 sec 972 MBytes 815 Mbits/sec
[ 3] 40.0-50.0 sec 972 MBytes 815 Mbits/sec
[ 3] 0.0-60.0 sec 5.69 GBytes 815 Mbits/sec
[ 3] Sent 4158696 datagrams
[ 3] Server Report:
[ 3] 0.0-60.0 sec 5.33 GBytes 763 Mbits/sec 0.013 ms 264719/4158695 (6.4%)
[ 3] 0.0-60.0 sec 1 datagrams received out-of-order
[root@minion ~]# iperf -c 10.65.14.43 -u -m -t 60 -i 10 -b 763M
------------------------------------------------------------
Client connecting to 10.65.14.43, UDP port 5001
Sending 1470 byte datagrams
UDP buffer size: 122 KByte (default)
------------------------------------------------------------
[ 3] local 10.65.14.42 port 56885 connected with 10.65.14.43 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-10.0 sec 935 MBytes 784 Mbits/sec
[ 3] 10.0-20.0 sec 935 MBytes 784 Mbits/sec
[ 3] 20.0-30.0 sec 935 MBytes 784 Mbits/sec
[ 3] 30.0-40.0 sec 935 MBytes 784 Mbits/sec
[ 3] 40.0-50.0 sec 935 MBytes 784 Mbits/sec
[ 3] 50.0-60.0 sec 935 MBytes 784 Mbits/sec
[ 3] 0.0-60.0 sec 5.48 GBytes 784 Mbits/sec
[ 3] Sent 3999978 datagrams
[ 3] Server Report:
[ 3] 0.0-60.0 sec 5.48 GBytes 784 Mbits/sec 0.017 ms 49/3999977 (0.0012%)
[ 3] 0.0-60.0 sec 1 datagrams received out-of-order
[root@minion ~]# iperf -c 10.65.14.43 -u -m -t 60 -i 10 -b 784M
------------------------------------------------------------
Client connecting to 10.65.14.43, UDP port 5001
Sending 1470 byte datagrams
UDP buffer size: 122 KByte (default)
------------------------------------------------------------
[ 3] local 10.65.14.42 port 30343 connected with 10.65.14.43 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-10.0 sec 972 MBytes 815 Mbits/sec
[ 3] 10.0-20.0 sec 971 MBytes 815 Mbits/sec
[ 3] 20.0-30.0 sec 971 MBytes 815 Mbits/sec
[ 3] 30.0-40.0 sec 971 MBytes 815 Mbits/sec
[ 3] 40.0-50.0 sec 971 MBytes 815 Mbits/sec
[ 3] 50.0-60.0 sec 971 MBytes 815 Mbits/sec
[ 3] 0.0-60.0 sec 5.69 GBytes 815 Mbits/sec
[ 3] Sent 4157414 datagrams
[ 3] Server Report:
[ 3] 0.0-60.0 sec 5.69 GBytes 815 Mbits/sec 0.013 ms 727/4157413 (0.017%)
[ 3] 0.0-60.0 sec 1 datagrams received out-of-order
[root@minion ~]# iperf -c 10.65.14.43 -u -m -t 60 -i 10 -b 815M
------------------------------------------------------------
Client connecting to 10.65.14.43, UDP port 5001
Sending 1470 byte datagrams
UDP buffer size: 122 KByte (default)
------------------------------------------------------------
[ 3] local 10.65.14.42 port 17417 connected with 10.65.14.43 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-10.0 sec 972 MBytes 815 Mbits/sec
[ 3] 10.0-20.0 sec 972 MBytes 815 Mbits/sec
[ 3] 20.0-30.0 sec 972 MBytes 815 Mbits/sec
[ 3] 30.0-40.0 sec 972 MBytes 815 Mbits/sec
[ 3] 40.0-50.0 sec 972 MBytes 815 Mbits/sec
[ 3] 50.0-60.0 sec 972 MBytes 815 Mbits/sec
[ 3] 0.0-60.0 sec 5.69 GBytes 815 Mbits/sec
[ 3] Sent 4158793 datagrams
[ 3] Server Report:
[ 3] 0.0-60.0 sec 5.69 GBytes 815 Mbits/sec 0.013 ms 2061/4158792 (0.05%)
[ 3] 0.0-60.0 sec 1 datagrams received out-of-order