談談 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

相關文章
相關標籤/搜索