The purpose of this assignment is to become familiar with Elixir nodes, the
Node module, and distributing computing across nodes. Record the results of the steps below, and turn in a writeup to the instructor.
Introduction. We can run multiple instances of the BEAM (using iex or elixir) on the same computer, or over a network of computers. Each such instance is called a node and nodes can communicate with each other. To do this, BEAM nodes must 1) be named using the
–name option AND 2) be running on systems with the same value (a 'cookie') stored in the file ~/.erlang.cookie.
Let's look into this. Start two Terminal windows, side by side. Change to a different directory in one of them.
iex --sname harry
and another could be
iex --sname maude
Node.connectto connect to the 'right' node using its full name (what
Node.listin both nodes. Record the results, labeling with the node name so I know which is which
func = fn -> IO.inspect Node.self end
func.()directly and record the results
Node.spawn nodeName, func
nodeName is the full name of the other node. Record (and label!) both results. Does this work on both nodes? Why or why not?
fun = fn -> IO.puts(Enum.join(File.ls!, ",")) end
Run this function on each node and record the results
Node.get_cookiein both nodes. Is it the same as the value held in ~/.erlang.cookie?
Exit both instances of iex and restart, but with different cookie values. You can change the cookie value used by nodes by specifying the cookie on the command line when you start iex. Use the
–cookie option to do this. For example, to start an BEAM node named harry that communicates using the cookie this_is_very_secret, you might start iex this way:
iex --sname harry --cookie this_is_very_secret
Start your nodes again but with different cookie values. Try using
Node.connect to connect them again. Record the results.
We'll see how to extend all this to multiple computers in a coming lab.