Elixir Distribution, ELI5

Let’s form cluster locally

Start three Nodes
iex(1)>
iex(foo@pop-os)1>
iex(foo@pop-os)1> Node.list()
List Nodes in the Cluster
iex(foo@pop-os)2> Node.ping(:"bar@pop-os")
Let’s ping another Node
iex(foo@pop-os)3> Node.list()
List the foo’s Nodes again
List the bar’s Nodes
iex(baz@pop-os)1> Node.list()
[]
iex(baz@pop-os)2> Node.ping(:"foo@pop-os")
iex(baz@pop-os)3> Node.list()
List baz’s known Nodes
Let’s check all the Nodes

A quiet hero

epmd -names
Query epmd

Getting serious

IP Address of one computer
IP address of the other computer
> iex --name foo@192.168.1.176
Start foo on the first computer
> iex --name bar@192.168.1.153
Start bar on the other computer
iex(bar@192.168.1.153)1> Node.ping(:"foo@192.168.1.176")
Connect Nodes — first attempt
iex(bar@192.168.1.153)2> Node.list()
List known Nodes
A log message
iex --name foo@192.168.1.176 --erl "-setcookie for_fun"
Start a named Node with Cookie
iex --name bar@192.168.1.153 --erl "-setcookie for_fun"
Start another Node with the same Cookie
iex(bar@192.168.1.153)1> Node.ping(:"foo@192.168.1.176")
Connect Nodes — second attempt
iex(bar@192.168.1.153)2> Node.list()
List known foo’s Nodes
iex(foo@192.168.1.176)1> Node.list()
Bar’s known Nodes
epmd on foo
epmd on bar

Conclusion

  1. There are two strategies to start BEAM Node in a Distributed mode:
    * With a “short name” (--sname option) that is sufficient to start Nodes on the same machine
    * With a “fully qualified name” (--name option) that has to include the location of the Node, eg. the IP address of the machine it is hosted on
  2. For the Nodes to connect, they have to share the same Cookie (via --erl "-setcookie <cookie>")
  3. When starting BEAM in a Distributed Node, additional process — EPMD- is started, which tracks the ports for each registered Node.
    In fact, when the cross-machine communication is established, this is a very first attempt between Nodes — when one Node tries to connect to the other, it will check with EPMD first, and a random port, upon successful connection will be allocated.
    In fact, port management will be very important when deploying applications eg. in AWS’ environment, so we will need to make sure proper ports are configured, otherwise — the Nodes won’t be able to connect.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store