9.5. 高性能配置

9.5.1. NIC

Suricata性能的主要依赖之一是网络接口卡。供应商有很多可能性。一些NIC具有并需要自己的特定说明和工具来设置NIC。这确保了在运行Suricata时最大的好处。Napatech、Netronome、accorade和Myricom等供应商将这些工具和文档作为其来源的一部分。

对于Intel、Mellanox和商品NIC,可以使用以下建议。

建议使用最新可用的稳定NIC驱动程序。通常,在更改NIC设置时,建议使用最新的 ethtool 版本。有些网卡有自己的 ethtool 建议使用。以下是如何在需要时设置ethtool的示例:

wget https://mirrors.edge.kernel.org/pub/software/network/ethtool/ethtool-5.2.tar.xz
tar -xf ethtool-5.2.tar.xz
cd ethtool-5.2
./configure && make clean && make && make install
/usr/local/sbin/ethtool --version

进行高性能优化时,请确保 irqbalance 关闭且未运行:

service irqbalance stop

根据NIC的可用队列(例如Intel的x710/i40每个端口/接口有64个可用),可以相应地设置工作线程。通常可以通过运行以下命令查看可用队列:

/usr/local/sbin/ethtool -l eth1

某些NIC(通常为低端1Gbps)不支持对称哈希请参阅 数据包捕获 . 在这些系统上,出于对无序分组的考虑,建议使用af分组进行以下设置(下面的示例使用 eth1 ):

/usr/local/sbin/ethtool -L eth1 combined 1

然后用所需的工作线程数设置af包 threads: auto (默认情况下自动将使用可用的CPU数量)和 cluster-type: cluster_flow (也是默认设置)

对于高端系统/NIC,更好、更高性能的解决方案可以更多地利用NIC本身。x710/i40和类似的Intel NIC或Mellanox MT27800系列 [ConnectX-5] 例如,可以很容易地设置为使用更多的RSS队列和对称散列来完成更大的工作块,以便通过使用af packet和 cluster-type: cluster_qm 模式。在这种模式下,af包通过网卡链接到RSS队列的所有数据包都被发送到同一个套接字。下面是基于使用x710的16核单CPU/NUMA节点套接字系统的建议配置设置示例:

rmmod i40e && modprobe i40e
ifconfig eth1 down
/usr/local/sbin/ethtool -L eth1 combined 16
/usr/local/sbin/ethtool -K eth1 rxhash on
/usr/local/sbin/ethtool -K eth1 ntuple on
ifconfig eth1 up
/usr/local/sbin/ethtool -X eth1 hkey 6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A equal 16
/usr/local/sbin/ethtool -A eth1 rx off
/usr/local/sbin/ethtool -C eth1 adaptive-rx off adaptive-tx off rx-usecs 125
/usr/local/sbin/ethtool -G eth1 rx 1024

可以在的帮助或手册页中详细查看上述命令 ethtool . 简言之,该序列确保NIC已重置,RSS队列的数量设置为16,NIC的负载平衡已启用,插入低熵toepiltz密钥以允许对称哈希,禁用接收卸载,禁用自适应控制以尽可能降低延迟,最后但并非最不重要,环接收描述符大小设置为1024。确保RSS哈希函数为Toeplitz:

/usr/local/sbin/ethtool -X eth1 hfunc toeplitz

尽可能让NIC保持平衡:

for proto in tcp4 udp4 tcp6 udp6; do
   /usr/local/sbin/ethtool -N eth1 rx-flow-hash $proto sdfn
done

在某些情况下:

/usr/local/sbin/ethtool -N eth1 rx-flow-hash $proto sd

可能足够了,甚至更好,取决于交通类型。然而,并不是所有的网卡都允许这样做。这个 sd 指定NIC的多队列哈希算法(针对特定的协议)以仅使用src IP、dst IP。这个 sdfn 允许将元组src IP、dst IP、src port、dst port用于哈希算法。在苏瑞塔亚姆:

af-packet:
 - interface: eth1
   threads: 16
   cluster-id: 99
   cluster-type: cluster_qm
   ...
   ...

9.5.2. CPU亲和力和NUMA

9.5.2.1. 基于Intel的系统

