背景
最近公司在整改内网服务网络质量。内网间速度从百兆上升至千兆。
此处记录下测试方法。
服务器
内网服务器两台: 192.168.32.175、192.168.32.176
网络测试
两台服务器安装 iperf3
apt install iperf3
~# apt install iperf3
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libiperf0 libsctp1
Suggested packages:
lksctp-tools
The following NEW packages will be installed:
iperf3 libiperf0 libsctp1
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 94.1 kB of archives.
After this operation, 331 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 https://mirrors.ustc.edu.cn/ubuntu focal/main amd64 libsctp1 amd64 1.0.18+dfsg-1 [7876 B]
Get:2 https://mirrors.ustc.edu.cn/ubuntu focal/universe amd64 libiperf0 amd64 3.7-3 [72.0 kB]
Get:3 https://mirrors.ustc.edu.cn/ubuntu focal/universe amd64 iperf3 amd64 3.7-3 [14.2 kB]
Fetched 94.1 kB in 0s (430 kB/s)
Selecting previously unselected package libsctp1:amd64.
(Reading database ... 82143 files and directories currently installed.)
Preparing to unpack .../libsctp1_1.0.18+dfsg-1_amd64.deb ...
Unpacking libsctp1:amd64 (1.0.18+dfsg-1) ...
Selecting previously unselected package libiperf0:amd64.
Preparing to unpack .../libiperf0_3.7-3_amd64.deb ...
Unpacking libiperf0:amd64 (3.7-3) ...
Selecting previously unselected package iperf3.
Preparing to unpack .../iperf3_3.7-3_amd64.deb ...
Unpacking iperf3 (3.7-3) ...
Setting up libsctp1:amd64 (1.0.18+dfsg-1) ...
Setting up libiperf0:amd64 (3.7-3) ...
Setting up iperf3 (3.7-3) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
接收端
在其中一台服务器上运行接收端命令。 假设此处服务器ip为 192.168.32.176
iperf3 -s
默认端口号为5201, 如果需要指定的端口号加上-p port: iperf3 -s -p <port>
, 例:iperf3 -s -p 8080
发送端
在另一台服务器上作为发送端。 执行下述发送命令:
Options:
iperf3 -c <接收端ip>
命令:
iperf3 -c 192.168.32.176
日志
服务器端(接收端)
~# iperf3 -s
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------
Accepted connection from 192.168.32.175, port 33550
[ 5] local 192.168.32.176 port 5201 connected to 192.168.32.175 port 33552
[ ID] Interval Transfer Bitrate
[ 5] 0.00-1.00 sec 1.01 GBytes 8.70 Gbits/sec
[ 5] 1.00-2.00 sec 1.14 GBytes 9.81 Gbits/sec
[ 5] 2.00-3.00 sec 1.08 GBytes 9.31 Gbits/sec
[ 5] 3.00-4.00 sec 1.17 GBytes 10.0 Gbits/sec
[ 5] 4.00-5.00 sec 1.25 GBytes 10.7 Gbits/sec
[ 5] 5.00-6.00 sec 1.25 GBytes 10.7 Gbits/sec
[ 5] 6.00-7.00 sec 1.32 GBytes 11.4 Gbits/sec
[ 5] 7.00-8.00 sec 1.22 GBytes 10.4 Gbits/sec
[ 5] 8.00-9.00 sec 1.28 GBytes 11.0 Gbits/sec
[ 5] 9.00-10.00 sec 1.60 GBytes 13.8 Gbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bitrate
[ 5] 0.00-10.00 sec 12.3 GBytes 10.6 Gbits/sec receiver
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------
客户端(发送端)
~# iperf3 -c 192.168.32.176
Connecting to host 192.168.32.176, port 5201
[ 5] local 192.168.32.175 port 33552 connected to 192.168.32.176 port 5201
[ ID] Interval Transfer Bitrate Retr Cwnd
[ 5] 0.00-1.00 sec 1.01 GBytes 8.70 Gbits/sec 0 3.08 MBytes
[ 5] 1.00-2.00 sec 1.15 GBytes 9.84 Gbits/sec 0 3.08 MBytes
[ 5] 2.00-3.00 sec 1.08 GBytes 9.30 Gbits/sec 0 3.08 MBytes
[ 5] 3.00-4.00 sec 1.17 GBytes 10.0 Gbits/sec 0 3.08 MBytes
[ 5] 4.00-5.00 sec 1.25 GBytes 10.7 Gbits/sec 0 3.08 MBytes
[ 5] 5.00-6.00 sec 1.25 GBytes 10.7 Gbits/sec 0 3.08 MBytes
[ 5] 6.00-7.00 sec 1.32 GBytes 11.4 Gbits/sec 0 3.08 MBytes
[ 5] 7.00-8.00 sec 1.21 GBytes 10.4 Gbits/sec 0 3.08 MBytes
[ 5] 8.00-9.00 sec 1.28 GBytes 11.0 Gbits/sec 0 3.08 MBytes
[ 5] 9.00-10.00 sec 1.60 GBytes 13.8 Gbits/sec 0 3.08 MBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bitrate Retr
[ 5] 0.00-10.00 sec 12.3 GBytes 10.6 Gbits/sec 0 sender
[ 5] 0.00-10.00 sec 12.3 GBytes 10.6 Gbits/sec receiver
iperf Done.
iperf3 手册
官网下载地址:
iperf
iPerf3是用于主动测试IP网络上最大可用带宽的工具。它支持时序、缓冲区、协议(TCP,UDP,SCTP与IPv4和IPv6)有关的各种参数。对于每次测试,它都会详细的带宽报告,延迟抖动和数据包丢失。
它与原始 iPerf 不共享任何代码,也不向后兼容。
它是一个C/S架构的测试工具,需要在同时运行在服务器端和客户端。
CMD
执行,iperf3 -h,可以查看所有的命令信息。
命令手册:
~# iperf3 -h
Usage: iperf3 [-s|-c host] [options]
iperf3 [-h|--help] [-v|--version]
Server or Client: 公共参数
-p, --port # server port to listen on/connect to【Server 端监听、Client 端连接的端口号】
-f, --format [kmgtKMGT] format to report【报告中所用的数据单位】: Kbits, Mbits, Gbits, Tbits
-i, --interval # seconds between periodic throughput reports【每次报告的间隔,单位为秒】
-F, --file name xmit/recv the specified file
【测试所用文件的文件名。如果使用在 Client 端,发送该文件用作测试;如果使用在 Server 端,则是将数据写入该文件,而不是丢弃】
-A, --affinity n/n,m set CPU affinity【设置 CPU 亲和力】
-B, --bind <host> bind to the interface associated with the address <host>【绑定指定的网卡接口】
-V, --verbose more detailed output【运行时输出更多细节】
-J, --json output in JSON format【运行时以 JSON 格式输出结果】
--logfile f send output to a log file【输出到文件】
--forceflush force flushing output at every interval
-d, --debug emit debugging output【以 debug 模式输出结果】
-v, --version show version information and quit【显示版本信息并退出】
-h, --help show this message and quit【显示帮助信息并退出】
Server specific: Server 端参数
-s, --server run in server mode【以 Server 模式运行】
-D, --daemon run the server as a daemon【在后台以守护进程运行】
-I, --pidfile file write PID file【指定 pid 文件】
-1, --one-off handle one client connection then exit
【只接受 1 次来自 Client 端的测试,然后退出】
--rsa-private-key-path path to the RSA private key used to decrypt
authentication credentials
--authorized-users-path path to the configuration file containing user
credentials
Client specific: Client 端参数
-c, --client <host> run in client mode, connecting to <host>
【以 Client 模式运行,并指定 Server 端的地址】
--sctp use SCTP rather than TCP
-X, --xbind <name> bind SCTP association to links
--nstreams # number of SCTP streams
-u, --udp use UDP rather than TCP【以 UDP 协议进行测试】
--connect-timeout # timeout for control connection setup (ms)
-b, --bitrate #[KMG][/#] target bitrate in bits/sec (0 for unlimited)
(default 1 Mbit/sec for UDP, unlimited for TCP)
(optional slash and packet count for burst mode)
【限制测试带宽。UDP 默认为 1Mbit/秒,TCP 默认无限制】
--pacing-timer #[KMG] set the timing for pacing, in microseconds (default 1000)
--fq-rate #[KMG] enable fair-queuing based socket pacing in
bits/sec (Linux only)
-t, --time # time in seconds to transmit for (default 10 secs)
【以时间为测试结束条件进行测试,默认为 10 秒】
-n, --bytes #[KMG] number of bytes to transmit (instead of -t)
【以数据传输大小为测试结束条件进行测试】
-k, --blockcount #[KMG] number of blocks (packets) to transmit (instead of -t or -n)
【以传输数据包数量为测试结束条件进行测试】
-l, --length #[KMG] length of buffer to read or write
(default 128 KB for TCP, dynamic or 1460 for UDP)
【读写缓冲区的长度,TCP 默认为 128K,UDP 默认为 8K】
--cport <port> bind to a specific client port (TCP and UDP, default: ephemeral port)
【指定 Client 端运行所使用的 TCP 或 UDP 端口,默认为临时端口】
-P, --parallel # number of parallel client streams to run【测试数据流并发数量】
-R, --reverse run in reverse mode (server sends, client receives)【反向模式运行(Server 端发送,Client 端接收)】
--bidir run in bidirectional mode.
Client and server send and receive data.
-w, --window #[KMG] set window size / socket buffer size【设置套接字缓冲区大小,TCP 模式下为窗口大小】
-C, --congestion <algo> set TCP congestion control algorithm (Linux and FreeBSD only)
【设置 TCP 拥塞控制算法(仅支持 Linux 和 FreeBSD )】
-M, --set-mss # set TCP/SCTP maximum segment size (MTU - 40 bytes)
【设置 TCP/SCTP 最大分段长度(MSS,MTU 减 40 字节)】
-N, --no-delay set TCP/SCTP no delay, disabling Nagle's Algorithm【设置 TCP/SCTP no delay,屏蔽 Nagle 算法】
-4, --version4 only use IPv4【仅使用 IPv4】
-6, --version6 only use IPv6【仅使用 IPv6】
-S, --tos N set the IP type of service, 0-255.
The usual prefixes for octal and hex can be used,
i.e. 52, 064 and 0x34 all specify the same value.
【设置 IP 服务类型(TOS,Type Of Service)】
--dscp N or --dscp val set the IP dscp value, either 0-63 or symbolic.
Numeric values can be specified in decimal,
octal and hex (see --tos above).
-L, --flowlabel N set the IPv6 flow label (only supported on Linux)【设置 IPv6 流标签(仅支持 Linux)】
-Z, --zerocopy use a 'zero copy' method of sending data【使用 “zero copy”(零拷贝)方法发送数据】
-O, --omit N omit the first n seconds【忽略前 n 秒的测试】
-T, --title str prefix every output line with this string【设置每行测试结果的前缀】
--extra-data str data string to include in client and server JSON
--get-server-output get results from server【从 Server 端获取测试结果】
--udp-counters-64bit use 64-bit counters in UDP test packets
【在 UDP 测试包中使用 64 位计数器(防止计数器溢出)】
--repeating-payload use repeating pattern in payload, instead of
randomized payload (like in iperf2)
--username username for authentication
--rsa-public-key-path path to the RSA public key used to encrypt
authentication credentials
[KMG] indicates options that support a K/M/G suffix for kilo-, mega-, or giga-
iperf3 homepage at: https://software.es.net/iperf/
Report bugs to: https://github.com/esnet/iperf
复杂用例
运行iperf3在客户端,使用UDP协议,并设置使用的测试带宽:
iperf3 -s -p <port>
iperf3 -c <serverIP>
-p <port>
-b 1000M -t 60 -d
-c 为客户端运行并要指定服务端的IP地址
-b 表示使用的测试带宽
-t 表示以时间为测试结束条件进行测试,默认为 10 秒;
-d 打印出更详细的debug调试信息
服务端:
iperf3 -s -p 18181客户端:
iperf3 -c 192.168.32.176 -p 18181 -b 1000M -t 60 -d
服务端报告:
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bitrate
[ 5] 0.00-59.93 sec 6.98 GBytes 1.00 Gbits/sec receiver
-----------------------------------------------------------
客户端报告:
send_results
{
"cpu_util_total": 17.623769540641447,
"cpu_util_user": 0.76691941560797527,
"cpu_util_system": 16.856870123323286,
"sender_has_retransmits": 1,
"congestion_used": "cubic",
"streams": [{
"id": 1,
"bytes": 7499939840,
"retransmits": 0,
"jitter": 0,
"errors": 0,
"packets": 0,
"start_time": 0,
"end_time": 60.000149
}]
}
get_results
{
"cpu_util_total": 4.935035309381572,
"cpu_util_user": 0.3594056678518765,
"cpu_util_system": 4.5756337861111254,
"sender_has_retransmits": -1,
"congestion_used": "cubic",
"streams": [{
"id": 1,
"bytes": 7499939840,
"retransmits": -1,
"jitter": 0,
"errors": 0,
"packets": 0,
"start_time": 0,
"end_time": 59.933064
}]
}
interval_len 1.000061 bytes_transferred 125042688
interval forces keep
[ 5] 59.00-60.00 sec 119 MBytes 1.00 Gbits/sec 0 691 KBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bitrate Retr
[ 5] 0.00-60.00 sec 6.98 GBytes 1000 Mbits/sec 0 sender
[ 5] 0.00-59.93 sec 6.98 GBytes 1.00 Gbits/sec receiver
iperf Done.
Interval:程序的运行时间
Transfer:传输的数据总量
Bandwidth:测试出的带宽
Jitter:网路抖动
Lost/Total Datagrams:丢包数/总数据包数(丢包率)
其他
如果发现退出后端口仍被占用的情况,按如下步骤 kill.
# 查看端口占用情况
~# netstat -anp |grep 18182
tcp6 0 0 :::18182 :::* LISTEN 483214/iperf3 <pid> / <server name>
~# kill -9 483214
netstat 语法格式
netstat -tunlp | grep 端口号
netstat -anp | grep 端口号
-t (tcp) 仅显示tcp相关选项
-u (udp)仅显示udp相关选项
-n 拒绝显示别名,能显示数字的全部转化为数字
-l 仅列出在Listen(监听)的服务状态
-p 显示建立相关链接的程序名