介绍
iperf/iperf3命令是一个网络性能测试工具,可以测试TCP,UDP,SCTP带宽表现,丢包率或者发包性能,是一个网络测试的实用工具。 其在windows上也有移植的版本可以使用。iperf3和iperf有些细微差别,这里以iperf3为主。
使用
iperf工具可以运行为服务器端或客户端,服务器端是收包的,客户端是发包的。使用时,需要指定作为服务器和客户端,二者有一些共同参数, 以及各自的额外参数。详细参考 man iperf3
即可,参数选项较多。
简单示例:(测试时不要有其他占用网络带宽的应用)。
tcp测试
首先启动一个iperf3 server。默认全地址段监听。
1
2
3
4
$ iperf3 -s
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------
再使用一个client去进行测试,需要指定server的地址,client会向server 不断发包,也可以通过参数修改包间隔,大小,数量等参数。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$ iperf3 -c 192.168.100.2
Connecting to host 192.168.100.2, port 5201
[ 4] local 192.168.2.224 port 35400 connected to 192.168.100.2 port 5201
[ ID] Interval Transfer Bandwidth Retr Cwnd
[ 4] 0.00-1.00 sec 114 MBytes 959 Mbits/sec 0 378 KBytes
[ 4] 1.00-2.00 sec 112 MBytes 942 Mbits/sec 0 395 KBytes
[ 4] 2.00-3.00 sec 112 MBytes 942 Mbits/sec 0 414 KBytes
[ 4] 3.00-4.00 sec 112 MBytes 942 Mbits/sec 0 414 KBytes
[ 4] 4.00-5.00 sec 112 MBytes 941 Mbits/sec 0 414 KBytes
[ 4] 5.00-6.00 sec 112 MBytes 941 Mbits/sec 0 414 KBytes
[ 4] 6.00-7.00 sec 112 MBytes 941 Mbits/sec 0 414 KBytes
[ 4] 7.00-8.00 sec 112 MBytes 942 Mbits/sec 0 414 KBytes
[ 4] 8.00-9.00 sec 112 MBytes 942 Mbits/sec 0 414 KBytes
[ 4] 9.00-10.00 sec 112 MBytes 941 Mbits/sec 0 414 KBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bandwidth Retr
[ 4] 0.00-10.00 sec 1.10 GBytes 943 Mbits/sec 0 sender
[ 4] 0.00-10.00 sec 1.10 GBytes 941 Mbits/sec receiver
iperf Done.
server段也会显示接收情况,因为中间会经过路由器,所以可能丢包,所以client的发的速率和server接收的速率可能会有些差距。
udp 测试
server操作相同。
1
2
3
4
$ iperf3 -s
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------
带宽性能压力测试通常采用udp模式,因为能测出极限带宽、时延抖动、丢包率等。使用udp时,需要指定client发送的速率,(tcp是默认是不限制,而udp默认是1 Mbit/sec),尝试出极限的不丢包速率,以及其他信息。
此处的局域网是千兆网,进行一下测试,以500M带宽和1000M带宽分别测试。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
$ iperf3 -c 192.168.100.2 -u -b 500M --get-server-output
Connecting to host 192.168.100.2, port 5201
[ 4] local 192.168.2.224 port 41401 connected to 192.168.100.2 port 5201
[ ID] Interval Transfer Bandwidth Total Datagrams
[ 4] 0.00-1.00 sec 59.2 MBytes 496 Mbits/sec 7572
[ 4] 1.00-2.00 sec 60.0 MBytes 504 Mbits/sec 7684
[ 4] 2.00-3.00 sec 59.2 MBytes 497 Mbits/sec 7576
[ 4] 3.00-4.00 sec 60.0 MBytes 503 Mbits/sec 7683
[ 4] 4.00-5.00 sec 58.8 MBytes 494 Mbits/sec 7532
[ 4] 5.00-6.00 sec 59.9 MBytes 503 Mbits/sec 7672
[ 4] 6.00-7.00 sec 60.0 MBytes 504 Mbits/sec 7684
[ 4] 7.00-8.00 sec 59.2 MBytes 496 Mbits/sec 7575
[ 4] 8.00-9.00 sec 60.0 MBytes 503 Mbits/sec 7681
[ 4] 9.00-10.00 sec 59.2 MBytes 497 Mbits/sec 7578
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams
[ 4] 0.00-10.00 sec 596 MBytes 500 Mbits/sec 0.069 ms 0/76229 (0%)
[ 4] Sent 76229 datagrams
Server output:
Accepted connection from 192.168.2.224, port 34300
[ 5] local 192.168.100.2 port 5201 connected to 192.168.2.224 port 41401
[ ID] Interval Transfer Bitrate Jitter Lost/Total Datagrams
[ 5] 0.00-1.00 sec 59.1 MBytes 495 Mbits/sec 0.104 ms 0/7559 (0%)
[ 5] 1.00-2.00 sec 60.1 MBytes 504 Mbits/sec 0.041 ms 0/7690 (0%)
[ 5] 2.00-3.00 sec 59.1 MBytes 496 Mbits/sec 0.075 ms 0/7570 (0%)
[ 5] 3.00-4.00 sec 60.1 MBytes 504 Mbits/sec 0.078 ms 0/7688 (0%)
[ 5] 4.00-5.00 sec 58.8 MBytes 493 Mbits/sec 0.081 ms 0/7528 (0%)
[ 5] 5.00-6.00 sec 59.9 MBytes 503 Mbits/sec 0.077 ms 0/7670 (0%)
[ 5] 6.00-7.00 sec 60.1 MBytes 504 Mbits/sec 0.078 ms 0/7693 (0%)
[ 5] 7.00-8.00 sec 59.1 MBytes 496 Mbits/sec 0.074 ms 0/7567 (0%)
[ 5] 8.00-9.00 sec 60.1 MBytes 504 Mbits/sec 0.064 ms 0/7691 (0%)
[ 5] 9.00-10.00 sec 59.1 MBytes 496 Mbits/sec 0.071 ms 0/7568 (0%)
[ 5] 10.00-10.00 sec 40.0 KBytes 853 Mbits/sec 0.069 ms 0/5 (0%)
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bitrate Jitter Lost/Total Datagrams
[ 5] 0.00-10.00 sec 596 MBytes 500 Mbits/sec 0.069 ms 0/76229 (0%) receiver
iperf Done.
$ iperf3 -c 192.168.100.2 -u -b 1000M --get-server-output
Connecting to host 192.168.100.2, port 5201
[ 4] local 192.168.2.224 port 56026 connected to 192.168.100.2 port 5201
[ ID] Interval Transfer Bandwidth Total Datagrams
[ 4] 0.00-1.00 sec 103 MBytes 863 Mbits/sec 13171
[ 4] 1.00-2.00 sec 114 MBytes 958 Mbits/sec 14624
[ 4] 2.00-3.00 sec 114 MBytes 958 Mbits/sec 14622
[ 4] 3.00-4.00 sec 114 MBytes 958 Mbits/sec 14624
[ 4] 4.00-5.00 sec 114 MBytes 958 Mbits/sec 14623
[ 4] 5.00-6.00 sec 114 MBytes 958 Mbits/sec 14624
[ 4] 6.00-7.00 sec 114 MBytes 958 Mbits/sec 14622
[ 4] 7.00-8.00 sec 114 MBytes 958 Mbits/sec 14624
[ 4] 8.00-9.00 sec 114 MBytes 958 Mbits/sec 14623
[ 4] 9.00-10.00 sec 114 MBytes 958 Mbits/sec 14622
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams
[ 4] 0.00-10.00 sec 1.10 GBytes 949 Mbits/sec 0.081 ms 853/144774 (0.59%)
[ 4] Sent 144774 datagrams
Server output:
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------
Accepted connection from 192.168.2.224, port 56196
[ 5] local 192.168.100.2 port 5201 connected to 192.168.2.224 port 56026
[ ID] Interval Transfer Bitrate Jitter Lost/Total Datagrams
[ 5] 0.00-1.00 sec 102 MBytes 854 Mbits/sec 0.077 ms 119/13157 (0.9%)
[ 5] 1.00-2.00 sec 114 MBytes 958 Mbits/sec 0.086 ms 7/14619 (0.048%)
[ 5] 2.00-3.00 sec 114 MBytes 955 Mbits/sec 0.083 ms 49/14620 (0.34%)
[ 5] 3.00-4.00 sec 114 MBytes 954 Mbits/sec 0.073 ms 58/14622 (0.4%)
[ 5] 4.00-5.00 sec 114 MBytes 955 Mbits/sec 0.087 ms 57/14624 (0.39%)
[ 5] 5.00-6.00 sec 114 MBytes 956 Mbits/sec 0.066 ms 40/14623 (0.27%)
[ 5] 6.00-7.00 sec 114 MBytes 954 Mbits/sec 0.079 ms 68/14622 (0.47%)
[ 5] 7.00-8.00 sec 114 MBytes 956 Mbits/sec 0.073 ms 32/14624 (0.22%)
[ 5] 8.00-9.00 sec 111 MBytes 933 Mbits/sec 0.053 ms 385/14623 (2.6%)
[ 5] 9.00-10.00 sec 114 MBytes 956 Mbits/sec 0.091 ms 38/14622 (0.26%)
[ 5] 10.00-10.00 sec 144 KBytes 1.04 Gbits/sec 0.081 ms 0/18 (0%)
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bitrate Jitter Lost/Total Datagrams
[ 5] 0.00-10.00 sec 1.10 GBytes 943 Mbits/sec 0.081 ms 853/144774 (0.59%) receiver
可以看到,以500M带宽测试时,没有丢包;而以1000M带宽测试时,出现了 0.59%的丢包,印证了局域网大约是1000M带宽。