linux网卡收包调优¶
网卡监控¶
| Bash | |
|---|---|
1 2 3 4 5 6 7 8 | |
网卡调优¶
队列¶
| Bash | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | |
硬件中断¶
| Bash | |
|---|---|
1 | |
软中断¶
| Bash | |
|---|---|
1 2 3 4 | |
监控数据处理¶
| Bash | |
|---|---|
1 2 3 | |
RPS¶
/sys/class/net/DEVICE_NAME/queues/QUEUE/rps_cpus
RFS¶
将属于相同 flow 的包送到相同的 CPU 进行处理 sysctl -w net.core.rps_sock_flow_entries=32768 echo 2048 > /sys/class/net/eth0/queues/rx-0/rps_flow_cnt
收包打时间戳¶
sysctl -w net.core.netdev_tstamp_prequeue=0
backlog¶
在 Linux 网络收包过程中,CPU 的 backlog queue(积压队列)是指内核在软中断阶段处理网络包时,如果当前 CPU 处理不过来,会将未处理的包暂存到 backlog 队列中。这个队列是 per-CPU 的,主要用于缓冲那些暂时无法及时处理的网络包,防止丢包。
backlog queue 的作用:
缓解瞬时流量高峰,避免因处理速度跟不上而丢包。 由 softirq 处理(如 net_rx_action),当 backlog 队列满时,内核会丢弃新到的包。 相关参数和监控:
/proc/net/softnet_stat 可以查看每个 CPU 的 backlog 队列状态和丢包统计。 net.core.netdev_max_backlog 用于设置 backlog 队列的最大长度。 简而言之,backlog queue 是 CPU 级别的网络包缓冲队列,用于提升网络收包的鲁棒性和性能。
sysctl -w net.core.netdev_max_backlog=3000 sysctl -w net.core.dev_weight=600 sysctl -w net.core.flow_limit_table_len=8192
cat /proc/net/snmp InReceives: The total number of IP packets that reached ip_rcv before any data integrity checks. InHdrErrors: Total number of IP packets with corrupted headers. The header was too short, too long, non-existent, had the wrong IP protocol version number, etc. InAddrErrors: Total number of IP packets where the host was unreachable. ForwDatagrams: Total number of IP packets that have been forwarded. InUnknownProtos: Total number of IP packets with unknown or unsupported protocol specified in the header. InDiscards: Total number of IP packets discarded due to memory allocation failure or checksum failure when packets are trimmed. InDelivers: Total number of IP packets successfully delivered to higher protocol layers. Keep in mind that those protocol layers may drop data even if the IP layer does not. InCsumErrors: Total number of IP Packets with checksum errors.
sysctl -w net.core.netdev_max_backlog=3000 sysctl -w net.core.dev_weight=600 sysctl -w net.core.flow_limit_table_len=8192 AMD_pstat=disable idle=poll nohz=off iommu=pt
cpupower monitor