谈谈 epmd

在《Erlang/OTP 并发编程实战》中,对 epmd 有以下描述: css

  • epmd  表明 Erlang 端口映射守护进程(Erlang Port Mapper Daemon)。
  • 每启动一个节点,都会检查本地机器上是否运行着 epmd ,若是没有,节点就会自行启动 epmd 。
  • epmd 会追踪在本地机器上运行的每一个节点,并记录分配给它们的端口。
  • 当一台机器上的 Erlang 节点试图与某远程节点通讯时,本地的 epmd 就会联络远程机器上的 epmd(默认使用 TCP/IP 端口 4369),询问在远程机器上有没有叫相应名字的节点。若是有,远程的 epmd 就会回复一个端口号,经过该端口即可直接与远程节点通讯。
  • epmd 不会自动搜索其余 epmd ,只有在某个节点主动搜寻其余节点时通讯才能创建。 

在《Learn You Some Erlang for Great Good!》中有以下描述: node

When you start a node, you give it a name, and it will connect to an application called Erlang Port Mapper Daemon (EPMD), which will run on each of the computers that are part of your Erlang cluster. EPMD will act as a name server that lets nodes register themselves, contact other nodes by name rather than port numbers, and warn you about any name clashes.
If you need to go through a firewall with distributed Erlang (and do not want to tunnel), you will likely want to open a few ports here and there for Erlang communication. In this case, you should open port 4369, the default port for EPMD. It’s a good idea to use this port, because it has been officially registered for EPMD by Ericsson. This means that any standards-compliant operating system you use will have that port free, ready for EPMD.

 

Erlang 中和 epmd 相关的文件


在 otp_src_xxx\erts\epmd\  中,实现了 epmd 服务程序和 epmd 命令行程序。 

【epmd.c】 
linux

  • 函数 epmd_dbg 是对函数 epmd 的封装,便于在 debug 模式下使用 epmd ;
  • 给出了如何在 linux 和 windows 上实现 daemon 函数,以及与 syslog 的配合;

【epmd.h】 
定义了 epmd 所采用协议的消息编码(C语言侧定义)。 

【epmd_int.h】 
针对跨平台函数和变量进行定义。 

【epmd_cli.c】 
实现了 epmd 命令行功能所需的的 API 调用。 

【epmd_srv.c】 
编程

  • 基于 select 实现了 epmd 服务程序的事件驱动主循环;实现了针对上述 epmd 协议的解析。服务模型为一问一答式。
  • 经过对 select 超时时间的约束(最大 5s),模拟了 busy server 的 delay_accept 和 delay_write 功能。


在 otp_src_xxx\lib\kernel\src\ 中,在 erlang 代码层面实现了与 epmd 服务程序的协议交互。 

【erl_epmd.erl】 
基于 gen_server 行为模式、采用 TCP socket 方式与本地或远端 epmd 进行协议通讯的实现。 

【erl_epmd.hrl】 
定义了 epmd 所使用协议的消息编码(Erlang 语言侧定义)。 


在 otp_src_xxx\lib\erl_interface\src\epmd\ 中,与 erlang 层实现对应的底层 C 实现。 

【ei_epmd.h】 
常量定义。 

【epmd_port.c】 
经过 TCP socket 链接本地或远端 epmd ,并经过协议 EPMD_PORT2_REQ 获取 the distribution port of another node 。 

【epmd_publish.c】 
经过协议 EPMD_ALIVE2_REQ 向隐藏 node 发布自身的 listen port 和 alive name。 

【epmd_unpublish.c】 
经过协议 EPMD_STOP_REQ 中止指定名字的 node。 
windows

 

EPMD Protocol


erts-5.9.2 中的内容 

 
 

 

 

 

 

 

 

 

 


erts-7.1 中的内容 
10 
 
11 
并发

 

12 
 
13 
 
14 
 
15 
 
16 
 
17 
 app

相关文章
相关标签/搜索