Starting processes at remote nodes

Vance Shipley vances@REDACTED
Fri Jun 4 20:34:18 CEST 2004


Folks,

Is there a good reason why we don't have a proc_lib function
to synchronously start a process on a remote node?

Am I being naive about how well this works?


Background
----------

You can spawn a process on a remote node like this:

(foo@REDACTED)3> spawn('bar@REDACTED', io, fwrite, ["Hello World!~n"]).
Hello World!
<4183.42.0>

The proc_lib library supplies it's own version:

(foo@REDACTED)4> proc_lib:spawn('bar@REDACTED', io, fwrite, ["Hello World!~n"]).
Hello World!
<4183.43.0>

The generic behaviours in OTP are started synchronously using 
proc_lib:start_link/5.  When you run gen_server:start_link/3 your
process will execute proc_lib:start_link/5 to start the process
with gen_server:init_it/6.  This new process runs proc_lib:init_ack/2
to signal the calling process of the result.  Your process now
returns the result ({ok, Pid}).  

(foo@REDACTED)1> proc_lib:start_link(gen_server, init_it, [self(), self(), self(), server, [], []]).
{ok,<0.36.0>}


Proposal
--------

New functions:

	proc_lib:start(Node, M,F,A,Timeout,SpawnOpts)
	proc_lib:start_link(Node,M,F,A,Timeout,SpawnOpts)

We should add the same capability to the generic behaviours.

New functions:

	gen_server:start_link(Node, Name, Mod, Args, Options)
	gen_fsm:start_link(Node, Name, Mod, Args, Options)
	supervisor:start_link(Node, Name, Mod, Args)

	%%%    Node ::= node()

Extend the definition of Name to include none:

	%%%    Name ::= {local, atom()} | {global, atom()} | none


Application
-----------

Automatically distribute processes across several nodes.

For example:

-module(super).
-behaviour(supervisor).

init(_Args) ->
   StartArgs = [fsm, [], []],
   StartFunc = {start_link, start_link, StartArgs},
   ChildSpec = {fsm, StartFunc, transient, 4000, worker, [fsm]},
   {ok, {{simple_one_for_one, 10, 60}, [ChildSpec]}}.


-module(starter).
-export([start_link/4]).

start_link(Mod, Arg, Opt, Node) ->
   gen_fsm:start_link(Node, none, Mod, Arg, Opt).


(foo@REDACTED)3> supervisor:start_child(SupRef, [pool:get_node()]).
{ok, <4183.43.0>}


	-Vance


Vance Shipley
Motivity Telecom Inc.
+1 519 240 3684
vances@REDACTED



More information about the erlang-questions mailing list