ZMQ模式经销商/路由器HeartBeating [英] ZMQ Pattern Dealer/Router HeartBeating

查看:552
本文介绍了ZMQ模式经销商/路由器HeartBeating的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在客户端有一个经销商套接字,在服务器端连接到路由器套接字。

I have a Dealer socket in client side, who is connected to Router socket in server side.

我经常看到Heartbeating机制:服务器定期发送消息到客户端,以便客户端知道他是否正确连接到服务器,因此如果客户端在一段时间内没有收到消息,客户端可以重新连接。

I often see Heartbeating mechanism : the server regularly send message to the client in order that client knows if he is correctly connect to the server, so the client can reconnect if he doesn't received message for some times.

例如这里的Paranoid Pirate模式: http: //zguide.zeromq.org/page:chapter4

For example the Paranoid Pirate pattern here : http://zguide.zeromq.org/page:chapter4

但是在一些测试之后:如果客户端松开与服务器的连接一段时间,并找到它

But after some tests : if the client loose the connection to the server for a moment and find it again, the client is automatically reconnected to the server socket (he receive sended message...).

我不知道在哪种情况下Heartbeating是必要的?

I wonder in which case Heartbeating is necessary ?

推荐答案

心跳不必要保持连接活动(TCP套接字有一个ZMQ_TCP_KEEPALIVE套接字选项)。相反,需要心跳以使双方知道另一侧仍然活动。如果任一方检测到另一方没有活动,它可以采取替代措施。

Heartbeating isn't necessary to keep the connection alive (there is a ZMQ_TCP_KEEPALIVE socket option for TCP sockets). Instead, heartbeating is required for both sides to know that the other side is still active. If either side does detect that the other is inactive, it can take alternative action.

不活动可能是因为一个进程已经死亡,它是死锁,它做了太多的工作之间网络活动或网络故障等。从其他方面来看,所有这些情况都无法区分,没有更多信息。

Inactivity might be because a process has died, it's deadlocked, it's doing too much work between network activity, or network failure, etc. From the other sides point of view, all these scenarios are indistinguishable without more information.

在网络中,设计工作是容易的部分。压倒性的部分是处理失败。您必须考虑尽可能多的可能的故障模式,并在设计协议中处理它们。心跳通常是这些协议中有用的部分。如果一个套接字仍然在使用监视器事件,比如说,它们比尝试解决更有用。

In networking, making a design work is the easy part. The overwhelmingly hard part is dealing with failure. You have to consider as many possible failure modes as possible and deal with them in the design protocols. Heartbeating is often a helpful part in those protocols. They are far more useful than trying to work out if a socket is still up by use of monitor events, say.

说到这里,如果你的应用程序不需要任何特定级别的可靠性;也许你可以只是循环设备发生故障时。那么你可能不需要担心心跳。毕竟,在指南中有很多模式,不使用它。这是马的课程。

Having said that, if your application doesn't need any particular level of reliability; perhaps you can just power cycle equipment when a failure happens. Then you probably don't need to worry about heartbeating. After all, there are plenty of patterns in the guide that don't use it. It's horses for courses.

这篇关于ZMQ模式经销商/路由器HeartBeating的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