User Tools

Site Tools


cs326:labd

CSci 326 Lab - Distributing Computations

The purpose of this assignment is to become familiar with concurrent and distributed computing concepts. Record the results of the steps below, and turn in a writeup to the instructor.

Getting Started. Download the program kvs.erl. This is a simple program (a name server) to store and lookup key/value pairs, as described in Chapter 14, Section 14.3.

Read through the program to get an idea of how it works, compared to the programs we looked at previously. It's dead easy to use: call KVS.store with a key and a value to store the key with the value, and KVS.lookup with a key to retrieve a previously stored value. For example:

>KVS.store :cs326, "Elixir"
:ok
>KVS.store :cs320, "pseudocode"
:ok
>KVS.store :cs157, "Java"
:ok
>KVS.lookup(cs326)
{:ok, "Elixir"}
>KVS.lookup(cs257)
undefined

Going Distributed.

To communicate over a network, two BEAM nodes must 1) be named using the -sname option AND 2) be running on systems with the same value stored in the file ~/.erlang.cookie. For most of us, the system already generated a .erlang.cookie file, and they are all different! There are two ways to make these the same:

  1. the easy way: specify the value on the command line when you start iex, using the -setcookie option. For example, to start an BEAM node named key that communicates using the cookie this_is_very_secret, start iex this way:
    iex -sname key -setcookie this_is_very_secret
  2. the almost as easy way: delete the file ~/.erlang.cookie, then recreate it using the method shown in the tutorial, section 3.4.

Now we all have the same value stored in our file, and the -setcookie option is not needed. I hope.

Start iex directly as shown above (but choose a different node name than key):

  1. Compile the KVS module
  2. Try the examples above to make sure it works.
  3. I have a server running on the host farheen with BEAM node named bob. The keys are atoms representing computer science courses in the catalog, as above.
  4. look up at least three different keys. Record the results.
  5. store at least three new key/value pairs on my server. Personalize them so I know who did what! Use your initials (all 3, all lower case) plus a three digit course number as the key; for example, for me the key might be spc276. The value can be any old string, but remember this is a family-friendly lab!
  6. Record the results of trying to store and trying to look them up again.
  7. Restart iex using the same node name as before. Work with the person nearest to you (exchange node and host names). Each of you will add some key/value pairs. Again the keys are computer science courses, but the value can be any string, such as “really hard”, “boring”, or “too much fun”. Once you each have some values stored, use the appropriate mechanism to lookup values on your partner's name server.

NOTE: don't get too frustrated if this doesn't work easily. I haven't tested it very deeply! If you have problems, consult the instructor. No matter the outcome, record your results.

Writeup your results and turn in to the instructor.

cs326/labd.txt · Last modified: 2021/11/01 11:01 by scarl