简体   繁体   English

什么是Erlang节点?

[英]What is an Erlang node?

I see a definition in one of books about Erlang: 我在其中一本关于Erlang的书中看到了一个定义:

A node is a self-contained Erlang system containing a complete virtual machine with its own address space and own set of processes. 节点是一个独立的Erlang系统,包含一个完整的虚拟机,它有自己的地址空间和自己的一组进程。

But this raises more questions to me. 但这给我带来了更多问题。

What is a self-contained Erlang system? 什么是独立的Erlang系统?

As an example, do I spawn a new node by going to terminal and running erl shell ? 举个例子,我是通过转到终端并运行erl shell来生成一个新节点吗? Do I open multiple nodes by opening multiple terminals and running erl shell in each? 通过打开多个终端并在每个终端中运行erl shell ,我可以打开多个节点吗?

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? 如果这些是不同的节点,那么我是否将此方法视为分布式编程,并且应该深入研究该主题,以防我想独立运行和停止进程,然后连接它们?

A node is one instance of the Erlang virtual machine running. 节点是运行的Erlang虚拟机的一个实例。 If you're on linux and you list the processes, there will be one process for each node. 如果你在linux上并且列出了进程,那么每个节点都会有一个进程。

This means that when you start the vm on the terminal using erl , you are staring a new node every time. 这意味着当您使用erl在终端上启动vm时,您每次都在盯着一个新节点。

If you're writing an application, you generally don't need to worry about the distributed portion of Erlang just yet. 如果您正在编写应用程序,通常不需要担心Erlang的分布式部分。 One node can handle millions of Erlang processes, and you can understand the model just fine by working on a single node. 一个节点可以处理数百万个Erlang进程,您可以通过在单个节点上工作来理解该模型。 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. 节点彼此隔离,但Erlang有许多用于它们之间通信的工具。 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个终端
  2. In terminal 1, start Erlang with a short name: erl -sname hi 在终端1中,以短名称启动Erlang: erl -sname hi
  3. In terminal 2, start Erlang with another name: erl -sname hi2 在终端2中,以另一个名称启动Erlang: erl -sname hi2
  4. The shell will show you what your nodes are now called: shell将显示您现在调用的节点:

    Terminal 1: 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: 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: 我现在可以让节点相互ping通:

     (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知道的节点,那么另一个节点现在将显示:

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

Erlang nodes use another daemon to figure out what Erlang nodes are running on a machine. Erlang节点使用另一个守护进程来确定计算机上运行的Erlang节点。 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. 当节点在另一台主机上查找节点时,它会向主机的epmd实例请求连接所需的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM