iperf

最後更新: 2024-09-27

目錄

 


介紹

iperf 是用來測試 Server 與 Client 之間的連線速度工具來

它分別能夠測試 TCP 及 UDP 的來回(up/down)速度

 * iperf3 與 iperf2 是不相容的

 


iperf v2 用法

 

# Default Client use TCP upload to Server

iperf -s           # Server

iperf -c host    # Client

 


Server

 

Opts:

  • -s                        # server mode
  • -D                       # daemon
  • -p N                     # listen 那個 port ( Default: 5001 )
  • -B IP                    # listen 那個 interface
  • -u                        # 用 UDP 去 test speed ( Default: TCP )

i.e.

# 所有都用 Default Setting 來行 Server

iperf -s

# 未有 connection 時

------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------

# 改用 UDP 及 Port 8888 並 bind 其中一個 Interface

iperf -s -u -P 5001 -B 192.168.123.254

更改 TCP window size ( socket buffer size )

-w, --window n[KM]

more info

 


Client

 

 * Default run upload test only !! ( C -> S )

Opts

  • -c                        # client mode
  • -p p                     # server port, default port 5001
  • -P, --parallel n      # number of parallel client threads to run
  • -t t                      # 測試幾多秒 ( Default 10 secs )
  • -i s                      # 多久有一次 report. 預設每秒顯示一次
  • -f [kmKM]           # 顯示的單位 ( Kbits, Mbits, KBytes, MBytes )

Example1: 測試 20 秒, Unit: Mbit, 每 5 秒 report 一次

iperf.exe -c 192.168.123.254 -t 20 -f M -i 5

------------------------------------------------------------
Client connecting to 192.168.88.150, TCP port 5001
TCP window size: 0.04 MByte (default)
------------------------------------------------------------
[  3] local 192.168.8.231 port 58852 connected with 192.168.88.150 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0- 5.0 sec  33.8 MBytes  6.75 MBytes/sec
[  3]  5.0-10.0 sec  33.6 MBytes  6.72 MBytes/sec
[  3] 10.0-15.0 sec  33.6 MBytes  6.72 MBytes/sec
[  3] 15.0-20.0 sec  33.6 MBytes  6.72 MBytes/sec
[  3]  0.0-20.0 sec   135 MBytes  6.73 MBytes/sec

Example2: Parallel

[  6] local 10.0.0.1 port 56679 connected with 10.0.0.2 port 5001
[  4] local 10.0.0.1 port 56676 connected with 10.0.0.2 port 5001
[  5] local 10.0.0.1 port 56677 connected with 10.0.0.2 port 5001
[  3] local 10.0.0.1 port 56678 connected with 10.0.0.2 port 5001
[ ID] Interval       Transfer     Bandwidth
[  4]  0.0- 3.0 sec  82.0 MBytes   229 Mbits/sec
[  5]  0.0- 3.0 sec  86.8 MBytes   243 Mbits/sec
[  3]  0.0- 3.0 sec  88.8 MBytes   248 Mbits/sec
[  6]  0.0- 3.0 sec  80.1 MBytes   224 Mbits/sec
[SUM]  0.0- 3.0 sec   338 MBytes   944 Mbits/sec

 


UDP 測試

 

iperf uses a default of 1Mb/sec for UDP tests.

Use the -b flag on the iperf client to specify the UDP bandwidth you want to transmit at

opts

-u                        # 使用 udp 測試 (Default 是用 tcp 的)

-b                        # 限制 bandwidth. --bandwidth n[k/m](bit/sec) requires UDP (-u)

e.g.

# options 一定要放在最尾

iperf -c 192.168.88.150  -t 20 -i 5 -u -b 100m

------------------------------------------------------------
Client connecting to 192.168.88.150, UDP port 5001
Sending 1470 byte datagrams
UDP buffer size:  160 KByte (default)
------------------------------------------------------------
[  3] local 192.168.8.231 port 46373 connected with 192.168.88.150 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0- 5.0 sec  47.7 MBytes  80.1 Mbits/sec
[  3]  5.0-10.0 sec  47.6 MBytes  79.9 Mbits/sec
[  3] 10.0-15.0 sec  47.6 MBytes  79.8 Mbits/sec
[  3] 15.0-20.0 sec  47.6 MBytes  79.9 Mbits/sec
[  3]  0.0-20.0 sec   191 MBytes  79.9 Mbits/sec
[  3] Sent 135911 datagrams
[  3] Server Report:
[  3]  0.0-20.0 sec   191 MBytes  79.9 Mbits/sec   0.132 ms    0/135910 (0%)
[  3]  0.0-20.0 sec  1 datagrams received out-of-order

 


來回測試 (-r / -d)

 

Example:

