[erlang-questions] How to structure a manager/worker structure

paul erlang pc.erlang@REDACTED
Fri Jun 15 09:05:58 CEST 2007


Hi Ulf,

Thanks for your response, I will try to go with the additional
simple_one_for_one
supervisor. I can't really generate the child start specification for
the workers in init/1
since I want their number to be variable even at runtime.

Given the fact that I also have a "meta-manager" that will take care
of the various
managers (each manager beings specialized in a certain kind of data), my project
structure is starting to be really hairy, but there's not a whole lot
I can do about it.

Paul

On 6/14/07, Ulf Wiger <ulf@REDACTED> wrote:
> You can't talk to the supervisor while it is busy starting
> a process, since the start procedure is synchronous.
>
> One way to solve it is to generate child start specifications
> for the manager _and_ the workers in the supervisor's
> init/1 function.
>
> A better way might be to have the supervisor start
> first a simple_one_for_one supervisor for the workers,
> and then the manager. The manager can then call
> on the simple_one_for_one supervisor to start the
> workers, which, presumably only differ in the start
> arguments.
>
> BR,
> Ulf W
>
> 2007/6/14, paul erlang <pc.erlang@REDACTED>:
> > Hi,
> >
> > I am trying to set up a structure where I have some generic workers
> > (gen_server  processes
> > driving ports) and a manager (another gen_server process.)
> > The manager is responsible for creating the workers and assigning work
> > to them, as required (there is a queue of work handled by the
> > manager.)
> >
> > I would like all this to be supervised by one supervisor. I thought of
> > doing it the following way:
> >
> > 1. Add the manager "statically" when creating the manager_supervisor.
> > 2. Pass the manager_supervisor pid as a parameter to the manager, for
> > the manager's initialization procedure.
> > 3. In the manager "init" method, I want to do as many "start_child" as
> > required on the same supervisor that is overseeing the manager. This
> > would allow me to have the manager static in the supervisor and the
> > "workers" dynamic.
> >
> > However, if I call "start_child" from the manager's "init", the system
> > locks when "start_child" is executed.
> >
> > Is there any limitation against calling "start_child" on a supervisor,
> > while the supervisor is initializing another child process?
> >
> > If so, what is the best way to accomplish what I am trying to do here?
> > Should I have a process that is executing the "start_child" for the
> > workers in one second (to allow the supervisor to finish the
> > initialization of the static children)?
> >
> > Or am I approaching all this in the wrong way? As you can guess, I'm
> > somewhat of a newbie, trying to understand both Erlang and OTP.
> >
> > Thanks,
> >
> > Paul
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questions@REDACTED
> > http://www.erlang.org/mailman/listinfo/erlang-questions
> >
>



More information about the erlang-questions mailing list