Skip to content
Permalink
Browse files

add support for SILENT event

NB: evasive could be safely deprecated with this modification
  • Loading branch information...
ingenuityio committed Oct 6, 2019
1 parent a3c7c42 commit 2d6ef2b05d11bcf923440dd34334c17b771a3074
Showing with 68 additions and 2 deletions.
  1. +12 −0 api/zyre.api
  2. +3 −0 examples/chat/chat.c
  3. +11 −0 include/zyre.h
  4. +22 −1 src/zyre.c
  5. +20 −1 src/zyre_node.c
@@ -76,6 +76,18 @@
<argument name = "interval" type = "integer" />
</method>

<method name = "set silent timeout">
Set the peer silence timeout, in milliseconds. Default is 5000.
This can be tuned in order to deal with expected network conditions
and the response time expected by the application. This is tied to
the beacon interval and rate of messages received.
Silence is triggered one second after the timeout if peer has not
answered ping and has not sent any message.
NB: this is currently redundant with the evasiveness timeout. Both
affect the same timeout value.
<argument name = "interval" type = "integer" />
</method>

<method name = "set expired timeout">
Set the peer expiration timeout, in milliseconds. Default is 30000.
This can be tuned in order to deal with expected network conditions
@@ -83,6 +83,9 @@ chat_actor (zsock_t *pipe, void *args)
else
if (streq (event, "EVASIVE"))
printf ("%s is being evasive\n", name);
else
if (streq (event, "SILENT"))
printf ("%s is being silent\n", name);

free (event);
free (peer);
@@ -78,6 +78,17 @@ ZYRE_EXPORT void
ZYRE_EXPORT void
zyre_set_evasive_timeout (zyre_t *self, int interval);

// Set the peer silence timeout, in milliseconds. Default is 5000.
// This can be tuned in order to deal with expected network conditions
// and the response time expected by the application. This is tied to
// the beacon interval and rate of messages received.
// Silence is triggered one second after the timeout if peer has not
// answered ping and has not sent any message.
// NB: this is currently redundant with the evasiveness timeout. Both
// affect the same timeout value.
ZYRE_EXPORT void
zyre_set_silent_timeout (zyre_t *self, int interval);

// Set the peer expiration timeout, in milliseconds. Default is 30000.
// This can be tuned in order to deal with expected network conditions
// and the response time expected by the application. This is tied to
@@ -26,7 +26,9 @@
ENTER fromnode name headers ipaddress:port
a new peer has entered the network
EVASIVE fromnode name
a peer is being evasive (quiet for too long)
a peer is being evasive (i.e. quiet) and will be pinged manually
SILENT fromnode name
a peer has been quiet and has not answered ping after 1 second
EXIT fromnode name
a peer has left the network
JOIN fromnode name groupname
@@ -232,6 +234,25 @@ zyre_set_evasive_timeout (zyre_t *self, int interval)
zstr_sendf (self->actor, "%d", interval);
}

// --------------------------------------------------------------------------
// Set the node silence timeout, in milliseconds. Default is 5000.
// Silence means that a peer does not send messages and does not
// answer to ping. SILENT event is triggered one second after the
// configured silence timeout, and every second after that until
// the expired timeout is reached.
// This can be tuned in order to deal with expected network conditions
// and the response time expected by the application. This is tied to
// the beacon interval and rate of messages received.
// NB: in current implementation, zyre_set_silent_timeout is redundant
// with zyre_set_evasive_timeout and calls the same code underneath.
void
zyre_set_silent_timeout (zyre_t *self, int interval)
{
assert (self);
zstr_sendm (self->actor, "SET SILENT TIMEOUT");
zstr_sendf (self->actor, "%d", interval);
}

// --------------------------------------------------------------------------
// Set the node expiration timeout, in milliseconds. Default is 30000.
// This can be tuned in order to deal with expected network conditions
@@ -467,6 +467,12 @@ zyre_node_recv_api (zyre_node_t *self)
zstr_free (&value);
}
else
if (streq (command, "SET SILENT TIMEOUT")) {
char *value = zmsg_popstr (request);
self->evasive_timeout = atoi (value);
zstr_free (&value);
}
else
if (streq (command, "SET EXPIRED TIMEOUT")) {
char *value = zmsg_popstr (request);
self->expired_timeout = atoi (value);
@@ -1378,7 +1384,7 @@ zyre_node_ping_peer (const char *key, void *item, void *argument)
// it would be nicer to use a proper state machine
// for peer management.
if (self->verbose)
zsys_info ("(%s) peer seems dead/slow name=%s endpoint=%s",
zsys_info ("(%s) peer does not send messages (evasive) name=%s endpoint=%s",
self->name, zyre_peer_name (peer), zyre_peer_endpoint (peer));
zre_msg_t *msg = zre_msg_new ();
zre_msg_set_id (msg, ZRE_MSG_PING);
@@ -1388,6 +1394,19 @@ zyre_node_ping_peer (const char *key, void *item, void *argument)
zstr_sendm (self->outbox, "EVASIVE");
zstr_sendm (self->outbox, zyre_peer_identity (peer));
zstr_send (self->outbox, zyre_peer_name (peer));
if (zclock_mono () >= zyre_peer_evasive_at (peer) + REAP_INTERVAL) {
// Inform the calling application this peer is being silent
// despite having tried to ping it. Something is wrong with
// the connection to this peer (or with the network).
// NB: this is an improvement of the EVASIVE event which triggers
// before getting ping result and thus has poor meaning.
if (self->verbose)
zsys_info ("(%s) peer has not answered ping after %d milliseconds (silent)",
self->name, REAP_INTERVAL);
zstr_sendm (self->outbox, "SILENT");
zstr_sendm (self->outbox, zyre_peer_identity (peer));
zstr_send (self->outbox, zyre_peer_name (peer));
}
}
return 0;
}

0 comments on commit 2d6ef2b

Please sign in to comment.
You can’t perform that action at this time.