iperf3 測速
https://iperf.fr/iperf-doc.php
https://github.com/esnet/iperf
在 iPerf 2.0、iPerf 3.0 和 iPerf 3.1 之間切換
- iPerf3 當前支持的 iPerf2 功能:
- TCP 和 UDP 測試
- 設置端口(-p)
- 設置 TCP 選項:無延遲、MSS 等。
- 設置 UDP 帶寬 (-b)
- 設置套接字緩沖區大小 (-w)
- 報告間隔 (-i)
- 設置 iPerf 緩沖區 (-l)
- 綁定到特定接口 (-B)
- IPv6 測試 (-6)
- 要傳輸的字節數 (-n)
- 測試長度 (-t)
- 並行流 (-P)
- 設置 DSCP/TOS 位向量 (-S)
- 更改數字輸出格式 (-f)
- iPerf 3.0 中的新功能:
- 動態服務器(客戶端/服務器參數交換)——iPerf2 中的大多數服務器選項現在可以由客戶端動態設置
- 客戶端/服務器結果交換
- iPerf3 服務器同時接受單個客戶端(iPerf2 同時接受多個客戶端)
- iPerf API (libiperf) – 提供一種簡單的方法來使用、自定義和擴展 iPerf 功能
- -R,反向測試模式——服務器發送,客戶端接收
- -O, --omit N :省略前 n 秒(忽略TCP 慢啟動)
- -b, --bandwidth n[KM] 用於 TCP(僅 UDP 用於 IPERF 2):將目標帶寬設置為 n 位/秒(UDP 默認為 1 Mbit/秒,TCP 無限制)。
- -V, --verbose :比以前更詳細的輸出
- -J, --json : 以 JSON 格式輸出
- -Z, --zerocopy :使用“零拷貝”sendfile() 方法發送數據。這使用更少的CPU。
- -T, --title str : 用這個字符串作為每個輸出行的前綴
- -F, --file name : xmit/recv 指定文件
- -A, --affinity n/n,m :設置 CPU 親和性(核心從 0 開始編號 - 僅限 Linux 和 FreeBSD)
- -k, --blockcount #[KMG] :要傳輸的塊(數據包)數(而不是 -t 或 -n)
- -4, --version4 :僅使用 IPv4
- -6, --version6 :僅使用 IPv6
- -L, --flowlabel :設置 IPv6 流標簽(僅限 Linux)
- -C, --linux-congestion :設置擁塞控制算法(僅限 Linux 和 FreeBSD)(iPerf2 中的 -Z)
- -d, --debug :發出調試輸出。主要(可能專門)供開發人員使用。
- -s, --server : iPerf2 可以處理多個客戶端請求。iPerf3 一次只允許一個 iperf 連接。
- iPerf 3.1 中的新功能:
- -I, --pidfile file 使用進程 ID 寫入文件,在作為守護進程運行時最有用。
- --cport :指定客戶端端口。
- --sctp 使用 SCTP 而不是 TCP(Linux、FreeBSD 和 Solaris)。
- --udp-counters-64bit :支持非常長時間運行的 UDP 測試,這可能導致計數器溢出
- --logfile 文件:將輸出發送到日志文件。
- iPerf3 不支持的 iPerf2 功能:
- 雙向測試(-d / -r)
- 從標准輸入 (-I) 傳輸的數據
- TTL:生存時間,用於多播 (-T)
- 排除 C(連接) D(數據) M(多播) S(設置) V(服務器)報告 (-x)
- 報告為逗號分隔值 (-y)
- 兼容模式允許與舊版本的 iPerf (-C) 一起使用
iPerf 3 user documentation
GENERAL OPTIONS | |
---|---|
Command line option | Description |
-p, --port n | The server port for the server to listen on and the client to connect to. This should be the same in both client and server. Default is 5201. |
--cport n | Option to specify the client-side port. (new in iPerf 3.1) |
-f, --format [kmKM] | A letter specifying the format to print bandwidth numbers in. Supported formats are 'k' = Kbits/sec 'K' = KBytes/sec 'm' = Mbits/sec 'M' = MBytes/secThe adaptive formats choose between kilo- and mega- as appropriate. |
-i, --interval n | Sets the interval time in seconds between periodic bandwidth, jitter, and loss reports. If non-zero, a report is made every interval seconds of the bandwidth since the last report. 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. |
-A, --affinity n/n,m-F | Set the CPU affinity, if possible (Linux and FreeBSD only). On both the client and server you can set the local affinity by using the n form of this argument (where n is a CPU number). In addition, on the client side you can override the server’s affinity for just that one test, using the n,m form of argument. Note that when using this feature, a process will only be bound to a single CPU (as opposed to a set containing potentialy multiple CPUs). |
-B, --bind host | Bind to host, one of this machine's addresses. For the client this sets the outbound interface. For a server this sets the incoming interface. This is only useful on multihomed hosts, which have multiple network interfaces. |
-V, --verbose | give more detailed output |
-J, --json | output in JSON format |
--logfile file | send output to a log file. (new in iPerf 3.1) |
--d, --debug | emit debugging output. Primarily (perhaps exclusively) of use to developers. |
-v, --version | Show version information and quit. |
-h, --help | Show a help synopsis and quit. |
SERVER SPECIFIC OPTIONS | |
Command line option | Description |
-s, --server | Run iPerf in server mode. (This will only allow one iperf connection at a time) |
-D, --daemon | Run the server in background as a daemon. |
-I, --pidfilefile | write a file with the process ID, most useful when running as a daemon. (new in iPerf 3.1) |
CLIENT SPECIFIC OPTIONS | |
Command line option | Description |
-c, --client host | Run iPerf in client mode, connecting to an iPerf server running on host. |
--sctp | Use SCTP rather than TCP (Linux, FreeBSD and Solaris). (new in iPerf 3.1) |
-u, --udp | Use UDP rather than TCP. See also the -b option. |
-b, --bandwidth n[KM] | Set target bandwidth to n bits/sec (default 1 Mbit/sec for UDP, unlimited for TCP). If there are multiple streams (-P flag), the bandwidth limit is applied separately to each stream. You can also add a ’/’ and a number to the bandwidth specifier. This is called "burst mode". It will send the given number of packets without pausing, even if that temporarily exceeds the specified bandwidth limit. |
-t, --time n | The time in seconds to transmit for. iPerf normally works by repeatedly sending an array of len bytes for time seconds. Default is 10 seconds. See also the -l, -k and -n options. |
-n, --num n[KM] | The number of buffers to transmit. Normally, iPerf sends for 10 seconds. The -n option overrides this and sends an array of len bytes num times, no matter how long that takes. See also the -l, -k and -t options. |
-k, --blockcount n[KM] | The number of blocks (packets) to transmit. (instead of -t or -n) See also the -t, -l and -n options. |
-l, --length n[KM] | The length of buffers to read or write. iPerf works by writing an array of len bytes a number of times. Default is 128 KB for TCP, 8 KB for UDP. See also the -n, -k and -t options. |
-P, --parallel n | The number of simultaneous connections to make to the server. Default is 1. |
-R, --reverse | Run in reverse mode (server sends, client receives). |
-w, --window n[KM] | Sets the socket buffer sizes to the specified value. For TCP, this sets the TCP window size. (this gets sent to the server and used on that side too) |
-M, --set-mss n | Attempt to set the TCP maximum segment size (MSS). The MSS is usually the MTU - 40 bytes for the TCP/IP header. For ethernet, the MSS is 1460 bytes (1500 byte MTU). |
-N, --no-delay | Set the TCP no delay option, disabling Nagle's algorithm. Normally this is only disabled for interactive applications like telnet. |
-4, --version4 | only use IPv4. |
-6, --version4 | only use IPv6. |
-S, --tos n | The type-of-service for outgoing packets. (Many routers ignore the TOS field.) You may specify the value in hex with a '0x' prefix, in octal with a '0' prefix, or in decimal. For example, '0x10' hex = '020' octal = '16' decimal. The TOS numbers specified in RFC 1349 are: IPTOS_LOWDELAY minimize delay 0x10 IPTOS_THROUGHPUT maximize throughput 0x08 IPTOS_RELIABILITY maximize reliability 0x04 IPTOS_LOWCOST minimize cost 0x02 |
-L, --flowlabel n | Set the IPv6 flow label (currently only supported on Linux). |
-Z, --zerocopy | Use a "zero copy" method of sending data, such as sendfile(2), instead of the usual write(2). This uses much less CPU. |
-O, --omit n | Omit the first n seconds of the test, to skip past the TCP TCP slowstart period. |
-T, --title str | Prefix every output line with this string. |
-C, --linux-congestion algo | Set the congestion control algorithm (Linux only for iPerf 3.0, Linux and FreeBSD for iPerf 3.1). |
root@ubuntu-test:~# root@ubuntu-test:~# vi /lib/systemd/system/iperf3.service root@ubuntu-test:~# root@ubuntu-test:~# cat /lib/systemd/system/iperf3.service [Unit] Description=iperf3 server After=syslog.target network.target auditd.service [Service] PIDFile=/var/run/iperf3.pid ExecStart=/usr/bin/iperf3 -s ExecStop=/usr/bin/killall -9 iperf3 [Install] WantedBy=multi-user.target root@ubuntu-test:~# root@ubuntu-test:~# systemctl daemon-reload root@ubuntu-test:~# root@ubuntu-test:~# systemctl start iperf3.service root@ubuntu-test:~# root@ubuntu-test:~# systemctl status iperf3.service ● iperf3.service - iperf3 server Loaded: loaded (/lib/systemd/system/iperf3.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2022-03-30 09:17:34 EDT; 2min 6s ago Main PID: 19282 (iperf3) Tasks: 1 (limit: 4915) CGroup: /system.slice/iperf3.service └─19282 /usr/bin/iperf3 -s Mar 30 09:17:34 ubuntu-test systemd[1]: Started iperf3 server. root@ubuntu-test:~# root@ubuntu-test:~# systemctl enable iperf3 root@ubuntu-test:~# root@ubuntu-test:~# systemctl list-units --type=service | grep iperf3 iperf3.service loaded active running iperf3 server root@ubuntu-test:~# root@ubuntu-test:~# sudo systemctl list-unit-files | grep enable | grep iperf3 iperf3.service enabled root@ubuntu-test:~#
網絡性能測試工具 iperf 的使用
來源 https://zhuanlan.zhihu.com/p/390420078
常用的參數有
-u
:發送 UDP 包,僅客戶端可用,服務端默認 tcp udp 都可以接收-b
:指定發送速率(比如 100M),發送端不受限速影響,如果有限速,也只是接收端有影響-p
:后接服務端監聽的端口(默認端口: 5201)-i
:設置帶寬報告的時間間隔,單位為秒-t
:設置測試的時長,單位為秒-w
:設置tcp窗口大小,一般可以不用設置,默認即可-B
:綁定客戶端的ip地址-4
:指定 ipv4-n
:指定傳輸的字節數-f
:格式化帶寬數輸出,后接單位,比如 K,M--get-server-output
:在客戶端直接獲取服務端輸出的結果
iperf3 的結果
iperf3 的輸出結果可以分為兩類
- 一類是,詳細的帶寬數據
- 一類是,最終的帶寬數據
如果你像我一樣加上 --get-server-output
,可以看到服務端輸出的報告。
接下來看一下,輸出的報告有哪些內容。
- 第一列 Interval:測試的時長
- 第二列 Transfer:在 Interval 時長里,傳輸的數據量
- 第三列 Bitrate:傳輸速率
- 第四列 Jitter:網絡抖動,連續發送數據包時延差值的平均值,越小說明網絡質量越好
- 第五列 Lost/Total Datagrams:丟失的數據包與發送的總數據包
============
HT2500 Modem Info
SAN: HTS65TEST0010 ESN: 14708933
BeamID: beam01
RxHuntFreq: 1936.25MHz
RxLnbLO: 10600MHz
TxBucLO: 12800MHz
RxPol: V
============
Speedtest
Download: 10.15Mbps Upload: 2.10Mbps Ping: 600.30ms Jitter: 116.88ms
============
iperf3
TxPacketNum: 100 ServerTx: 10Mbits/sec ClientRx: 10Mbits/sec
[ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams
[ 4] 0.00-100.00 sec 120 MBytes 10.1 Mbits/sec 1.169 ms 2639/89715 (2.9%)
[ 4] Sent 89715 datagrams
------------
TxPacketNum: 100 ClientTx: 1Mbits/sec ServerRx: 1Mbits/sec
[ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams
[ 4] 0.00-100.00 sec 11.9 MBytes 999 Kbits/sec 26.338 ms 428/8838 (4.8%)
[ 4] Sent 8838 datagrams
============
iperf3.exe -B 10.241.128.53 -c 192.168.151.200 -u -i 1 -t 10 -l 1400 -b 1m --get-server-output
iperf3.exe -B 10.241.128.53 -c 192.168.151.200 -u -R -i 1 -t 10 -l 1400 -b 10m --get-server-output
經驗總結
- 如果想要
測試吞吐量
,抖動
和丟包率
這三個指標,只能添加-u
參數 使用UDP進行測試,並且使用--get-server-output
獲得 server端的報告。最后不斷在client端增加帶寬值,直到server端出現輕微的丟包為止,此時server端顯示的帶寬就是被測系統的吞吐量。 - 我們在做性能測試的時候需要指定包長,不同的包長會得到不同的吞吐量,通過-l指定,而使用-b指定帶寬。
- 使用TCP來測試網絡帶寬,有一個參數需要特別注意,那就是TCP窗口大小,可以使用-w參數指定。網絡通道的容量capacity = bandwidth * round-trip time。而理論TCP窗口的大小就是網絡通道的容量。比如,網絡帶寬為40Mbit/s,回環路徑消耗時間是2ms,那么TCP的窗口大小不小於40Mbit/s×2ms = 80kbit = 10Kbytes,此時我們可以查詢iperf默認的TCP窗口大小來決定是否需要設置此參數,在此例中,窗口大小應設計大於10Kbytes,當然,這僅僅是理論值,在實際測試中可能需要作出調整。
=============== End