I have been dipping my feet into Distributed Systems and set up a cluster of Raspberry Pi Nodes recently. The first thing I wanted to try was forming an Erlang cluster, And libcluster makes this very easy through the Gossip strategy. Here is the code to form the erlang cluster automatically (as long as it is on the same network).
1 | # application.ex |
Once, the clustering was set up I wanted to try sending messages through the cluster and see how it performed, the simplest test I could think of was a baton relay. Essentially, I spin up one GenServer per node and it relays a counter to the next node, which sends it to the next node and so on like the picture below (psa, psb, psc, and psd are the names of the nodes):
The code for this ended up being very straightforward. We create a GenServer and
make one of the nodes a main_node
so that it can kick off the baton relay.
And, whenever we get a counter with a :pass
message we increment the counter
and forward it to the next node. Here is the full code:
1 | defmodule Herd.Baton.ErlangProcess do |
Finally, here is the Datadog graph for the counter, The big thing to note is that the 4 GenServers on a local lan were able to pass around 100M messages in 8 hours which amounts to about 3.5K messages per second which is impressive: