Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is an Erlang node?

Tags:

erlang

I see a definition in one of books about Erlang:

A node is a self-contained Erlang system containing a complete virtual machine with its own address space and own set of processes.

But this raises more questions to me.

What is a self-contained Erlang system?

As an example, do I spawn a new node by going to terminal and running erl shell? Do I open multiple nodes by opening multiple terminals and running erl shell in each?

Are shells opened like above anyhow relate to each other or are they completely isolated by default? If these are different nodes, then do I treat this approach as distributed programming and should dig deeper in that topic in case I want to run and stop processes independently but then connect them?

like image 236
Sergei Basharov Avatar asked Aug 12 '16 08:08

Sergei Basharov


People also ask

What are elixir nodes?

An ELIXIR Node is a collection of research institutes within a member country. ELIXIR Nodes run the resources and services that are part of ELIXIR. Each Node has a lead institute that oversees the work of that Node.

What is an Erlang cookie?

The Erlang cookie is a shared secret used for authentication between RabbitMQ nodes and CLI tools. The value is stored in a file commonly referred to as the Erlang cookie file. The cookie file used by the service account and the user running rabbitmqctl. bat must be synchronised for CLI tools such as rabbitmqctl.


1 Answers

A node is one instance of the Erlang virtual machine running. If you're on linux and you list the processes, there will be one process for each node.

This means that when you start the vm on the terminal using erl, you are staring a new node every time.

If you're writing an application, you generally don't need to worry about the distributed portion of Erlang just yet. One node can handle millions of Erlang processes, and you can understand the model just fine by working on a single node. Processes and nodes are different concepts, so don't get them confused.

Nodes are isolated from each other, but Erlang has many facilities for communicating between them. You don't have to write any code to enable communication, it's a built in feature.

A simple demo of this can be done extremely simply:

  1. Open 2 terminals
  2. In terminal 1, start Erlang with a short name: erl -sname hi
  3. In terminal 2, start Erlang with another name: erl -sname hi2
  4. The shell will show you what your nodes are now called:

    Terminal 1:

    Erlang/OTP 18 [erts-7.1] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
    
    Eshell V7.1  (abort with ^G)
    
    (hi@kwong-mbp)1>
    

    Terminal 2:

    Erlang/OTP 18 [erts-7.1] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
    
    Eshell V7.1  (abort with ^G)
    (hi2@kwong-mbp)1>
    
  5. I can now get the nodes to ping each other:

    (hi2@kwong-mbp)1> net_adm:ping('hi@kwong-mbp').
    pong
    
  6. If I list the nodes hi@kwong-mbp knows about, the other node will now show up:

    (hi@kwong-mbp)1> nodes().
    ['hi2@kwong-mbp']
    

Erlang nodes use another daemon to figure out what Erlang nodes are running on a machine. When a node is looking for a node on another host, it asks the host machine's epmd instance for the information needed to connect.

like image 98
kjw0188 Avatar answered Sep 22 '22 19:09

kjw0188