启动远程 Erlang 节点

发布于 2024-09-07 14:49:55 字数 418 浏览 10 评论 0原文

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

  • 奴隶不应该在主人死亡时死亡,而是在主人死亡时尝试重新连接到它

  • 如果远程节点没有自动连接或关闭,主节点应该自动启动远程节点(可能是 OTP)

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

I want to write a master-slave application in Erlang. I am thinking at the following things I need from the architecture:

  • the slaves shouldn't die when the master dies, but rather try to reconnect to it while the master is down

  • the master should automatically start the remote nodes if they don't connect automatically or they are down (probably the supervisor behaviour in OTP)

Is there a OTP oriented behaviour to do this? I know I can start remote nodes with slave:start_link() and I can monitor nodes with erlang:monitor(), but I don't know how this can be incorporated in a gen_server behaviour.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

葮薆情 2024-09-14 14:49:55

我同意关于使用 erlang:monitor_node 和使用分布式应用程序的评论。

您不能仅使用从属模块来完成此任务,它明确指出“当主控终止时,由主控启动的所有从属节点将自动终止”。

目前也没有 OTP 行为可以做到这一点。监督树是分层的;似乎您正在寻找在应用程序逻辑方面存在层次结构的东西,但生成是在对等基础上完成的(或在个人基础上完成,具体取决于您的观点)。

如果您要使用多个 Erlang VM,那么您应该仔细考虑运行的数量,因为大量 VM 可能会因操作系统交换操作​​系统进程而导致性能问题。获得最佳性能的一条经验法则是每个 CPU 核心的操作系统进程不超过一个(即一个 Erlang VM)。

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.

孤檠 2024-09-14 14:49:55

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

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

搜索一下,你会发现有不少有关该框架的讨论和演示。

If you're interested in studying other implementations, Basho's riak_core framework has a pretty good take on decentralized distributed applications.

riak_core_node_watcher.erl has most of the interesting node observation code in it.

Search and you'll find there are quite a few talks and presentations about the framework.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文