O'Reilly logo

Erlang Programming by Francesco Cesarini, Simon Thompson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Distributed Computing in Erlang: The Basics

An Erlang node is an executing Erlang runtime system that has been given a name. Multiple nodes can run on a single host, but they can also be running on different host computers, too, as shown in Figure 11-1, where three nodes are running on the hosts STC and FCC in their respective subnetworks.

Three nodes running on two hosts

Figure 11-1. Three nodes running on two hosts

As a first example, we’ll look at two nodes running on the same machine, STC, as shown in Figure 11-2. To run a node, the erl command needs to be given the sname flag (the name flag can also be used; we’ll discuss this shortly). For example:

erl -sname foo
Erlang (BEAM) emulator version 5.6.3 [source] [64-bit] [smp:2]
 [async-threads:0] [kernel-poll:false]

Eshell V5.6.3  (abort with ^G)
(foo@STC)1>

Note that the prompt in the Erlang shell displays the name of the node, as well as its host computer: foo@STC. This is called the (unique) identifier of the node.

A similar command, erl–sname bar, will set up a second node on the STC system.

A first example: two nodes on one host

Figure 11-2. A first example: two nodes on one host

To understand what happens next, you need to look at the module dist.er1. This contains the function t:

t(From) -> From ! node().

The function takes as a parameter a pid, From, and in its single action it sends a message to the process ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required