【性能测试】iperf网卡性能测试测试工具

介绍

  • iperf3 githup仓库地址:https://github.com/esnet/iperf.git

  • iperf2 源码仓库地址:https://sourceforge.net/p/iperf2/code/ci/master/tree/

iperf2 和 iperf3 是两个独立维护的项目,由不同的团队维护,功能上有差异,最主要的差异是 iperf2 支持多线程,iperf3 不支持,因此 iperf2 对于网卡多队列的使用更友好。iperf3 3.16 版本开始支持多线程。

Benchmark子项

项目中主要测试 TCP 和 UDP 带宽。

安装

源码编译

步骤 1 联网下载iperf源码,或从浏览器下载后上传至服务器

wget https://github.com/esnet/iperf/archive/refs/tags/3.13.zip --no-check-certificate  
wget https://iperf.fr/download/source/iperf-2.0.9-source.tar.gz --no-check-certificate

步骤 2 解压并进入目录

# unzip  
# cd iperf-3.13

步骤 3 编译安装

# ./configure  
# make -j  
# make install

软件仓安装

yum install iperf3
apt install iperf3

以上安装以iperf3为例,iperf2的安装方法一样,iperf2的源码编译方法跟iperf3一样,参考iperf3的步骤替换对应的源码地址,源码包名称即可。

测试

命令选项介绍

  1. iperf2 命令格式 iperf [-s|-c host] [options] ,常用选项如下
iperf命令功能备注
-h,–help显示帮助信息
-s,–server设置为server模式
-p,–port指定监听或发送端口不指定默认是5001
-c,–client作为client端时,指定server
-i,–interval指定实时打印测试信息的时间如-i 1则一秒打印一次
-v,–version打印版本
-u,–udp测试UDP不指定-u时测试TCP
-t,–time在客户端使用是指定测试时间,以秒为单位

在服务端使用是指定监听时间,超时后没有收到客户端发来的报文就会退出程序;默认不设置,持续监听。
不指定为10s
-b,–bandwidth设置发送报文速率
-n,–num指定报文传输字节数,会取代-t选项
-P ,–parallel指定客户端运行的线程数iperf2 特有的功能,iperf3 无此功能。

多线程会使用网卡的多队列特性,结合绑核,绑中断可以提升性能,通常 25GE 及以上的高速网络需要用多线程测试才能达到理论值。

 

  1. iperf3 命令格式:iperf3 [-s|-c host] [options],常用选项如下
iperf3命令功能备注
-h,–help显示帮助信息
-s,–server设置为server模式
-D,–daemon以守护进程的方式运行服务端服务端参数
-p,–port指定监听或发送端口,默认端口5201
-c,–client作为client端时,指定server
-i,–interval指定实时打印测试信息的时间如-i 1则一秒打印一次,最大设置 60s 。
-v,–version打印版本
-V,–verbose输出更多详细信息
-d, --debug输出调试信息
-u,–udp测试UDP不指定-u时测试TCP
-t,–time指定测试时间,以秒为单位不指定为10s
-b,–bitrate指定发送报文的速率,0表示无限制

默认UDP限制为1 Mbit/sec,TCP无限制
客户端参数
-n,–bytes指定传输的字节数,取代-t参数
-k, --blockcount指定传输的报文数,取代-t和-n参数
-l, --length设置读写buffer的深度,TCP默认是128KB,
-P, --parallel设置发送的流数量注意和iperf2的区别,多条流并不能使用多队列,也不能使用多核,实际上还是单核,单队列测试。

因此在25GE以上高速网络测试时,iperf3需要起多个测试命令并行测试才能发挥网卡的多队列特性,达到最优测试性能。注意:iperf3 3.16版本开始支持多线程。

常用测试项命令

服务端运行服务

iperf -s -B <服务端网卡IP> 
iperf3 -s -B <服务端网卡IP>

服务端运行服务并指定端口为9001

iperf -s -p 9001  
iperf3 -s -p 9001

客户端执行TCP带宽测试

iperf -c xx.xx.xx.xx  
iperf3 -c *xx.xx.xx.xx*

客户端执行TCP带宽测试,指定端口为9001

iperf -c xx.xx.xx.xx -p 9001  
iperf3 -c *xx.xx.xx.xx* -p 9001

客户端执行60s UDP带宽测试,并指定发包速率为1Gbit/sec

iperf -c xx.xx.xx.xx -t 60 -u -b 1G  
iperf3 -c xx.xx.xx.xx -t 60 -u -b 1G

