使用 python elasticsearch 客户端嗅探解决 TCP 死连接问题

Using sniffing with python elasticsearch client to solve dead TCP connection issues

我的应用程序中的 Python elasticsearch 客户端存在连接问题(拒绝连接),因为空闲 TCP 连接因防火墙而超时(我无法阻止这种情况)。

我解决这个问题的最简单方法是,如果我可以通过定期发送一些数据来防止连接空闲,elasticsearch 客户端中的嗅探选项似乎很适合这个,但是它们 not very well documented:

sniff_on_start – flag indicating whether to obtain a list of nodes from the cluser at startup time

sniffer_timeout – number of seconds between automatic sniffs

sniff_on_connection_fail – flag controlling if connection failure triggers a sniff

sniff_timeout – timeout used for the sniff request - it should be a fast api call and we are talking potentially to more nodes so we want to fail quickly. Not used during initial sniffing (if sniff_on_start is on) when the connection still isn’t initialized.

我希望客户端每(比如说)5 分钟嗅探一次,我应该使用 sniff_timeout 还是 sniffer_timeout 选项?另外,sniff_on_start参数是否应该设置为True

我使用了 @val 的建议,发现这些设置解决了我的问题:

sniff_on_start=True
sniffer_timeout=60
sniff_on_connection_fail=True

嗅探在 TCP 连接上放置了足够的流量,因此它们永远不会闲置足够长的时间,以至于我们的防火墙无法终止连接。