我的应用程序中的 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 连接上放置了足够的流量,因此它们永远不会闲置足够长的时间,以至于我们的防火墙无法终止连接。
关于python - 使用嗅探与 python elasticsearch 客户端解决死 TCP 连接问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40865611/