遇到一个很有意思的案例,忍不住跟大家分享一下。
客户在做压力测试的时候,用 snmpget 命令对大量的 ip 地址进行并行操作,刚开始一切正常,当 ip 地址数量达到5000个的时候出现报错,用 strace 看到 sendmsg() 调用返回了 EINVAL 错误,EINVAL 的含义在 manpage 上明明白白地写着表示非法参数:
EINVAL Invalid argument passed.
可是调用 sendmsg() 所用的参数都差不多,怎么在压力小的时候参数不非法,压力一大参数就非法了呢?
答案出乎意料之外又在情理之中,是 Neighbour table overflow,也就是 ARP table,用于把 ip 地址翻译成 mac 地址,满了之后 ip 地址解析失败,返回的错误类型就是 EINVAL。在 4.3 kernel 中加入了报错信息"neighbor table overflow",/proc/net/stat/arp_cache 中也加入了 table_fulls 统计值,有助于诊断。但是RHEL7的 kernel 还没有这些,既没有报错也没有统计,所以没什么线索可循。
ARP table (neighbour table) 的大小可以通过以下内核参数来控制,RHEL7的缺省值如下:
net.ipv4.neigh.default.gc_thresh1 = 128
net.ipv4.neigh.default.gc_thresh2 = 512
net.ipv4.neigh.default.gc_thresh3 = 1024
注:最大值可以达到 INT_MAX,即最大的整数值。
参数的含义可见 arp(7) 的手册页:
gc_thresh1 (since Linux 2.2) The minimum number of entries to keep in the ARP cache. The garbage collector will not run if there are fewer than this num‐ ber of entries in the cache. Defaults to 128. gc_thresh2 (since Linux 2.2) The soft maximum number of entries to keep in the ARP cache. The garbage collector will allow the number of entries to exceed this for 5 seconds before collection will be performed. Defaults to 512. gc_thresh3 (since Linux 2.2) The hard maximum number of entries to keep in the ARP cache. The garbage collector will always run if there are more than this number of entries in the cache. Defaults to 1024. |
具体到本例,最后把参数调大就解决了问题。
上文内容不用于商业目的,如涉及知识产权问题,请权利人联系博为峰小编(021-64471599-8017),我们将立即处理。