iperf部分参数学习

用过很多次iperf,但是对其中某些参数选项还不甚了解,今天特意下了代码看看某些项的含义。

Usage: iperf [-s|-c host] [options]
       iperf [-h|--help] [-v|--version]

Server or Client:
  -J, --json                output in JSON format
Client specific:
  -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)
                            
  -l, --len       #[KMG]    length of buffer to read or write
                            (default 128 KB for TCP, 8 KB for UDP)
  -P, --parallel  #         number of parallel client streams to run
  -w, --window    #[KMG]    set window size / socket buffer size
  -C, --linux-congestion <algo>  set TCP congestion control algorithm (Linux only)
  -M, --set-mss   #         set TCP maximum segment size (MTU - 40 bytes)
  -S, --tos N               set the IP 'type of service'
  -Z, --zerocopy            use a 'zero copy' method of sending data(系统有关,可能不支持,linux一般支持)
  -O, --omit N              omit the first n seconds
  --get-server-output       get results from server

1. -P -parallel

并行发包的流,一般而言,如果吞吐不大,一条流足以,多条流不一定能提高吞吐.先测试了1-3-6条例,没有明显的看到收益。当前这个也跟服务器有关,如果服务器限制每条流的速率(如何限速,比较复杂,暂时不研究),那么多条流明显有优势

aaa@ubuntu:~/share/iperf-master/src$ ./iperf3 -c 192.168.0.103 -u -t 5 
Connecting to host 192.168.0.103, port 5201
SNDBUF is 212992, expecting 0
[  5] local 192.168.0.202 port 45475 connected to 192.168.0.103 port 5201
[ ID] Interval           Transfer     Bitrate         Total Datagrams
[  5]   0.00-1.00   sec   129 KBytes  1.05 Mbits/sec  91  
[  5]   1.00-2.00   sec   129 KBytes  1.06 Mbits/sec  91  
[  5]   2.00-3.00   sec   127 KBytes  1.04 Mbits/sec  90  
[  5]   3.00-4.00   sec   129 KBytes  1.05 Mbits/sec  91  
[  5]   4.00-5.00   sec   127 KBytes  1.04 Mbits/sec  90  
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Jitter    Lost/Total Datagrams
[  5]   0.00-5.00   sec   641 KBytes  1.05 Mbits/sec  0.000 ms  0/453 (0%)  sender
[  5]   0.00-5.00   sec   641 KBytes  1.05 Mbits/sec  0.908 ms  0/453 (0%)  receiver

iperf Done.
aaa@ubuntu:~/share/iperf-master/src$ ./iperf3 -c 192.168.0.103  -t 5   
Connecting to host 192.168.0.103, port 5201
[  5] local 192.168.0.202 port 42122 connected to 192.168.0.103 port 5201
[ ID] Interval           Transfer     Bitrate         Retr  Cwnd
[  5]   0.00-1.00   sec  8.43 MBytes  70.7 Mbits/sec    0    428 KBytes       
[  5]   1.00-2.00   sec  7.22 MBytes  60.6 Mbits/sec    0    754 KBytes       
[  5]   2.00-3.00   sec  7.50 MBytes  62.9 Mbits/sec    0   1.00 MBytes       
[  5]   3.00-4.00   sec  7.50 MBytes  62.9 Mbits/sec    0   1.00 MBytes       
[  5]   4.00-5.00   sec  7.50 MBytes  62.9 Mbits/sec    0   1.00 MBytes       
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Retr
[  5]   0.00-5.00   sec  38.2 MBytes  64.0 Mbits/sec    0             sender
[  5]   0.00-5.00   sec  36.2 MBytes  60.8 Mbits/sec                  receiver

