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:
-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
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):
KVS
moduleNOTE: 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.