iperf是一款进行网络性能测试的工具命令,由美国伊利诺斯大学研发和维护。可以用来测试一些网络设备如路由器,防火墙,交换机等的性能。
性能测试是在服务器已经启动服务的场景下进行的,服务器需先执行“iperf -s”或“iperf3 -s”命令。
语法格式:iperf [参数]
常用参数:
-l |
设置读写缓冲区的长度 |
-u |
使用UDP协议 |
-c |
进入客户端模式 |
-p |
设置端口,与服务器端的监听端口一致 |
-o |
重定向输出到指定文件 |
-b |
设置数据包大小(bits/sec) |
-t |
设置传输的总时间 |
-v |
显示版本信息和编译信息并退出 |
参考实例
客户端向服务器发起累计10秒、每秒数据包为100M的请求:
[root@linuxcool ~]# iperf -c 192.168.10.10 -b 100M -t 10
Connecting to host 192.168.10.10, port 5201
[ 5] local 192.168.10.10 port 44256 connected to 192.168.10.10 port 5201
[ ID] Interval Transfer Bitrate Retr Cwnd
[ 5] 0.00-1.00 sec 12.0 MBytes 101 Mbits/sec 0 639 KBytes
[ 5] 1.00-2.00 sec 11.9 MBytes 99.6 Mbits/sec 0 639 KBytes
[ 5] 2.00-3.00 sec 12.0 MBytes 101 Mbits/sec 0 639 KBytes
[ 5] 3.00-4.00 sec 11.9 MBytes 99.7 Mbits/sec 0 639 KBytes
[ 5] 4.00-5.00 sec 11.9 MBytes 99.6 Mbits/sec 0 639 KBytes
[ 5] 5.00-6.00 sec 12.0 MBytes 101 Mbits/sec 0 639 KBytes
[ 5] 6.00-7.00 sec 11.9 MBytes 99.6 Mbits/sec 0 639 KBytes
[ 5] 7.00-8.00 sec 11.9 MBytes 99.6 Mbits/sec 0 639 KBytes
[ 5] 8.00-9.00 sec 12.0 MBytes 101 Mbits/sec 0 639 KBytes
[ 5] 9.00-10.00 sec 11.9 MBytes 99.6 Mbits/sec 0 639 KBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bitrate Retr
[ 5] 0.00-10.00 sec 119 MBytes 100 Mbits/sec 0 sender
[ 5] 0.00-10.04 sec 119 MBytes 99.7 Mbits/sec receiver
iperf Done.
基于默认TCP协议,测试客户端到服务器的上传速度:
[root@linuxcool ~]# iperf -c 192.168.10.10 -t 10
Connecting to host 192.168.10.10, port 5201
[ 5] local 192.168.10.10 port 44326 connected to 192.168.10.10 port 5201
[ ID] Interval Transfer Bitrate Retr Cwnd
[ 5] 0.00-1.00 sec 1.50 GBytes 12.8 Gbits/sec 0 1.69 MBytes
[ 5] 1.00-2.00 sec 1.29 GBytes 11.1 Gbits/sec 0 2.12 MBytes
[ 5] 2.00-3.00 sec 1.34 GBytes 11.5 Gbits/sec 0 2.62 MBytes
[ 5] 3.00-4.00 sec 1.47 GBytes 12.7 Gbits/sec 0 3.18 MBytes
[ 5] 4.00-5.00 sec 1.45 GBytes 12.5 Gbits/sec 0 3.18 MBytes
[ 5] 5.00-6.00 sec 1.61 GBytes 13.9 Gbits/sec 0 3.18 MBytes
[ 5] 6.00-7.00 sec 1.54 GBytes 13.2 Gbits/sec 0 3.18 MBytes
[ 5] 7.00-8.00 sec 1.51 GBytes 13.0 Gbits/sec 0 3.18 MBytes
[ 5] 8.00-9.00 sec 1.66 GBytes 14.2 Gbits/sec 0 3.18 MBytes
[ 5] 9.00-10.00 sec 1.66 GBytes 14.2 Gbits/sec 0 3.18 MBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bitrate Retr
[ 5] 0.00-10.00 sec 15.0 GBytes 12.9 Gbits/sec 0 sender
[ 5] 0.00-10.03 sec 15.0 GBytes 12.9 Gbits/sec receiver
iperf Done.