在Erlang中,是否可以将正在运行的进程发送到不同的节点?
我一直在研究移动代理,并且想知道是否可以将正在运行的进程发送到 erlang 中的另一个节点。我知道可以向另一个节点上的进程发送消息。我知道可以在集群中的所有节点上加载模块。是否可以将特定节点上可能处于某种状态的进程移动到另一个节点并恢复其状态。即erlang提供强大的移动性吗?或者erlang是否可以提供强大的可移动性?
I have been researching Mobile Agents, and was wondering if it is possible to send a running process to another node in erlang. I know it is possible to send a process on another node a message. I know it is possible to load a module on all nodes in a cluster. Is it possible to move a process that might be in some state on a particular node to another node and resume it's state. That is, does erlang provide strong mobility? Or is it possible to provide strong mobility in erlang?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这是可能的,但是没有“将进程移动到节点”调用。但是,如果进程是使用迁移功能构建的,那么您当然可以通过将进程的功能及其状态发送到另一个节点并在那里安排生成来实现。为了获得正确的进程标识,您需要使用全局进程注册表或 gproc,因为进程会更改pid。
还有其他考虑因素:该进程可能正在使用其数据不存在于其他节点上的 ETS 表,或者它可能已在进程字典中存储了内容(例如来自随机模块的状态)。
Erlang 中的普遍共识是进程不会在机器之间移动。相反,如果节点死亡,可以安排节点之间接管应用程序。或者对于系统的分发,数据已经分发到另一台机器。无论如何,无论是否具有移动性,在发生错误时保持状态持久化的主要问题仍然存在,而分布式是解决持久性问题的一个很好的工具。
Yes, it is possible, but there is no "Move process to node" call. However, if the process is built with a feature for migration, you can certainly do it by sending the function of the process and its state to another node and arrange for a spawn there. To get the identity of the process right, you will need to use either the global process registry or gproc, as the process will change pid.
There are other considerations as well: The process might be using an ETS table whose data are not present on the other node, or it may have stored stuff in the process dictionary (state from the random module comes to mind).
The general consensus in Erlang is that processes are not mobilized to move between machines. Rather, one either arranges for a takeover of applications between nodes should a node die. Or for distribution of the system so data are already distributed to another machine. In any case, the main problem of making state persistent in the event of errors still hold, mobility or not - and distribution is a nice tool to solve the persistence problem.