ZMQ Pattern Dealer / Router HeartBeating

I have a client side Dealer socket that is connected to a server side router socket.

I often see the Heartbeating mechanism: the server regularly sends a message to the client to let the client know if it is properly connected to the server, so the client can reconnect if it hasn't received the message multiple times.

For example, the paranoid pirate pattern is here: http://zguide.zeromq.org/page:chapter4

But after some tests: if the client lost the connection to the server for a moment and found it again, the client automatically connects to the server socket (it gets a message with a message ...).

I wonder in which case Heartbeating is required?

+3


source to share


1 answer


Heartbeat is not necessary to keep the connection alive (there is a ZMQ_TCP_KEEPALIVE socket option for TCP sockets). Instead, it takes a heartbeat for both sides to know that the other side is still active. If a party discovers that the other is inactive, it can take alternative action.

The inactivity could be that the process has died, it is deadlocked, it worked too much between network activity or network failure, etc. On the other hand, all these scenarios are indistinguishable without additional information.



On the web, creating design work is the easy part. In the vast majority of cases, it is about failure. You should consider as many possible failure modes as possible and deal with them in your development protocols. Heartbeat is often a useful part of these protocols. They are much more useful than trying to work out if the socket is still running using monitor events, say.

Having said that, if your application doesn't need any particular level of reliability; perhaps you can simply engage the loop hardware when a failure occurs. Then you probably don't need to worry about heartbeat. After all, there are many templates in the manual that don't use it. These are the horses for the courses.

+2


source







All Articles