安装
yum install iperf
iperf 架构
iperf 分为客户端和服务端. 服务端开启后, 就可以进行通信了.
应用
带宽测试
带宽测试通常采用UDP模式,因为能测出极限带宽、时延抖动、丢包率。在进行测试时,首先以链路理论带宽作为数据发送速率进行测试,例如,从客户端到服务器之间的链路的理论带宽为100Mbps,先用-b 100M
进行测试,然后根据测试结果(包括实际带宽,时延抖动和丢包率),再以实际带宽作为数据发送速率进行测试,会发现时延抖动和丢包率比第一次好很多,重复测试几次,就能得出稳定的实际带宽。
UDP模式
服务器端:
// -u udp 模式
// -s 开启服务端
iperf -u -s
输出:
[ 4] local 127.0.0.1 port 5001 connected with 127.0.0.1 port 59773
[ 4] 0.0-20.0 sec 2.50 MBytes 1.05 Mbits/sec 0.002 ms 0/ 1784 (0%)
客户端:
在udp模式下,以100Mbps为数据发送速率,客户端到服务器192.168.1.1上传带宽测试,测试时间为60秒。
iperf -u -c 192.168.1.1 -b 100M -t 60
iperf -u -c 192.168.1.1 -b 5M -P 30 -t 60
客户端同时向服务器端发起30个连接线程,以5Mbps为数据发送速率。
iperf -u -c 192.168.1.1 -b 100M -d -t 60
以100M为数据发送速率,进行上下行带宽测试。
输出:
# iperf -u -c 127.0.0.1 -b 1M -t 20
------------------------------------------------------------
Client connecting to 127.0.0.1, UDP port 5001
Sending 1470 byte datagrams, IPG target: 11215.21 us (kalman adjust)
UDP buffer size: 208 KByte (default)
------------------------------------------------------------
[ 3] local 127.0.0.1 port 59773 connected with 127.0.0.1 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-20.0 sec 2.50 MBytes 1.05 Mbits/sec
[ 3] Sent 1784 datagrams
[ 3] Server Report:
[ 3] 0.0-20.0 sec 2.50 MBytes 1.05 Mbits/sec 0.002 ms 0/ 1784 (0%)
TCP模式
服务器端:
iperf -s
客户端:
iperf -c 192.168.1.1 -t 60
在tcp模式下,客户端到服务器192.168.1.1上传带宽测试,测试时间为60秒。
iperf -c 192.168.1.1 -P 30 -t 60
客户端同时向服务器端发起30个连接线程。
iperf -c 192.168.1.1 -d -t 60
进行上下行带宽测试。
linux iperf 网络性能测试
iperf可以测试TCP和UDP带宽质量。iperf可以测量最大TCP带宽,具有多种参数和UDP特性。iperf可以报告带宽,延迟抖动和数据包丢失。
TCP(Transimission Control Protocol ,传输控制协议)是基于连接的协议,也就是说,在正式收发数据前,必须和对方建立可靠的连接,一个TCP
连接必须要经过三次的“对话”才能建立起来
UDP(User Data Protocol,用户数据报协议)是与TCP相对应的协议。他是面向非连接的协议。它不与对方建立连接,而是直接就把数据包发送过去。
udp模式
服务器端:
iperf -u -s
客户端:
iperf -u -c 192.168.1.1 -b 100M -t 60
在udp模式下,以100Mbps为数据发送速率,客户端到服务器192.168.1.1上传带宽测试,测试时间为60秒
iperf -u -c 192.168.1.1 -b 5M -P 30 -t 60
客户端同时向服务器端发起30个连接线程,已5Mbps为数据发送速率
TCP模式
服务端:
iperf -s
客户端:
iperf -c 192.168.1.1 -t 60
在tcp 模式下,客户端到服务器192.168.1.1上传带宽测试,测试时间为60秒
iperf -c 192.168.1.1 -d -t 60
进行上下行带宽测试
服务器端:
iperf -s -p 12345 -i 1 -M 以在本机端口12345上启用iperf
1. iperf: option requires an argument -- M
2. ------------------------------------------------------------
3. Server listening on TCP port 12345
4. TCP window size: 85.3 KByte (default)
5. ------------------------------------------------------------
在客户端,输入命令:
iperf -c 192.167.xxx.xxx -p 12345 -i 1 -t 10 -w 20K 其中参数说明如下
-c 客户端模式,后接服务器ip,
-p 后接服务端监听的端口
-i 设置带宽报告的时间间隔,单位为秒
-t 设置测试的时长,单位为秒
-w 设置tcp窗口大小,一般可以不用设置,默认即可
客户端测试后结果如下:
1. Last login: Thu May 29 21:58:49 2104 from 192.167.253.95
2. -bash-4.1# iperf -c 192.167.xxx.xxx -p 12345 -i 1 -t 10 -w 20K
3. ------------------------------------------------------------
4. Client connecting to 192.167.xxx.xxx, TCP port 12345
5. TCP window size: 40.0 KByte (WARNING: requested 20.0 KByte)
6. ------------------------------------------------------------
7. [ 3] local 192.167.xxx.xxx port 39803 connected with 192.167.xxx.xxx port 12345
8. [ 3] 0.0- 1.0 sec 89.2 MBytes 749 Mbits/sec
9. [ 3] 1.0- 2.0 sec 91.5 MBytes 768 Mbits/sec
10. [ 3] 2.0- 3.0 sec 89.1 MBytes 748 Mbits/sec
11. [ 3] 3.0- 4.0 sec 89.8 MBytes 754 Mbits/sec
12. [ 3] 4.0- 5.0 sec 89.0 MBytes 746 Mbits/sec
13. [ 3] 5.0- 6.0 sec 91.4 MBytes 767 Mbits/sec
14. [ 3] 6.0- 7.0 sec 89.0 MBytes 746 Mbits/sec
15. [ 3] 7.0- 8.0 sec 90.6 MBytes 760 Mbits/sec
16. [ 3] 8.0- 9.0 sec 89.7 MBytes 753 Mbits/sec
17. [ 3] 0.0-10.0 sec 899 MBytes 754 Mbits/sec
服务器端结果:
1. wxsc@ubuntu:~$ iperf -s -p 12345 -i 1 -M
2. iperf: option requires an argument -- M
3. ------------------------------------------------------------
4. Server listening on TCP port 12345
5. TCP window size: 85.3 KByte (default)
6. ------------------------------------------------------------
7. [ 4] local 192.167.xxx.xxx port 12345 connected with 192.167.xxx.xxx port 39803
8. [ 4] 0.0- 1.0 sec 89.2 MBytes 748 Mbits/sec
9. [ 4] 1.0- 2.0 sec 91.5 MBytes 768 Mbits/sec
10. [ 4] 2.0- 3.0 sec 89.2 MBytes 748 Mbits/sec
11. [ 4] 3.0- 4.0 sec 89.8 MBytes 753 Mbits/sec
12. [ 4] 4.0- 5.0 sec 88.9 MBytes 746 Mbits/sec
13. [ 4] 5.0- 6.0 sec 91.4 MBytes 767 Mbits/sec
14. [ 4] 6.0- 7.0 sec 88.9 MBytes 746 Mbits/sec
15. [ 4] 7.0- 8.0 sec 90.6 MBytes 760 Mbits/sec
16. [ 4] 8.0- 9.0 sec 89.8 MBytes 753 Mbits/sec
17. [ 4] 9.0-10.0 sec 89.6 MBytes 752 Mbits/sec
18. [ 4] 0.0-10.0 sec 899 MBytes 754 Mbits/sec
其中:Interval 表示时间间隔,Transfer表示时间间隔里面传输的数据量,Bandwidth是时间间隔里的传输速率,最后一行是本次测试的统计,测试可知带宽平均在89.9Mbit/s
1测试多线程TCP
在客户端添加-P 参数即可测试多线程的TCP性能,如下为使用两个线程的测试情况
1. -bash-4.1# iperf -c 192.167.xxx.xxx -p12345 -i 1 -t 3 -P 2
2. ------------------------------------------------------------
3. Client connecting to 192.167.xxx.xxx, TCP port 12345
4. TCP window size: 48.6 KByte (default)
5. ------------------------------------------------------------
6. [ 3] local 192.167.xxx.xxx port 39805 connected with 192.167.xxx.xxx port 12345
7. [ 4] local 192.167.xxx.xxx port 39806 connected with 192.167.xxx.xxx port 12345
8. [ 3] 0.0- 1.0 sec 56.0 MBytes 470 Mbits/sec
9. [ 4] 0.0- 1.0 sec 56.2 MBytes 472 Mbits/sec
10. [SUM] 0.0- 1.0 sec 112 MBytes 942 Mbits/sec
11. [ 3] 1.0- 2.0 sec 55.7 MBytes 467 Mbits/sec
12. [ 4] 1.0- 2.0 sec 55.7 MBytes 467 Mbits/sec
13. [SUM] 1.0- 2.0 sec 111 MBytes 934 Mbits/sec
14. [ 3] 2.0- 3.0 sec 55.1 MBytes 462 Mbits/sec
15. [ 3] 0.0- 3.0 sec 167 MBytes 466 Mbits/sec
16. [ 4] 2.0- 3.0 sec 56.1 MBytes 471 Mbits/sec
17. [SUM] 2.0- 3.0 sec 111 MBytes 933 Mbits/sec
18. [ 4] 0.0- 3.0 sec 168 MBytes 469 Mbits/sec
19. [SUM] 0.0- 3.0 sec 335 MBytes 935 Mbits/sec
服务器端输出:
1. [ 4] local 192.167.xxx.xxx port 12345 connected with 192.167.xxx.xxx port 39805
2. [ 5] local 192.167.xxx.xxx port 12345 connected with 192.167.xxx.xxx port 39806
3. [ 4] 0.0- 1.0 sec 55.5 MBytes 465 Mbits/sec
4. [ 5] 0.0- 1.0 sec 55.4 MBytes 465 Mbits/sec
5. [SUM] 0.0- 1.0 sec 111 MBytes 930 Mbits/sec
6. [ 4] 1.0- 2.0 sec 55.7 MBytes 467 Mbits/sec
7. [ 5] 1.0- 2.0 sec 55.7 MBytes 468 Mbits/sec
8. [SUM] 1.0- 2.0 sec 111 MBytes 935 Mbits/sec
9. [ 4] 2.0- 3.0 sec 55.1 MBytes 462 Mbits/sec
10. [ 5] 2.0- 3.0 sec 56.1 MBytes 470 Mbits/sec
11. [SUM] 2.0- 3.0 sec 111 MBytes 932 Mbits/sec
12. [ 4] 0.0- 3.0 sec 167 MBytes 465 Mbits/sec
13. [ 5] 0.0- 3.0 sec 168 MBytes 468 Mbits/sec
14. [SUM] 0.0- 3.0 sec 335 MBytes 932 Mbits/sec
2测试单线程UDP(默认带宽)
在服务器端运行iperf,输入命令iperf –s -u –p 12345 –i 1 以在本机端口12345上启用iperf,并运行与udp模式
在客户端运行iperf,输入命令iperf -c server-ip -p server-port -i 1 -t 10 -b 其中参数说明如下:
-b :设置udp 的发送带宽,单位bit/s
客户端输出:
1. -bash-4.1# iperf -c 192.167.xxx.xxx -p12345 -i 1 -t 10 -u -b
2. iperf: option requires an argument -- b
3. ------------------------------------------------------------
4. Client connecting to 192.167.xxx.xxx, UDP port 12345
5. Sending 1470 byte datagrams
6. UDP buffer size: 224 KByte (default)
7. ------------------------------------------------------------
8. [ 3] local 192.167.xxx.xxx port 36125 connected with 192.167.xxx.xxx port 12345
9. [ 3] 0.0- 1.0 sec 129 KBytes 1.06 Mbits/sec
10. [ 3] 1.0- 2.0 sec 128 KBytes 1.05 Mbits/sec
11. [ 3] 2.0- 3.0 sec 128 KBytes 1.05 Mbits/sec
12. [ 3] 3.0- 4.0 sec 128 KBytes 1.05 Mbits/sec
13. [ 3] 4.0- 5.0 sec 128 KBytes 1.05 Mbits/sec
14. [ 3] 5.0- 6.0 sec 128 KBytes 1.05 Mbits/sec
15. [ 3] 6.0- 7.0 sec 129 KBytes 1.06 Mbits/sec
16. [ 3] 7.0- 8.0 sec 128 KBytes 1.05 Mbits/sec
17. [ 3] 8.0- 9.0 sec 128 KBytes 1.05 Mbits/sec
18. [ 3] 9.0-10.0 sec 128 KBytes 1.05 Mbits/sec
19. [ 3] 0.0-10.0 sec 1.25 MBytes 1.05 Mbits/sec
20. [ 3] Sent 893 datagrams
21. [ 3] Server Report:
22. [ 3] 0.0-10.0 sec 1.25 MBytes 1.05 Mbits/sec 0.009 ms 0/ 893 (0%)
服务器端输出:
1. wxsc@ubuntu:~$ iperf -s -p12345 -m -i 1 -u
2. ------------------------------------------------------------
3. Server listening on UDP port 12345
4. Receiving 1470 byte datagrams
5. UDP buffer size: 208 KByte (default)
6. ------------------------------------------------------------
7. [ 3] local 192.167.xxx.xxx port 12345 connected with 192.167.xxx.xxx port 36125
8. [ 3] 0.0- 1.0 sec 128 KBytes 1.05 Mbits/sec 0.016 ms 0/ 89 (0%)
9. [ 3] 1.0- 2.0 sec 128 KBytes 1.05 Mbits/sec 0.219 ms 0/ 89 (0%)
10. [ 3] 2.0- 3.0 sec 128 KBytes 1.05 Mbits/sec 0.016 ms 0/ 89 (0%)
11. [ 3] 3.0- 4.0 sec 128 KBytes 1.05 Mbits/sec 0.018 ms 0/ 89 (0%)
12. [ 3] 4.0- 5.0 sec 128 KBytes 1.05 Mbits/sec 0.021 ms 0/ 89 (0%)
13. [ 3] 5.0- 6.0 sec 129 KBytes 1.06 Mbits/sec 0.451 ms 0/ 90 (0%)
14. [ 3] 6.0- 7.0 sec 128 KBytes 1.05 Mbits/sec 0.013 ms 0/ 89 (0%)
15. [ 3] 7.0- 8.0 sec 128 KBytes 1.05 Mbits/sec 0.020 ms 0/ 89 (0%)
16. [ 3] 8.0- 9.0 sec 128 KBytes 1.05 Mbits/sec 0.011 ms 0/ 89 (0%)
17. [ 3] 9.0-10.0 sec 128 KBytes 1.05 Mbits/sec 0.008 ms 0/ 89 (0%)
18. [ 3] 0.0-10.0 sec 1.25 MBytes 1.05 Mbits/sec 0.009 ms 0/ 893 (0%)
其中Jitter为抖动,lost/total为丢包数量,Datagrams 为包数量
测试单线程UDP(带宽为10Mbit/s)
设置客户端带宽为10M即可,使用参数-b 指定
客户端输出:
1. -bash-4.1# iperf -c 192.167.xxx.xxx -p12345 -i 1 -t 10 -u -b 10M
2. ------------------------------------------------------------
3. Client connecting to 192.167.xxx.xxx, UDP port 12345
4. Sending 1470 byte datagrams
5. UDP buffer size: 224 KByte (default)
6. ------------------------------------------------------------
7. [ 3] local 192.167.xxx.xxx port 57147 connected with 192.167.xxx.xxx port 12345
8. [ 3] 0.0- 1.0 sec 1.19 MBytes 10.0 Mbits/sec
9. [ 3] 1.0- 2.0 sec 1.19 MBytes 10.0 Mbits/sec
10. [ 3] 2.0- 3.0 sec 1.19 MBytes 10.0 Mbits/sec
11. [ 3] 3.0- 4.0 sec 1.19 MBytes 10.0 Mbits/sec
12. [ 3] 4.0- 5.0 sec 1.19 MBytes 10.0 Mbits/sec
13. [ 3] 5.0- 6.0 sec 1.19 MBytes 10.0 Mbits/sec
14. [ 3] 6.0- 7.0 sec 1.19 MBytes 10.0 Mbits/sec
15. [ 3] 7.0- 8.0 sec 1.19 MBytes 10.0 Mbits/sec
16. [ 3] 8.0- 9.0 sec 1.19 MBytes 10.0 Mbits/sec
17. [ 3] 9.0-10.0 sec 1.19 MBytes 10.0 Mbits/sec
18. [ 3] 0.0-10.0 sec 11.9 MBytes 10.0 Mbits/sec
19. [ 3] Sent 8505 datagrams
20. [ 3] Server Report:
21. [ 3] 0.0-10.0 sec 11.9 MBytes 10.0 Mbits/sec 0.007 ms 0/ 8504 (0%)
22. [ 3] 0.0-10.0 sec 1 datagrams received out-of-order
服务器端输出:
1.
2. [ 4] local 192.167.xxx.xxx port 12345 connected with 192.167.xxx.xxx port 57147
3. [ 4] 0.0- 1.0 sec 1.19 MBytes 10.0 Mbits/sec 0.026 ms 0/ 850 (0%)
4. [ 4] 1.0- 2.0 sec 1.19 MBytes 10.0 Mbits/sec 0.005 ms 0/ 851 (0%)
5. [ 4] 2.0- 3.0 sec 1.19 MBytes 10.0 Mbits/sec 0.056 ms 0/ 850 (0%)
6. [ 4] 3.0- 4.0 sec 1.19 MBytes 10.0 Mbits/sec 0.006 ms 0/ 850 (0%)
7. [ 4] 4.0- 5.0 sec 1.19 MBytes 10.0 Mbits/sec 0.010 ms 0/ 850 (0%)
8. [ 4] 5.0- 6.0 sec 1.19 MBytes 10.0 Mbits/sec 0.010 ms 0/ 851 (0%)
9. [ 4] 6.0- 7.0 sec 1.19 MBytes 10.0 Mbits/sec 0.048 ms 0/ 850 (0%)
10. [ 4] 7.0- 8.0 sec 1.19 MBytes 10.0 Mbits/sec 0.007 ms 0/ 850 (0%)
11. [ 4] 8.0- 9.0 sec 1.19 MBytes 10.0 Mbits/sec 0.078 ms 0/ 851 (0%)
12. [ 4] 9.0-10.0 sec 1.19 MBytes 10.0 Mbits/sec 0.008 ms 0/ 850 (0%)
13. [ 4] 0.0-10.0 sec 11.9 MBytes 10.0 Mbits/sec 0.007 ms 0/ 8504 (0%)
14. [ 4] 0.0-10.0 sec 1 datagrams received out-of-order
测试UDP的双向传输
客户端使用参数-d 以运行双测试模式,客户端会与服务端进行UDP往返测试完。可以使用-L 参数指定本端双测试监听的端口
1. -bash-4.1# iperf -c 192.167.xxx.xxx -p12345 -i 1 -t 5 -u -b 10M -d -L 30000
2. ------------------------------------------------------------
3. Server listening on UDP port 30000
4. Receiving 1470 byte datagrams
5. UDP buffer size: 224 KByte (default)
6. ------------------------------------------------------------
7. ------------------------------------------------------------
8. Client connecting to 192.167.xxx.xxx, UDP port 12345
9. Sending 1470 byte datagrams
10. UDP buffer size: 224 KByte (default)
11. ------------------------------------------------------------
12. [ 4] local 192.167.xxx.xxx port 45123 connected with 192.167.xxx.xxx port 12345
13. [ 3] local 192.167.xxx.xxx port 30000 connected with 192.167.xxx.xxx port 38182
14. [ 4] 0.0- 1.0 sec 1.19 MBytes 10.0 Mbits/sec
15. [ 3] 0.0- 1.0 sec 1.19 MBytes 10.0 Mbits/sec 0.017 ms 0/ 850 (0%)
16. [ 4] 1.0- 2.0 sec 1.19 MBytes 10.0 Mbits/sec
17. [ 3] 1.0- 2.0 sec 1.19 MBytes 10.0 Mbits/sec 0.018 ms 0/ 851 (0%)
18. [ 4] 2.0- 3.0 sec 1.19 MBytes 10.0 Mbits/sec
19. [ 3] 2.0- 3.0 sec 1.19 MBytes 10.0 Mbits/sec 0.016 ms 0/ 850 (0%)
20. [ 4] 3.0- 4.0 sec 1.19 MBytes 10.0 Mbits/sec
21. [ 3] 3.0- 4.0 sec 1.19 MBytes 10.0 Mbits/sec 0.016 ms 0/ 850 (0%)
22. [ 4] 4.0- 5.0 sec 1.19 MBytes 10.0 Mbits/sec
23. [ 4] 0.0- 5.0 sec 5.96 MBytes 10.0 Mbits/sec
24. [ 4] Sent 4253 datagrams
25. [ 3] 4.0- 5.0 sec 1.19 MBytes 10.0 Mbits/sec 0.017 ms 0/ 851 (0%)
26. [ 3] 0.0- 5.0 sec 5.96 MBytes 10.0 Mbits/sec 0.016 ms 0/ 4253 (0%)
27. [ 4] Server Report:
28. [ 4] 0.0- 5.0 sec 5.96 MBytes 10.0 Mbits/sec 0.002 ms 0/ 4252 (0%)
29. [ 4] 0.0- 5.0 sec 1 datagrams received out-of-order
服务端输出:
1. ------------------------------------------------------------
2. Client connecting to 192.167.xxx.xxx, UDP port 30000
3. Sending 1470 byte datagrams
4. UDP buffer size: 208 KByte (default)
5. ------------------------------------------------------------
6. [ 5] local 192.167.xxx.xxx port 38182 connected with 192.167.xxx.xxx port 30000
7. [ 3] local 192.167.xxx.xxx port 12345 connected with 192.167.xxx.xxx port 45123
8. [ 5] 0.0- 1.0 sec 1.19 MBytes 10.0 Mbits/sec
9. [ 3] 0.0- 1.0 sec 1.20 MBytes 10.0 Mbits/sec 0.011 ms 0/ 853 (0%)
10. [ 5] 1.0- 2.0 sec 1.19 MBytes 10.0 Mbits/sec
11. [ 3] 1.0- 2.0 sec 1.19 MBytes 10.0 Mbits/sec 0.414 ms 0/ 851 (0%)
12. [ 5] 2.0- 3.0 sec 1.19 MBytes 10.0 Mbits/sec
13. [ 3] 2.0- 3.0 sec 1.19 MBytes 10.0 Mbits/sec 0.005 ms 0/ 850 (0%)
14. [ 5] 3.0- 4.0 sec 1.19 MBytes 10.0 Mbits/sec
15. [ 3] 3.0- 4.0 sec 1.19 MBytes 10.0 Mbits/sec 0.713 ms 0/ 850 (0%)
16. [ 5] 4.0- 5.0 sec 1.19 MBytes 10.0 Mbits/sec
17. [ 3] 0.0- 5.0 sec 5.96 MBytes 10.0 Mbits/sec 0.003 ms 0/ 4252 (0%)
18. [ 3] 0.0- 5.0 sec 1 datagrams received out-of-order
19. [ 5] 0.0- 5.0 sec 5.96 MBytes 10.0 Mbits/sec
20. [ 5] Sent 4253 datagrams
21. [ 5] Server Report:
22. [ 5] 0.0- 5.0 sec 5.96 MBytes 10.0 Mbits/sec 0.016 ms 0/ 4253 (0%)