iperf Done.
aaa@ubuntu:~/share/iperf-master/src$ ./iperf3 -c 192.168.0.103  -t 5 -P 3
Connecting to host 192.168.0.103, port 5201
[  5] local 192.168.0.202 port 42126 connected to 192.168.0.103 port 5201
[  7] local 192.168.0.202 port 42128 connected to 192.168.0.103 port 5201
[  9] local 192.168.0.202 port 42130 connected to 192.168.0.103 port 5201
[ ID] Interval           Transfer     Bitrate         Retr  Cwnd
[  5]   0.00-1.00   sec  2.90 MBytes  24.3 Mbits/sec    0    188 KBytes       
[  7]   0.00-1.00   sec  2.71 MBytes  22.7 Mbits/sec    0    191 KBytes       
[  9]   0.00-1.00   sec  3.16 MBytes  26.4 Mbits/sec    0    208 KBytes       
[SUM]   0.00-1.00   sec  8.77 MBytes  73.4 Mbits/sec    0             
- - - - - - - - - - - - - - - - - - - - - - - - -
[  5]   1.00-2.00   sec  3.42 MBytes  28.7 Mbits/sec    0    324 KBytes       
[  7]   1.00-2.00   sec  3.67 MBytes  30.8 Mbits/sec    0    325 KBytes       
[  9]   1.00-2.00   sec  3.73 MBytes  31.3 Mbits/sec    0    352 KBytes       
[SUM]   1.00-2.00   sec  10.8 MBytes  90.7 Mbits/sec    0             
- - - - - - - - - - - - - - - - - - - - - - - - -
[  5]   2.00-3.00   sec  3.48 MBytes  29.2 Mbits/sec    0    472 KBytes       
[  7]   2.00-3.00   sec  3.36 MBytes  28.2 Mbits/sec    0    458 KBytes       
[  9]   2.00-3.00   sec  3.60 MBytes  30.2 Mbits/sec    0    506 KBytes       
[SUM]   2.00-3.00   sec  10.4 MBytes  87.7 Mbits/sec    0             
- - - - - - - - - - - - - - - - - - - - - - - - -
[  5]   3.00-4.00   sec  4.61 MBytes  38.6 Mbits/sec    0    645 KBytes       
[  7]   3.00-4.00   sec  4.78 MBytes  40.1 Mbits/sec    0    634 KBytes       
[  9]   3.00-4.00   sec  2.17 MBytes  18.3 Mbits/sec   26    417 KBytes       
[SUM]   3.00-4.00   sec  11.6 MBytes  96.9 Mbits/sec   26             
- - - - - - - - - - - - - - - - - - - - - - - - -
[  5]   4.00-5.00   sec  2.50 MBytes  20.9 Mbits/sec  180    270 KBytes       
[  7]   4.00-5.00   sec  3.75 MBytes  31.4 Mbits/sec   57    537 KBytes       
[  9]   4.00-5.00   sec  2.49 MBytes  20.8 Mbits/sec    0    482 KBytes       
[SUM]   4.00-5.00   sec  8.74 MBytes  73.2 Mbits/sec  237             
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Retr
[  5]   0.00-5.00   sec  16.9 MBytes  28.3 Mbits/sec  180             sender
[  5]   0.00-5.00   sec  14.1 MBytes  23.6 Mbits/sec                  receiver
[  7]   0.00-5.00   sec  18.3 MBytes  30.6 Mbits/sec   57             sender
[  7]   0.00-5.00   sec  15.1 MBytes  25.3 Mbits/sec                  receiver
[  9]   0.00-5.00   sec  15.1 MBytes  25.4 Mbits/sec   26             sender
[  9]   0.00-5.00   sec  13.4 MBytes  22.5 Mbits/sec                  receiver
[SUM]   0.00-5.00   sec  50.3 MBytes  84.4 Mbits/sec  263             sender
[SUM]   0.00-5.00   sec  42.6 MBytes  71.4 Mbits/sec                  receiver

