Search code examples
erlangerlang-otp

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


I'm new to erlang, I'm looking at some of the documentation on starting a supervisor http://erlang.org/doc/man/supervisor.html#start_link-3

The start_link/3 function has a possible return of

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

The documetation says:

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.

What does it mean to be registered locally vs globally?


Solution

    • local: register your pid only for your local node, you can use same name on other nodes if you have an Erlang cluster.
    • global: register this name for all your Erlang cluster, and alert each node about this name.

    From 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.

    This feature works for all standard OTP behaviour when you start your process.