User Tools

Site Tools


cs326:labdpre

CSci 326 Lab - Distributing Computations Part 1

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 –sname or –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.

  1. Start iex in both Terminal windows; give each node a different name, whatever you like, for example one could be
    iex --sname harry

    and another could be

    iex --sname maude
  2. Record the full name of each node using Node.self
  3. In your 'left' node, use Node.connect to connect to the 'right' node using its full name (what Node.self returns)
  4. Run Node.list in both nodes. Record the results, labeling with the node name so I know which is which
  5. In both nodes, create this anonymous function:
    func = fn -> IO.inspect Node.self end
  6. Call func.() directly and record the results
  7. Now in each node, spawn a process to execute func using the Node version:
    Node.spawn nodeName, func

    where nodeName is the full name of the other node. Record (and label!) both results. Does this work on both nodes? Why or why not?

  8. In one window, write this function that lists the contents of the current directory:
    fun = fn -> IO.puts(Enum.join(File.ls!, ",")) end

    Run this function on each node and record the results

  9. Determine and record your system's cookie value by looking at the contents of ~/.erlang.cookie
  10. Since our nodes were able to communicate, they must use the same cookie value. Confirm this by recording the 'cookie' value returned when calling Node.get_cookie in 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.

cs326/labdpre.txt · Last modified: 2021/11/05 14:55 by scarl