iperf Done.
aaa@ubuntu:~/share/iperf-master/src$ ./iperf3 -c 192.168.0.103  -t 5 -P 6
Connecting to host 192.168.0.103, port 5201
[  5] local 192.168.0.202 port 42134 connected to 192.168.0.103 port 5201
[  7] local 192.168.0.202 port 42136 connected to 192.168.0.103 port 5201
[  9] local 192.168.0.202 port 42138 connected to 192.168.0.103 port 5201
[ 11] local 192.168.0.202 port 42140 connected to 192.168.0.103 port 5201
[ 13] local 192.168.0.202 port 42142 connected to 192.168.0.103 port 5201
[ 15] local 192.168.0.202 port 42144 connected to 192.168.0.103 port 5201
[ ID] Interval           Transfer     Bitrate         Retr  Cwnd
[  5]   0.00-1.00   sec  1.48 MBytes  12.4 Mbits/sec    0    126 KBytes       
[  7]   0.00-1.00   sec  1004 KBytes  8.22 Mbits/sec    0   80.6 KBytes       
[  9]   0.00-1.00   sec  1.54 MBytes  12.9 Mbits/sec    0    117 KBytes       
[ 11]   0.00-1.00   sec  1004 KBytes  8.22 Mbits/sec    0   79.2 KBytes       
[ 13]   0.00-1.00   sec  1.04 MBytes  8.74 Mbits/sec    0   86.3 KBytes       
[ 15]   0.00-1.00   sec  1.10 MBytes  9.20 Mbits/sec    0   86.3 KBytes       
[SUM]   0.00-1.00   sec  7.12 MBytes  59.6 Mbits/sec    0             
- - - - - - - - - - - - - - - - - - - - - - - - -
[  5]   1.00-2.00   sec  1.55 MBytes  13.0 Mbits/sec    0    178 KBytes       
[  7]   1.00-2.00   sec  1.12 MBytes  9.35 Mbits/sec    0    124 KBytes       
[  9]   1.00-2.00   sec  1.24 MBytes  10.4 Mbits/sec    0    178 KBytes       
[ 11]   1.00-2.00   sec   891 KBytes  7.27 Mbits/sec    0    116 KBytes       
[ 13]   1.00-2.00   sec  1.24 MBytes  10.4 Mbits/sec    0    134 KBytes       
[ 15]   1.00-2.00   sec  1018 KBytes  8.31 Mbits/sec    0    132 KBytes       
[SUM]   1.00-2.00   sec  7.02 MBytes  58.7 Mbits/sec    0             
- - - - - - - - - - - - - - - - - - - - - - - - -
[  5]   2.00-3.00   sec  1.49 MBytes  12.6 Mbits/sec    0    240 KBytes       
[  7]   2.00-3.00   sec  1018 KBytes  8.37 Mbits/sec    0    171 KBytes       
[  9]   2.00-3.00   sec  1.30 MBytes  11.0 Mbits/sec    0    233 KBytes       
[ 11]   2.00-3.00   sec  1.30 MBytes  11.0 Mbits/sec    0    160 KBytes       
[ 13]   2.00-3.00   sec  1.18 MBytes  9.94 Mbits/sec    0    181 KBytes       
[ 15]   2.00-3.00   sec  1018 KBytes  8.37 Mbits/sec    0    177 KBytes       
[SUM]   2.00-3.00   sec  7.27 MBytes  61.2 Mbits/sec    0             
- - - - - - - - - - - - - - - - - - - - - - - - -
[  5]   3.00-4.00   sec  1.18 MBytes  9.92 Mbits/sec    0    297 KBytes       
[  7]   3.00-4.00   sec   954 KBytes  7.83 Mbits/sec    0    215 KBytes       
[  9]   3.00-4.00   sec  1.55 MBytes  13.0 Mbits/sec    0    279 KBytes       
[ 11]   3.00-4.00   sec   891 KBytes  7.31 Mbits/sec    0    204 KBytes       
[ 13]   3.00-4.00   sec  1018 KBytes  8.35 Mbits/sec    0    215 KBytes       
[ 15]   3.00-4.00   sec  1.43 MBytes  12.0 Mbits/sec    0    238 KBytes       
[SUM]   3.00-4.00   sec  6.96 MBytes  58.5 Mbits/sec    0             
- - - - - - - - - - - - - - - - - - - - - - - - -
[  5]   4.00-5.00   sec  1.43 MBytes  12.0 Mbits/sec    0    369 KBytes       
[  7]   4.00-5.00   sec  1.55 MBytes  13.0 Mbits/sec    0    270 KBytes       
[  9]   4.00-5.00   sec  1.99 MBytes  16.6 Mbits/sec    0    351 KBytes       
[ 11]   4.00-5.00   sec  1.49 MBytes  12.5 Mbits/sec    0    257 KBytes       
[ 13]   4.00-5.00   sec  1.18 MBytes  9.88 Mbits/sec    0    259 KBytes       
[ 15]   4.00-5.00   sec  1.99 MBytes  16.6 Mbits/sec    0    300 KBytes       
[SUM]   4.00-5.00   sec  9.63 MBytes  80.6 Mbits/sec    0             
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Retr
[  5]   0.00-5.00   sec  7.13 MBytes  12.0 Mbits/sec    0             sender
[  5]   0.00-5.00   sec  6.21 MBytes  10.4 Mbits/sec                  receiver
[  7]   0.00-5.00   sec  5.58 MBytes  9.35 Mbits/sec    0             sender
[  7]   0.00-5.00   sec  4.57 MBytes  7.66 Mbits/sec                  receiver
[  9]   0.00-5.00   sec  7.63 MBytes  12.8 Mbits/sec    0             sender
[  9]   0.00-5.00   sec  6.17 MBytes  10.3 Mbits/sec                  receiver
[ 11]   0.00-5.00   sec  5.52 MBytes  9.25 Mbits/sec    0             sender
[ 11]   0.00-5.00   sec  4.42 MBytes  7.41 Mbits/sec                  receiver
[ 13]   0.00-5.00   sec  5.64 MBytes  9.46 Mbits/sec    0             sender
[ 13]   0.00-5.00   sec  4.45 MBytes  7.46 Mbits/sec                  receiver
[ 15]   0.00-5.00   sec  6.50 MBytes  10.9 Mbits/sec    0             sender
[ 15]   0.00-5.00   sec  5.13 MBytes  8.60 Mbits/sec                  receiver
[SUM]   0.00-5.00   sec  38.0 MBytes  63.7 Mbits/sec    0             sender
[SUM]   0.00-5.00   sec  30.9 MBytes  51.9 Mbits/sec                  receiver

