9

我想用 Erlang 写一个主从应用程序。我正在考虑架构中需要的以下内容:

  • 当主节点死亡时,从节点不应该死,而是在主节点关闭时尝试重新连接到它

  • 如果远程节点未自动连接或已关闭,主节点应自动启动远程节点(可能是OTP中的主管行为)

是否有面向 OTP 的行为来执行此操作?我知道我可以使用 启动远程节点,slave:start_link()也可以使用 监控节点erlang:monitor(),但我不知道如何将其合并到gen_server行为中。

4

2 回答 2

1

I agree with the comments about using erlang:monitor_node and the use of distributed applications.

You cannot just use the slave module to accomplish that, it clearly states "All slave nodes which are started by a master will terminate automatically when the master terminates".

There is currently no OTP behaviour to do it either. Supervision trees are hierarchical ; it seems like you are looking for something where there is a hierarchy in terms of application logic, but spawning is done an a peer-to-peer basis (or an individual basis, depending upon your point of view).

If you were to use multiple Erlang VMs then you should carefully consider how many you run, as a large number of them may cause performance issues due to the OS swapping OS processes in and out. A rule of thumb for best performance is to aim for having no more than one OS process (i.e. one Erlang VM) per CPU core.

于 2011-01-03T19:21:49.983 回答
1

如果您对研究其他实现感兴趣,Basho 的riak_core框架对去中心化分布式应用程序有很好的了解。

riak_core_node_watcher.erl包含大部分有趣的节点观察代码。

搜索一下,你会发现有很多关于框架的演讲和演示

于 2011-01-10T14:48:29.533 回答