如果系统有多个NUMA节点,则有更多的可能性。在这些情况下,通常建议使用尽可能多的工作线程(cpu核心可用/可能多),来自同一个NUMA节点。下面的示例使用一台72核机器和Suricata使用的位于NUMA节点1上的嗅探NIC。在这种2个套接字配置中,建议将Suricata和嗅探NIC运行并驻留在第二个NUMA节点上,因为默认情况下,Linux中的许多服务广泛使用CPU 0。在不可能的情况下,建议(通过苏瑞塔亚姆并且NIC)CPU 0的irq关联脚本从未使用过。

在以下情况下,36个工作线程在NUMA节点1的CPU外使用,af包运行模式 cluster-type: cluster_qm .

如果CPU的NUMA设置如下:

lscpu
Architecture:        x86_64
CPU op-mode(s):      32-bit, 64-bit
Byte Order:          Little Endian
CPU(s):              72
On-line CPU(s) list: 0-71
Thread(s) per core:  2
Core(s) per socket:  18
Socket(s):           2
NUMA node(s):        2
Vendor ID:           GenuineIntel
CPU family:          6
Model:               79
Model name:          Intel(R) Xeon(R) CPU E5-2697 v4 @ 2.30GHz
Stepping:            1
CPU MHz:             1199.724
CPU max MHz:         3600.0000
CPU min MHz:         1200.0000
BogoMIPS:            4589.92
Virtualization:      VT-x
L1d cache:           32K
L1i cache:           32K
L2 cache:            256K
L3 cache:            46080K
NUMA node0 CPU(s):   0-17,36-53
NUMA node1 CPU(s):   18-35,54-71

建议使用36个工作线程,NIC设置如下:

rmmod i40e && modprobe i40e
ifconfig eth1 down
/usr/local/sbin/ethtool -L eth1 combined 36
/usr/local/sbin/ethtool -K eth1 rxhash on
/usr/local/sbin/ethtool -K eth1 ntuple on
ifconfig eth1 up
./set_irq_affinity local eth1
/usr/local/sbin/ethtool -X eth1 hkey 6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A equal 36
/usr/local/sbin/ethtool -A eth1 rx off tx off
/usr/local/sbin/ethtool -C eth1 adaptive-rx off adaptive-tx off rx-usecs 125
/usr/local/sbin/ethtool -G eth1 rx 1024
for proto in tcp4 udp4 tcp6 udp6; do
    echo "/usr/local/sbin/ethtool -N eth1 rx-flow-hash $proto sdfn"
    /usr/local/sbin/ethtool -N eth1 rx-flow-hash $proto sdfn
done

在上面的示例中, set_irq_affinity 脚本是从NIC驱动程序的源代码中使用的。在苏瑞塔亚姆配置:

# Suricata is multi-threaded. Here the threading can be influenced.
threading:
 cpu-affinity:
   - management-cpu-set:
       cpu: [ "1-10" ]  # include only these CPUs in affinity settings
   - receive-cpu-set:
       cpu: [ "0-10" ]  # include only these CPUs in affinity settings
   - worker-cpu-set:
       cpu: [ "18-35", "54-71" ]
       mode: "exclusive"
       prio:
         low: [ 0 ]
         medium: [ "1" ]
         high: [ "18-35","54-71" ]
         default: "high"

在苏瑞塔亚姆配置:

- interface: eth1
  # Number of receive threads. "auto" uses the number of cores
  threads: 18
  cluster-id: 99
  cluster-type: cluster_qm
  defrag: no
  use-mmap: yes
  mmap-locked: yes
  tpacket-v3: yes
  ring-size: 100000
  block-size: 1048576
- interface: eth1
  # Number of receive threads. "auto" uses the number of cores
  threads: 18
  cluster-id: 99
  cluster-type: cluster_qm
  defrag: no
  use-mmap: yes
  mmap-locked: yes
  tpacket-v3: yes
  ring-size: 100000
  block-size: 1048576

这样就可以映射36个工作线程(每个af包接口插槽18个),每个cpu numa1范围为18-35,54-71。这部分是通过 worker-cpu-set 关联设置。 ring-sizeblock-size 在上面的config部分中有一些不错的默认值。如果需要,可以更好地进行调整,如中所述 调整注意事项 .

9.5.2.2. 基于AMD的系统

另一个例子是使用基于AMD的系统,系统本身的体系结构和设计加上NUMA节点的交互是不同的,因为它是基于HyperTransport(HT)技术的。在这种情况下,不需要每个NUMA线程/锁。下面的例子显示了使用af分组的这种配置的建议, cluster-type: cluster_flow . Mellanox NIC位于NUMA 0上。