iperf Done.

2. -w, --window

  • set window size / socket buffer size

通过setsockopt设置发送/接收缓冲区大小,这个值一般不需要修改,使用系统的默认缓冲区大小。如果要配置,实际生效会是设置值得2倍。原因如下

man 7 socket

Sets or gets the maximum socket recv/send buffer in bytes. The kernel doubles this value (to allow space for bookkeeping overhead) when it is set using setsockopt

做个测试,发现系统的默认发送缓冲区是208KB(212992), 从测试来看,一般情况下,系统默认的缓冲区绰绰有余了。当然,这个与两端的时延有关,当时延大的,一开始,UDP发包可能有堵塞或丢包(NOWAIT模式)。

(1)设置发送速率为50mbps

aaa@ubuntu:~/share/iperf-master/src$ ./iperf3 -c 192.168.0.103 -u -t 5 -b 50M 
Connecting to host 192.168.0.103, port 5201
SNDBUF is 212992, expecting 0   //208KB
[  5] local 192.168.0.202 port 47768 connected to 192.168.0.103 port 5201
[ ID] Interval           Transfer     Bitrate         Total Datagrams
[  5]   0.00-1.00   sec  5.96 MBytes  50.0 Mbits/sec  4316  
[  5]   1.00-2.00   sec  5.96 MBytes  50.0 Mbits/sec  4316  
[  5]   2.00-3.00   sec  5.95 MBytes  49.9 Mbits/sec  4311  
[  5]   3.00-4.00   sec  5.97 MBytes  50.1 Mbits/sec  4322  
[  5]   4.00-5.00   sec  5.96 MBytes  50.0 Mbits/sec  4316  
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Jitter    Lost/Total Datagrams
[  5]   0.00-5.00   sec  29.8 MBytes  50.0 Mbits/sec  0.000 ms  0/21581 (0%)  sender
[  5]   0.00-5.00   sec  29.8 MBytes  50.0 Mbits/sec  0.265 ms  0/21573 (0%)  receiver

iperf Done.
aaa@ubuntu:~/share/iperf-master/src$ ./iperf3 -c 192.168.0.103 -u -t 5 -b 50M -w 10K
Connecting to host 192.168.0.103, port 5201
SNDBUF is 20480, expecting 10240    //配置了10K,实际系统配置是20K
[  5] local 192.168.0.202 port 36518 connected to 192.168.0.103 port 5201
[ ID] Interval           Transfer     Bitrate         Total Datagrams
[  5]   0.00-1.02   sec  5.93 MBytes  49.0 Mbits/sec  4296  
[  5]   1.02-2.00   sec  5.98 MBytes  50.9 Mbits/sec  4327  
[  5]   2.00-3.00   sec  5.97 MBytes  50.1 Mbits/sec  4320  
[  5]   3.00-4.00   sec  5.97 MBytes  50.0 Mbits/sec  4321  
[  5]   4.00-5.00   sec  5.95 MBytes  50.0 Mbits/sec  4312  
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Jitter    Lost/Total Datagrams
[  5]   0.00-5.00   sec  29.8 MBytes  50.0 Mbits/sec  0.000 ms  0/21576 (0%)  sender
[  5]   0.00-5.00   sec  27.0 MBytes  45.4 Mbits/sec  0.264 ms  1984/21567 (9.2%)  receiver

