VM IPSec 解密流量 CPU 负载
VM IPSec 解密流量 CPU 负载
FortiGate-VM 使用单条或多条 IPSec 隧道时,如果解密流量长期集中在少数 CPU 上,可能出现单核 CPU 高、隧道吞吐上不去或业务抖动的问题。可以通过 config system affinity-packet-redistribution 将指定接口收发的报文重新分配到指定 CPU 范围内处理,让 IPSec 软件加解密流量更均衡。
适用场景
该配置主要用于 FortiGate-VM,常见于以下场景:
- FortiGate-VM 有多个 vCPU,但 IPSec 解密流量只集中在一个或少数几个 CPU。
- 只有一条 IPSec 隧道承载大量流量,软件解密压力集中在同一个 CPU。
- 多条 IPSec 隧道共用同一个父接口,希望将该接口上的 IPSec 报文分散到更多 CPU。
可以使用 diagnose vpn ipsec cpu 查看 IPSec 软件加解密流量在各 CPU 上的分布。例如 8 vCPU 的 FortiGate-VM 中,只有部分 CPU 有明显计数:
FGT-VM # diagnose vpn ipsec cpu
Software crypto CPU distributions:
CPU# enc dec-in dec dec-out
0 60 0 65 65
1 57 0 57 57
2 0 0 0 0
3 0 0 0 0
4 0 0 0 0
5 0 0 0 0
6 0 0 0 0
7 60 0 65 65相关信息
如果只有一条 IPSec 隧道,解密流量可能固定由同一个 CPU 处理。此时只配置 CPU 掩码不一定能让单隧道流量均衡,通常还需要启用 round-robin。
CPU 掩码计算
affinity-cpumask 使用十六进制位图表示允许参与报文重分配的 CPU。每个 CPU 对应一个 bit:
| CPU | 掩码 |
|---|---|
| CPU0 | 0x0000000000000001 |
| CPU1 | 0x0000000000000002 |
| CPU2 | 0x0000000000000004 |
| CPU3 | 0x0000000000000008 |
| CPU4 | 0x0000000000000010 |
| CPU5 | 0x0000000000000020 |
| CPU6 | 0x0000000000000040 |
| CPU7 | 0x0000000000000080 |
常用掩码如下:
| CPU 范围 | 完整写法 | 简写 |
|---|---|---|
| CPU0 到 CPU3 | 0x000000000000000f | 0xf |
| CPU4 到 CPU7 | 0x00000000000000f0 | 0xf0 |
| CPU0 到 CPU7 | 0x00000000000000ff | 0xff |
| CPU0 到 CPU11 | 0x0000000000000fff | 0xfff |
例如希望将流量分布到 CPU0 到 CPU3,则掩码为:
0x1 + 0x2 + 0x4 + 0x8 = 0xf也可以使用 CPU Affinity Mask Calculator 计算 CPU 掩码,再结合 FortiGate-VM 实际 vCPU 数量确认配置值。
配置方法
在 IPSec 隧道建立所在的父接口上配置 affinity-packet-redistribution。例如 IPSec 隧道建立在 port2 上,希望将 port2 上的报文分布到 CPU0 到 CPU7:
config system affinity-packet-redistribution
edit 1
set interface "port2"
set round-robin enable
set affinity-cpumask "0xff"
next
endinterface:选择 IPSec 隧道所在的父接口,例如公网接口port2。如果多条 IPSec 隧道分别建立在不同父接口上,需要按接口分别配置。round-robin:单条 IPSec 隧道承载大量流量时建议启用,让报文在掩码指定的 CPU 间轮询分配。affinity-cpumask:指定参与报文分配的 CPU 范围,不能超过当前 FortiGate-VM 实际可用 vCPU。
提示
如果只希望使用 CPU0 到 CPU3,将 affinity-cpumask 配置为 0xf 即可。生产环境建议先确认当前 vCPU 数量、CPU 使用率和业务流量方向,再选择掩码范围。
结果验证
配置后重新发起 IPSec 业务流量,再次查看 IPSec 软件加解密 CPU 分布:
FGT-VM # diagnose vpn ipsec cpu
Software crypto CPU distributions:
CPU# enc dec-in dec dec-out
0 33 0 33 33
1 0 0 0 0
2 65 0 65 65
3 33 0 33 33
4 33 0 33 33
5 32 0 32 32
6 33 0 33 33
7 33 0 33 33重点观察:
enc、dec、dec-out等计数是否不再长期集中在单个 CPU。diagnose sys top或diagnose hardware sysinfo cpu中是否仍存在单核长期跑满。- IPSec 业务吞吐、丢包、重传和时延是否改善。
如果需要恢复配置,可以删除对应条目:
config system affinity-packet-redistribution
delete 1
end注意事项
- 该功能用于 FortiGate-VM 的报文/软件加解密 CPU 分配优化,不是 IPSec 选路、SD-WAN 成员选择或防火墙策略问题的解决方法。
interface应选择 IPSec 隧道创建所在的物理/虚拟父接口,而不是隧道接口本身。round-robin enable对单隧道大流量场景更有意义;多隧道环境中是否启用,需要结合实际 CPU 分布和业务压测结果评估。- 如果所有参与 CPU 都已经接近满载,该配置只能改善分布不均,不能突破 FortiGate-VM 授权、vCPU 数量或底层虚拟化平台的性能上限。
- 建议在维护窗口配置并压测,观察 CPU 分布、业务吞吐、丢包和重传情况后再投入生产。