Supervisor starts children in parallel
Ulf Wiger
ulf.wiger@REDACTED
Tue Dec 2 09:46:53 CET 2003
On Mon, 01 Dec 2003 21:19:21 +0100, Lennart Öhman <lennart.ohman@REDACTED>
wrote:
> Hmm,
> the next child is not supposed start until the previous ones init-phase
> has acknowledged back to the supervisor (i.e my_callback_modle:init(...)
> has returned {ok,DataStructure}.
>
> Some people wanting a more concurrent start usually make their init
> phases empty and keep a state in the DataStrcture. They then send a
> cast to change that state into "operational mode" for the worker process
> in some kind of order which is not equavalent to the start-order.
Since the topic of complex start dependencies was brought up...
The suave OTP way to do this is to use start phases.
You start your processes with minimal work done in the init functions,
then you write some code in the application callback module.
In the .app file, you fill in the start_phases attribute
{mod, {MyMod, Args}},
{start_phases, [{Phase, PhaseArgs}|...]}
Then, the function MyMod:start_phase(Phase, Type, PhaseArgs)
will be called once the processes are started.
From here, you can make gen_server calls to your processes
in an orderly fashion, and perhaps finish off by globally
registering the processes. Everything is synchronous, and since
the start_phase function executes in a separate process (the
application starter process), it can talk to all the worker
processes without locking problems or race conditions.
See erl -man application for details.
/Uffe
--
Ulf Wiger, Senior System Architect
EAB/UPD/S
More information about the erlang-questions
mailing list