iperf Done.
aaa@ubuntu:~/share/iperf-master/src$ ./iperf3 -c 192.168.0.103 -u -t 5 -b 50M -w 20K 
Connecting to host 192.168.0.103, port 5201
SNDBUF is 40960, expecting 20480
[  5] local 192.168.0.202 port 38735 connected to 192.168.0.103 port 5201
[ ID] Interval           Transfer     Bitrate         Total Datagrams
[  5]   0.00-1.00   sec  5.96 MBytes  49.9 Mbits/sec  4313  
[  5]   1.00-2.00   sec  5.96 MBytes  50.0 Mbits/sec  4313  
[  5]   2.00-3.00   sec  5.97 MBytes  50.0 Mbits/sec  4320  
[  5]   3.00-4.00   sec  5.96 MBytes  50.0 Mbits/sec  4316  
[  5]   4.00-5.00   sec  5.96 MBytes  50.1 Mbits/sec  4319  
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Jitter    Lost/Total Datagrams
[  5]   0.00-5.00   sec  29.8 MBytes  50.0 Mbits/sec  0.000 ms  0/21581 (0%)  sender
[  5]   0.00-5.00   sec  29.4 MBytes  49.4 Mbits/sec  0.263 ms  264/21579 (1.2%)  receiver

iperf Done.
aaa@ubuntu:~/share/iperf-master/src$ ./iperf3 -c 192.168.0.103 -u -t 5 -b 50M -w 30K
Connecting to host 192.168.0.103, port 5201
SNDBUF is 61440, expecting 30720
[  5] local 192.168.0.202 port 43618 connected to 192.168.0.103 port 5201
[ ID] Interval           Transfer     Bitrate         Total Datagrams
[  5]   0.00-1.00   sec  5.96 MBytes  50.0 Mbits/sec  4316  
[  5]   1.00-2.00   sec  5.96 MBytes  50.0 Mbits/sec  4316  
[  5]   2.00-3.00   sec  5.96 MBytes  50.0 Mbits/sec  4314  
[  5]   3.00-4.00   sec  5.96 MBytes  50.0 Mbits/sec  4315  
[  5]   4.00-5.00   sec  5.96 MBytes  50.0 Mbits/sec  4318  
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Jitter    Lost/Total Datagrams
[  5]   0.00-5.00   sec  29.8 MBytes  50.0 Mbits/sec  0.000 ms  0/21579 (0%)  sender
[  5]   0.00-5.00   sec  29.4 MBytes  49.3 Mbits/sec  0.208 ms  272/21572 (1.3%)  receiver

iperf Done.
aaa@ubuntu:~/share/iperf-master/src$ ./iperf3 -c 192.168.0.103 -u -t 5 -b 50M -w 50K
Connecting to host 192.168.0.103, port 5201
SNDBUF is 102400, expecting 51200
[  5] local 192.168.0.202 port 42494 connected to 192.168.0.103 port 5201
[ ID] Interval           Transfer     Bitrate         Total Datagrams
[  5]   0.00-1.00   sec  5.96 MBytes  50.0 Mbits/sec  4315  
[  5]   1.00-2.00   sec  5.87 MBytes  49.3 Mbits/sec  4252  
[  5]   2.00-3.00   sec  6.04 MBytes  50.7 Mbits/sec  4377  
[  5]   3.00-4.00   sec  5.97 MBytes  50.0 Mbits/sec  4320  
[  5]   4.00-5.00   sec  5.96 MBytes  50.0 Mbits/sec  4313  
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Jitter    Lost/Total Datagrams
[  5]   0.00-5.00   sec  29.8 MBytes  50.0 Mbits/sec  0.000 ms  0/21577 (0%)  sender
[  5]   0.00-5.00   sec  29.6 MBytes  49.7 Mbits/sec  0.267 ms  127/21573 (0.59%)  receiver

