Erlang Supervisor 重新启动与已关闭主机的连接的策略
我使用 erlang 作为服务之间的桥梁,我想知道人们对处理断开的连接有什么建议?
我正在从本地文件获取输入并将它们通过管道传输到 AMQP,可以想象 AMQP 代理可能会崩溃。对于这种情况,我想继续重试连接到 AMQP 服务器,但我不想将 CPU 与这些连接尝试挂钩。我的倾向是在 AMQP 代码重新启动时进入睡眠状态。这种“黑客”难道不会本质上规避快速失败并让 erlang 处理它的目的吗?更一般地说,erlang 管理程序行为是否应该用于处理断开的连接?
I'm using erlang as a bridge between services and I was wondering what advice people had for handling downed connections?
I'm taking input from local files and piping them out to AMQP and it's conceivable that the AMQP broker could go down. For that case I would want to keep retrying to connect to the AMQP server but I don't want to peg the CPU with those connections attempts. My inclination is to put a sleep into the reboot of the AMQP code. Wouldn't that 'hack' essentially circumvent the purpose of failing quickly and letting erlang handle it? More generally, should the erlang supervisor behavior be used for handling downed connections?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为编写自己的语义来处理与外部服务器的连接是合理的。 Supervisor 最适合处理您自己的进程树中崩溃/锁定/其他不健康的进程,而不是重新连接到外部服务。
您的进程是在与 AMQP 代理相同的进程树中传输本地文件还是一个单独的服务?
I think it's reasonable to code your own semantics for handling connections to an external server yourself. Supervisors are best suited to handling crashed/locked/otherwise unhealthy processes in your own process tree not reconnections to an external service.
Is your process that pipes the local files in the same process tree as the AMQP broker or is it a separate service?