在erlang中注册全局和本地主管有什么区别

What the difference between registering a global and local supervisor in erlang

我是 erlang 的新手,我正在查看一些关于启动 supervisor 的文档http://erlang.org/doc/man/supervisor.html#start_link-3

start_link/3 函数可能有 return 个

{local, Name :: atom()} |
{global, Name :: atom()} |

文档说:

If SupName={local,Name}, the supervisor is registered locally as Name using register/2.
If SupName={global,Name}, the supervisor is registered globally as Name using global:register_name/2.

本地注册和全球注册分别是什么意思?

  • 本地:只为本地节点注册你的 pid,如果你有 Erlang 集群,你可以在其他节点上使用相同的名称。
  • global:为你所有的 Erlang 集群注册这个名字,并提醒每个节点这个名字。

来自global:register_name/3

When new nodes are added to the network, they are informed of the globally registered names that already exist. The network is also informed of any global names in newly connected nodes. If any name clashes are discovered, function Resolve is called. Its purpose is to decide which pid is correct. If the function crashes, or returns anything other than one of the pids, the name is unregistered. This function is called once for each name clash.

此功能适用于您启动流程时的所有标准 OTP 行为。