iperf Done.
aaa@ubuntu:~/share/iperf-master/src$ ./iperf3 -c 192.168.0.103 -u -t 5 -b 50M 
Connecting to host 192.168.0.103, port 5201
SNDBUF is 212992, expecting 0
[  5] local 192.168.0.202 port 55511 connected to 192.168.0.103 port 5201
[ ID] Interval           Transfer     Bitrate         Total Datagrams
[  5]   0.00-1.00   sec  5.96 MBytes  50.0 Mbits/sec  4315  
[  5]   1.00-2.00   sec  5.96 MBytes  50.0 Mbits/sec  4313  
[  5]   2.00-3.00   sec  5.96 MBytes  50.0 Mbits/sec  4317  
[  5]   3.00-4.00   sec  5.96 MBytes  50.0 Mbits/sec  4318  
[  5]   4.00-5.00   sec  5.96 MBytes  50.0 Mbits/sec  4317  
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Jitter    Lost/Total Datagrams
[  5]   0.00-5.00   sec  29.8 MBytes  50.0 Mbits/sec  0.000 ms  0/21580 (0%)  sender
[  5]   0.00-5.00   sec  29.7 MBytes  49.9 Mbits/sec  0.289 ms  44/21580 (0.2%)  receiver

(2)设置发送速率为80mbps

aaa@ubuntu:~/share/iperf-master/src$ ./iperf3 -c 192.168.0.103 -u -t 5 -b 80M -w 50K  
Connecting to host 192.168.0.103, port 5201
SNDBUF is 102400, expecting 51200
[  5] local 192.168.0.202 port 57863 connected to 192.168.0.103 port 5201
[ ID] Interval           Transfer     Bitrate         Total Datagrams
[  5]   0.00-1.00   sec  9.51 MBytes  79.8 Mbits/sec  6887  
[  5]   1.00-2.00   sec  9.54 MBytes  80.0 Mbits/sec  6907  
[  5]   2.00-3.00   sec  9.54 MBytes  80.1 Mbits/sec  6911  
[  5]   3.00-4.00   sec  9.55 MBytes  80.1 Mbits/sec  6913  
[  5]   4.00-5.00   sec  9.54 MBytes  80.0 Mbits/sec  6909  
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Jitter    Lost/Total Datagrams
[  5]   0.00-5.00   sec  47.7 MBytes  80.0 Mbits/sec  0.000 ms  0/34527 (0%)  sender
[  5]   0.00-5.00   sec  42.2 MBytes  70.7 Mbits/sec  0.180 ms  3946/34470 (11%)  receiver

iperf Done.
aaa@ubuntu:~/share/iperf-master/src$ ./iperf3 -c 192.168.0.103 -u -t 5 -b 80M -w 100K
Connecting to host 192.168.0.103, port 5201
SNDBUF is 204800, expecting 102400
[  5] local 192.168.0.202 port 59945 connected to 192.168.0.103 port 5201
[ ID] Interval           Transfer     Bitrate         Total Datagrams
[  5]   0.00-1.00   sec  9.53 MBytes  79.9 Mbits/sec  6900  
[  5]   1.00-2.00   sec  9.54 MBytes  80.1 Mbits/sec  6911  
[  5]   2.00-3.00   sec  9.54 MBytes  80.0 Mbits/sec  6906  
[  5]   3.00-4.00   sec  9.54 MBytes  80.1 Mbits/sec  6907  
[  5]   4.00-5.00   sec  9.53 MBytes  79.9 Mbits/sec  6901  
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Jitter    Lost/Total Datagrams
[  5]   0.00-5.00   sec  47.7 MBytes  80.0 Mbits/sec  0.000 ms  0/34525 (0%)  sender
[  5]   0.00-5.00   sec  47.5 MBytes  79.8 Mbits/sec  0.295 ms  84/34510 (0.24%)  receiver

3. -l, --len

  • length of buffer to read or write (default 128 KB for TCP, 8 KB for UDP)
    这个表示每次write(send)的大小,而非发送或接收缓冲区的大小。

TCP而言,这个128K并非每个数据包都会有128K那么大,这个与系统设置、网络状态有关。然后tcp包会根据MSS来控制每个包的大小,最终会分成大小为MSS的“小”包(相对128K的大包),分包后,每个包依然是一个TCP包。一般来说,现在这个分包动作一般由网卡驱动来做,减轻协议栈负荷。

对于UDP,没有MSS的机制,那么只有通过IP层分片了(通常都会分成最大1480(不含UDP头,仅有IP头)和最大1472(含UDP头)),分成若干个IP包和一个UDP包。当然接收端最后会组合而成一个payload 8192的UDP包

在下面的iperf源码里blksize就是通过“-l”选项配置的

