談談 epmd


在《Erlang/OTP 並發編程實戰》中,對 epmd 有如下描述: 

  • 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!》中有如下描述: 

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】 

  • 函數 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。 

 

EPMD Protocol


erts-5.9.2 中的內容 

 
 

 

 

 

 

 

 

 

 


erts-7.1 中的內容 
10 
 
11 

 

12 
 
13 
 
14 
 
15 
 
16 
 
17 
 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM