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

paul erlang <>
Thu Jun 14 08:58:42 CEST 2007


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



More information about the erlang-questions mailing list