int Nwrite(int fd, const char *buf, size_t count, int prot)
{
    register ssize_t r;
    register size_t nleft = count;

    while (nleft > 0) {
		r = write(fd, buf, nleft);
		if (r < 0) {
		    switch (errno) {
			case EINTR:
			case EAGAIN:
#if (EAGAIN != EWOULDBLOCK)
			case EWOULDBLOCK:
#endif
				return count - nleft;

			case ENOBUFS:
				return NET_SOFTERROR;

			default:
				return NET_HARDERROR;
		    }
		} else if (r == 0)
		    return NET_SOFTERROR;
		nleft -= r;
		buf += r;
    }
    return count;
    
int iperf_tcp_send(struct iperf_stream *sp)
{
    int r;

    if (sp->test->zerocopy)
	r = Nsendfile(sp->buffer_fd, sp->socket, sp->buffer, sp->settings->blksize);
    else
	r = Nwrite(sp->socket, sp->buffer, sp->settings->blksize, Ptcp);

    if (r < 0)
        return r;

    sp->result->bytes_sent += r;
    sp->result->bytes_sent_this_interval += r;

    if (sp->test->debug)
	printf("sent %d bytes of %d, total %" PRIu64 "\n", r, sp->settings->blksize, sp->result->bytes_sent);

    return r;
}

int iperf_udp_send(struct iperf_stream *sp)
{
    int r;
    int       size = sp->settings->blksize;
    struct iperf_time before;

......
    r = Nwrite(sp->socket, sp->buffer, size, Pudp);

    if (r < 0)
	return r;

    sp->result->bytes_sent += r;
    sp->result->bytes_sent_this_interval += r;

    if (sp->test->debug)
	printf("sent %d bytes of %d, total %" PRIu64 "\n", r, sp->settings->blksize, sp->result->bytes_sent);

    return r;
}

4. -J, --json

把相关结果用json格式输出,这里可以看到更多的细节

{
	"start": {
		"connected": [{
			"socket": 4,
			"local_host": "192.168.0.202",
			"local_port": 41892,
			"remote_host": "192.168.0.103",
			"remote_port": 5201
		}],
    ......
		"connecting_to": {
			"host": "192.168.0.103",
			"port": 5201
		},
		"cookie": "ubuntu.1584752606.101102.5dfea28148b",
		"tcp_mss_default": 1448, 
		"test_start": {
			"protocol": "TCP",
			"num_streams": 1, //表示有多少条流传输测试(可能会建立更多的流,但是有些流不用于跑吞吐)
			"blksize": 131072, //这里对应的是参数-l
			"omit": 0,
			"duration": 3, // -t 
			"bytes": 0,
			"blocks": 0,
			"reverse": 0
		}
	},
	"intervals": [{
		"streams": [{
			"socket": 4,
			"start": 0,
			"end": 1.00056,
			"seconds": 1.00056,
			"bytes": 7804720,
			"bits_per_second": 6.24028e+07,
			"retransmits": 0,
			"snd_cwnd": 325800,
			"omitted": false
		}],
		"sum": {
			"start": 0,
			"end": 1.00056,
			"seconds": 1.00056,
			"bytes": 7804720,
			"bits_per_second": 6.24028e+07,
			"retransmits": 0,
			"omitted": false
		}
	}
	//此处省略2个streams/sum结果
	],
	"end": {
		"streams": [{
			"sender": {
				"socket": 4,
				"start": 0,
				"end": 3.00068,
				"seconds": 3.00068,
				"bytes": 29723560,
				"bits_per_second": 7.92448e+07,
				"retransmits": 0
			},
			"receiver": {
				"socket": 4,
				"start": 0,
				"end": 3.00068,
				"seconds": 3.00068,
				"bytes": 26984928,
				"bits_per_second": 7.19435e+07
			}
		}],
		"sum_sent": {
			"start": 0,
			"end": 3.00068,
			"seconds": 3.00068,
			"bytes": 29723560,
			"bits_per_second": 7.92448e+07,
			"retransmits": 0
		},
		"sum_received": {
			"start": 0,
			"end": 3.00068,
			"seconds": 3.00068,
			"bytes": 26984928,
			"bits_per_second": 7.19435e+07
		},
		"cpu_utilization_percent": {
			"host_total": 2.8436,
			"host_user": 0.576524,
			"host_system": 2.26691,
			"remote_total": 5.81529,
			"remote_user": 0.237727,
			"remote_system": 5.58659
		}
	}
}```

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值