4
votes

I have an Erlang application which runs a supervisor behaviour. Now I want to distribute it across different nodes, meaning that the supervised processes should run on different computers.

Although I read the OTP documentation, I haven't grasped how to configure my app to do this.

Currently, the .app file looks like this:

{application, my_application,
[{description, "My Description"},
 {vsn, "1"},
 {modules, [my_application, my_supervisor, supervised_process, my_monitor]},
 {registered, [my_supervisor]},
 {applications, [kernel, stdlib]},
 {mod, {my_application,[]}},
 {env, [{file, "/usr/local/log"}]}
]}.

If I have two computers running named Erlang VMs, how do I configure the app to run some supervised_processes on both computers?

1

1 Answers

0
votes

Once each Erlang VM is running on the same internal network with the same Erlang cookie, you can use the net_adm module to check that the other node is present and the rpc module to communicate between them.

Here is an example of checking if the other node is responding and sending a synchronous message to it:

 Remote = app2@localhost,
 pong = net_adm:ping(Remote),
 ok = rpc:call(Remote, supervised_process, do_something, []).

As far as I know you can't have a supervisor on one node supervise processes on another node. You can only control other nodes via messages.