CPU设置如下:

Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                128
On-line CPU(s) list:   0-127
Thread(s) per core:    2
Core(s) per socket:    32
Socket(s):             2
NUMA node(s):          8
Vendor ID:             AuthenticAMD
CPU family:            23
Model:                 1
Model name:            AMD EPYC 7601 32-Core Processor
Stepping:              2
CPU MHz:               1200.000
CPU max MHz:           2200.0000
CPU min MHz:           1200.0000
BogoMIPS:              4391.55
Virtualization:        AMD-V
L1d cache:             32K
L1i cache:             64K
L2 cache:              512K
L3 cache:              8192K
NUMA node0 CPU(s):     0-7,64-71
NUMA node1 CPU(s):     8-15,72-79
NUMA node2 CPU(s):     16-23,80-87
NUMA node3 CPU(s):     24-31,88-95
NUMA node4 CPU(s):     32-39,96-103
NUMA node5 CPU(s):     40-47,104-111
NUMA node6 CPU(s):     48-55,112-119
NUMA node7 CPU(s):     56-63,120-127

这个 ethtoolshow_irq_affinity.shset_irq_affinity_cpulist.sh 工具由官方驱动源提供。设置NIC,包括卸载和负载平衡:

ifconfig eno6 down
/opt/mellanox/ethtool/sbin/ethtool -L eno6 combined 15
/opt/mellanox/ethtool/sbin/ethtool -K eno6 rxhash on
/opt/mellanox/ethtool/sbin/ethtool -K eno6 ntuple on
ifconfig eno6 up
/sbin/set_irq_affinity_cpulist.sh 1-7,64-71 eno6
/opt/mellanox/ethtool/sbin/ethtool -X eno6 hfunc toeplitz
/opt/mellanox/ethtool/sbin/ethtool -X eno6 hkey 6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A:6D:5A

在上面的例子中(对于irq亲和力为1-7,64-71),cpu0被跳过,因为它通常在Linux系统上被许多应用程序/工具默认使用。尽可能让NIC保持平衡:

for proto in tcp4 udp4 tcp6 udp6; do
   /usr/local/sbin/ethtool -N eth1 rx-flow-hash $proto sdfn
done

在苏瑞塔亚姆配置:

# Suricata is multi-threaded. Here the threading can be influenced.
threading:
 set-cpu-affinity: yes
 cpu-affinity:
   - management-cpu-set:
       cpu: [ "120-127" ]  # include only these cpus in affinity settings
   - receive-cpu-set:
       cpu: [ 0 ]  # include only these cpus in affinity settings
   - worker-cpu-set:
       cpu: [ "8-55" ]
       mode: "exclusive"
       prio:
         high: [ "8-55" ]
         default: "high"

在苏瑞塔亚姆配置:

- interface: eth1
  # Number of receive threads. "auto" uses the number of cores
  threads: 48 # 48 worker threads on cpus "8-55" above
  cluster-id: 99
  cluster-type: cluster_flow
  defrag: no
  use-mmap: yes
  mmap-locked: yes
  tpacket-v3: yes
  ring-size: 100000
  block-size: 1048576

在上面的示例中,有15个RSS队列固定在NUMA节点0上的核心1-7、64-71上,40个工作线程使用不同NUMA节点上的其他cpu。在这个设置中跳过CPU 0的原因是,在Linux系统中,许多工具/服务默认使用CPU 0是非常常见的。此配置中的NIC本身位于NUMA0上,因此从NUMA节点上的15个RSS队列开始,并在系统中的其他工具上关闭这些队列可以提供最好的优势。

注解

整个系统的性能和优化会受到NIC驱动程序和pkg/内核升级的影响,因此应该定期对其进行监控,并首先在QA/测试环境中进行测试。作为一般建议,建议始终按照特定NIC供应商的指示和提供运行最新的稳定固件和驱动程序。

9.5.2.3. 其他注意事项

另一个需要考虑的高级选项是 isolcpus kernel boot参数是一种允许CPU内核被隔离以供一般系统进程使用的方法。这样可以确保这些CPU/范围只用于Suricata进程。

stream.wrong_thread / tcp.pkt_on_wrong_thread 柜台在吗 stats.logeve.json 作为 event_type: stats 表示负载平衡有问题。也可能存在相关的流量/NIC设置。在非常高/大量增加的计数器值中,建议通过NIC或例如使用XDP/eBPF试验不同的负载平衡方法。有一个问题未解决https://redmine.openinfosecfoundation.org/issues/2725这是反馈和发现的占位符。