iperf.exe -c 192.168.123.254 -f K  -r

  • -L N                # 是指要 Server send data 到 client 的那一個 port (client local port)
  • -r                   # --tradeoff, 是指先 client upload 完後, server 才再 send data 過來 Client
  • -d                   # --dualtest, 同時互相傳遞資料 ( duplex )

其他測試

-w N                              # 是用來加大 TCP Window Size ( defealt 8 KByte )

-N, --nodelay                 # Disabling Nagle's Algorithm

P.S.

當測試時要關 firewall, 因為效果會差很遠 (當開了 fw 後得 457 Mbits/sec )

測試時當速度有 740 Mbits/sec , CPU 大約佔用了 56-60% 左右 ( CPU: intel_e7200 )

另外當 "-d" 時, 在 xp 會很 lag

 



iperf3

 

與 version 2 的不同之處

 * iperf3 will only allow one iperf connection at a time.
    (iPerf2 can handle multiple client requests.)

 * Some iperf2 Features Not Supported by iPerf3

  • Bidirectional testing (-d, 同時 up&dl)
  • Data transmitted from stdin (-I)

Chec Version

iperf3 -v

iperf 3.11 (cJSON 1.7.13)

New Features in iPerf 3.1

  • -I, --pidfile                    # file write a file with the process ID, most useful when running as a daemon
  • --cport                         # Specify the client-side port
  • --sctp                           # use SCTP rather than TCP (Linux, FreeBSD and Solaris)
  • --udp-counters-64bit     # Support very long-running UDP tests, which could cause a counter to overflow
  • --logfile file                   # send output to a log file

New Features in iPerf 3.0

  • Dynamic Server (client/server parameter exchange)
  • Client/Server results exchange
  • -R,                                # Reverse test mode, Server sends, client receives
  • -O, --omit N                   # omit the first n seconds (to ignore TCP slowstart)
  • -Z, --zerocopy                # use a 'zero copy' sendfile() method of sending data.
                                        # This uses much less CPU. (Client Opts)
  • -b, --bandwidth n[KM]    # Default 1 Mbit/sec for UDP, unlimited for TCP
  • -V, --verbose                  # more detailed output than before
  • -J, --json                       # output in JSON format
  • -T, --title str                   # prefix every output line with this string
  • -F, --file name                # xmit/recv the specified file
  • -A, --affinity n/n,m         # set CPU affinity (cores are numbered from 0 - Linux and FreeBSD only)
  • -k, --blockcount             #[KMG] The number of blocks (packets) to transmit (instead of -t or -n)
  • -C, --linux-congestion     # set congestion control algorithm (Linux and FreeBSD only) (-Z in iPerf2)
  • iPerf API (libiperf)           # Provides an easy way to use, customize and extend iPerf functionality

Usage

Server(-s)

-f, --format [kmKM]        # 'k' = Kbits/sec, 'K' = KBytes/sec

-p port                           # Default: 5201/tcp

-i, --interval n                # If zero, no periodic reports are printed. Default is zero.

-F, --file name

  • client-side: read from the file and write to the network, instead of using random data;
  • server-side: read from the network and write to the file, instead of throwing the data away.

e.g.

iperf3 -s -D -i 5 -f M -p 5201 --logfile iperf.log -I iperf.pid

Client(-c)

預設是測試 upload 速度

  • -O, --omit n         # Omit the first n seconds of the test, to skip past the TCP TCP slowstart period
  • -P, --parallel n      # The number of simultaneous connections(Client) to make to the server. Default is 1
  • -R, --reverse        # Run in reverse mode (server sends, client receives)
  • -t sec                   # default 10 secs

iperf3 Usage Example

# 測試 Client 的 Upload 能力. 略過頭 3 秒, 測試 30 秒. 每 5 秒 report 一次

iperf3 -c 192.168.33.2 -O 3 -t 30 -i 5

Connecting to host 192.168.33.2, port 5201
[  5] local 192.168.8.11 port 58096 connected to 192.168.33.2 port 5201
[ ID] Interval           Transfer     Bitrate         Retr  Cwnd
[  5]   0.00-5.00   sec   513 MBytes   861 Mbits/sec    0    389 KBytes
[  5]   5.00-10.00  sec   512 MBytes   860 Mbits/sec    0    389 KBytes
...
[  5]  25.00-30.00  sec   512 MBytes   859 Mbits/sec    0    389 KBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Retr
[  5]   0.00-30.00  sec  3.00 GBytes   859 Mbits/sec    0             sender
[  5]   0.00-30.00  sec  3.00 GBytes   859 Mbits/sec                  receiver

iperf Done.

說明

Default: TCP 測速

Retr

stands for Retransmitted TCP packets

Cwnd

stands for "Congestion Window". It is a parameter used in TCP.

The value of Cwnd increases as long as no packet losses are detected.

# 測試 Client 的 Download 能力

iperf3.exe -c 192.168.88.150 -O 3 -i 10 -t 30 -R

 


 

 

Creative Commons license icon Creative Commons license icon