Gossip Much? The Gossip Epidemic and Other Issues in Polite Society
Join the DZone community and get the full member experience.Join For Free
in my previous post, i talked about the hybrid partial view protocol, and showed a visualization about how it actually works. something that is important to note about this protocol is that it is mostly meant to create a gossip topology that is resilient to failure. it is not meant to actually send messages, it is meant to serve as the backbone topology (the peer sampling service) for figuring out what the nodes are.
the reason for that can be seen in the following 10 node cluster (after running heartbeat enough times to get to a stable state:
let us assume that we want to disseminate a message across the cluster. we select node a as our root, and then send a message. the rules are as follow:
- each node send the message to all its active connections (except the sender, of course).
- a node that got the same message twice will ignore the message.
based on those rules, and the topology above, we’re going to have the following chain of messages:
- f – initial broadcast
- f -> e, g, j
- e -> g, i
- g -> e, h
- j -> i, h, j
- h -> c, i
- c -> b, a
- b -> d, a
- a -> b, d
- d -> a
the total number of messages passed is 20. which is twice as much as the optimal solution would generate.
what is worse, this is a very small network, and as the network grows, so will the number of redundant messages. this approach (called eager gossiping) has a major advantage, because it will traverse all paths in the graph, it will also traverse all the shortest paths. that means that the time to get a message from the origin to all nodes is the smallest, but the number of operations is high.
the plumtree paper ( epidemic broadcast trees ) presents a solution to this problem. it tries to minimize the number of messages while still maintaining both reliability and optimizing the number of messages that are passed as well as the distance they have to pass.
the way plumtree works is explained in quite beautiful detail in the paper, but the underlying idea goes like this, we start using the same approach as the eager gossiping, but whenever we get a message that we already got, we will reply to the source and tell it to stop sending us further messages. this is done so the next time that a message will be sent, we can skip the known duplicate path, and reduce the number of overall messages that we have.
so the first run is going to generate 20 messages on the network. the second is going to generate just 13, you can see the non traversed paths in the following image:
note that we didn’t pass any messages between i and j, or d and a. but a lot of the saving was achieved by avoiding duplicate notifications. so node i notified node h, but not vice versa. the next time we’ll run this, we have exactly 10 messages passing:
now, obviously this is pretty cool, but that is under a stable state. what happens when they are failures? well, at that point, the notion of lazy vs. eager peers come into play. one of the things we did initially was to clear the duplicate paths in the network, so we can optimize the number of messages being passed. that is pretty cool, but it also leave us vulnerable to failures. for example, imagine that nod h is down. what happens then?
there are two aspects of this that are interesting. plumtrees only care about the notion of message passing. they don’t deal with topology changes. in this case, the responsibility to join the different parts of the network lies with the peer sampling service, which is hyparview in this case. that would figure out the communication issue, and forge new connections with the remaining nodes. plumtree will get notified about that, and the process continue.
but let us leave that one aside, let us say that we have a static topology, how would plumtree handle this? well, at this point you have to realize that plumtree doesn’t just drop a connection when a node tell it that it already heard about a message. it just move it to a lazy state. periodically, a node will contact other nodes which told it that it wasn’t needed and tell them: “hi, i got messages with ids (43,41,81), do you have them?”. in this way, a node whose contact point went down would become aware that there are missing messages. at that point, it start a timer, and if it didn’t hear about those missing messages, it will ask the node that told it about those messages to send them over, and initiate an active link. the end result here is that we send additional messages, but those tend to be pretty small, just the message ids.
during steady state, we’ll just ignore those messages, but if there is a failure, they can help us recover from errors by letting us know that there are messages that we are missing, and taking action to recover that.
there is also another important aspect of this behavior, detecting and circumventing slow nodes. if a node is slow to distribute messages to its peers, other nodes will notify those peers that those messages exists, and if that is the case, we’ll eventually move to a more efficient topology by routing around that slow node.
plumtree has a few weaknesses, mostly it is that it is optimized for a single source topology. in other words, the first node you start from will influence the optimization of the network, and if you start a broadcast from another node, it won’t be an optimal operation. that said, there are a few ways to handle that. the actual topology remains the same, what influence plumtree is the rejection replies from nodes that say that the information it transmitted was already received. we can keep track on not only the nodes that rejected us, but the root source of that rejection, so a message originating in e wouldn’t stop us from propagating a message originating in j.
because plumtree is meant for very large clusters (the paper talks about testing this with 10,000 nodes), and you might have a message originate from any one of those, you probably want to limit the notion of “origin”, if you track the past three nodes it passed through, you get a reasonably small amount of data that you have to keep, and it is likely to be accurate enough to build multiple topologies that will optimize themselves based on actual conditions.
that is it for this post, i’ve got a couple more posts that i want to write about gossips, but that would be it for today.
Published at DZone with permission of Oren Eini, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
RAML vs. OAS: Which Is the Best API Specification for Your Project?
Microservices With Apache Camel and Quarkus
Build a Simple Chat Server With gRPC in .Net Core
How To Scan and Validate Image Uploads in Java