最後更新: 2019-05-06
介紹
iperf 是用來測試 Server 與 Client 之間的連線速度工具來
它分別能夠測試 TCP 及 UDP 的來回速度
* iperf3 與 iperf2 是不相容的
目錄
iperf v2 用法
# Default Client use TCP upload to Server
iperf -s # Server
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]
Client
Opts
- -c # client mode
- -t t # 測試幾多秒 ( Default 10 secs )
- -f [kmKM] # 顯示的單位 ( Kbits, Mbits, KBytes, MBytes )
- -i s # 多久有一次 report
- -p p # server port, default port 5001
- -P, --parallel n # number of parallel client threads to run
P.S.
Default Upload Test Only !! ( C -> S )
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))
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)
- (Most server options from iPerf2 can now be dynamically set by the client)
- Client/server results exchange
- iPerf API (libiperf) # Provides an easy way to use, customize and extend iPerf functionality
- -R, # Reverse test mode, Server sends, client receives
- -O, --omit N # omit the first n seconds (to ignore TCP slowstart)
- -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
- -Z, --zerocopy # use a 'zero copy' sendfile() method of sending data. This uses much less CPU. ( Client Opts)
- -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] : 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)
Usage
Server
-f, --format [kmKM] # 'k' = Kbits/sec, 'K' = KBytes/sec
-p port # Default 5201
-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.
-i, --interval n # If zero, no periodic reports are printed. Default is zero.
iperf3 -s -D -i 5 -f M -p 5201 --logfile iperf.log -I iperf.pid
Client
- -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
ie.
# 測試 Client 的 Upload 能力
iperf3.exe -c 192.168.88.150 -O 3 -i 10 -t 60
[ 4] local 192.168.88.177 port 4033 connected to 192.168.88.150 port 5201 [ ID] Interval Transfer Bandwidth [ 4] 0.00-10.00 sec 873 MBytes 732 Mbits/sec [ 4] 10.00-20.00 sec 918 MBytes 770 Mbits/sec [ 4] 20.00-30.00 sec 924 MBytes 775 Mbits/sec [ 4] 30.00-40.00 sec 878 MBytes 736 Mbits/sec [ 4] 40.00-50.01 sec 950 MBytes 796 Mbits/sec [ 4] 50.01-59.99 sec 883 MBytes 742 Mbits/sec - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bandwidth [ 4] 0.00-59.99 sec 5.30 GBytes 759 Mbits/sec sender [ 4] 0.00-59.99 sec 5.30 GBytes 759 Mbits/sec receiver
# 測試 Client 的 Download 能力
iperf3.exe -c 192.168.88.150 -O 3 -i 10 -t 30 -R
[ 4] local 192.168.88.177 port 1038 connected to 192.168.88.150 port 5201 [ ID] Interval Transfer Bandwidth [ 4] 0.00-10.00 sec 858 MBytes 720 Mbits/sec [ 4] 10.00-20.00 sec 820 MBytes 687 Mbits/sec [ 4] 20.00-30.00 sec 859 MBytes 721 Mbits/sec - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bandwidth Retr [ 4] 0.00-30.00 sec 2.48 GBytes 711 Mbits/sec 0 sender [ 4] 0.00-30.00 sec 2.48 GBytes 710 Mbits/sec receiver
Retr
Retr stands for Retransmitted TCP packets