客户端执行 TCP 带宽测试,使用 4 个线程

# iperf -c xx.xx.xx.xx -P 4

客户端执行 TCP 带宽测试,发送 4 条流

# iperf3 -c xx.xx.xx.xx -P 4

调优

硬件调优

BIOS调优

OS 调优

CPU governor

Linux CPU governor (P-States) 设置的影响很大。performance 和 powersave 对比,提升明显。

#For RHEL
cpupower frequency-set -g performance
#For Debian
cpufreq-set -r -g performance
#Check
cpupower frequency-info
CPU frequency
  • Driver: Kernel module or code that makes CPU frequency calls to hardware

  • Governor: Driver se ng that determines how the frequency will be set

  • Performance Governor: Bias towards higher frequencies

  • Userspace Governor: Allow user to specify exact core and package frequencies

  • Only the Intel P-States Driver can make use of Turbo Boost

  • Check current se ngs: cpupower frequency-info

内核协议栈调优

TCP调优

针对不同带宽网卡

对于具有 10G NIC 的主机,针对高达 100 毫秒 RTT 的网络路径进行了优化,并且对单流和并行流工具具有友好性,请将其添加到 /etc/sysctl.conf:

# allow TCP with buffers up to 64MB 
net.core.rmem_max = 67108864 
net.core.wmem_max = 67108864 
# increase Linux autotuning TCP buffer limit to 32MB
net.ipv4.tcp_rmem = 4096 87380 33554432
net.ipv4.tcp_wmem = 4096 65536 33554432
# recommended for hosts with jumbo frames enabled
net.ipv4.tcp_mtu_probing=1
# recommended to use a 'fair queueing' qdisc (either fq or fq_codel)
net.core.default_qdisc = fq

对于具有 10G 网卡的主机,该网卡针对高达 200 毫秒 RTT 的网络路径进行了优化,并且对单流和并行流工具具有友好性,或者对于在高达 50 毫秒 RTT 的路径上优化了 40G 网卡:

# allow TCP with buffers up to 128MB
net.core.rmem_max = 134217728 
net.core.wmem_max = 134217728 
# increase TCP autotuning buffer limits.
net.ipv4.tcp_rmem = 4096 87380 67108864
net.ipv4.tcp_wmem = 4096 65536 67108864
# recommended for hosts with jumbo frames enabled
net.ipv4.tcp_mtu_probing=1
# recommended to enable 'fair queueing'
net.core.default_qdisc = fq

对于具有针对高达 200 毫秒 RTT 的网络路径优化的 100G NIC 的主机,请使用以下配置:

# allow TCP with buffers up to 2GB (Max allowed in Linux is 2GB-1)
net.core.rmem_max=2147483647
net.core.wmem_max=2147483647
# increase TCP autotuning buffer limits. For 100G, it helps to increase default buffer too.
net.ipv4.tcp_rmem=4096 67108864 1073741824 
net.ipv4.tcp_wmem=4096 67108864 1073741824
# recommended for hosts with jumbo frames enabled
net.ipv4.tcp_mtu_probing=1
# recommended to enable 'fair queueing'
net.core.default_qdisc = fq

UDP调优

如果不进行一些调整,UDP 将无法获得完整的 10Gbps(或更高)。重要因素是:

  • 使用巨型帧 jumbo frames:使用 9K MTU 的性能将提高 4-5 倍
  • 数据包大小:最佳性能是 MTU 大小减去数据包标头大小。例如,对于 9000 字节的 MTU,将 8972 用于 IPV4,将 8952 用于 IPV6。
  • socket buffer size:对于 UDP,缓冲区大小与 RTT 的关系不像 TCP 那样,但默认值仍然不够大。在大多数情况下,将套接字缓冲区设置为 4M 似乎有很大帮助
  • core selection:10G 的 UDP 通常受到 CPU 限制,因此选择正确的核心非常重要。在 Sandy/Ivy Bridge 主板上尤其如此。

示例:

iperf3 -s -B <服务端IP> -u
taskset -c <CPU核心> numactl -N <NUMA节点> iperf3 -c <服务端IP> -B <被测网卡IP> -u -l 8972 -b4M
taskset -c <CPU核心> numactl -N  <NUMA节点> iperf3 -c <服务端IPv6> -B <被测网卡IPv6> -u -l 8952 -b4M -6

参考资料:
iperf3 at 40Gbps and above (es.net)

测试/测量主机调优 (es.net)

40G/100G网络调优 (es.net)

100G-Tuning-TechEx2016.tierney.pdf (es.net)

  • 24
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值