Supervisor hierarchy question

Chandrashekhar Mullaparthi chandrashekhar.mullaparthi@REDACTED
Mon Jan 17 13:03:00 CET 2005


Eric,

Whenever we need to dynamically create child processes which need to be 
supervised we put them under their own supervisor.


     +----------------------------------------------------------------+
     |                                                                |
     |                    Supervisor                                  |
     +----------------------------------------------------------------+
         /       |      |       |          |           |         |
        /        |      |       |          |           |         |
       /         |      |       |          |           |         |
     System     CP1   CP2  CP1_C1_Sup  CP1_C2_Sup CP2_C1_Sup CP2_C2_Sup
                                |           |           |         |
                                |           |           |         |
                             CP1_C1       CP1_C2     CP2_C1     CP2_C2


If CP1 and CP2 are also created dyanmically, I would put them under 
their own supervisor. The restart strategy, in the top level 
supervisor, for each CPm_Cn_Sup should be transient so that if that 
particular connection misbehaves, the rest of them are unaffected.

You should probably maintain an ETS table which has a mapping from 
connection pool name to process id or have a fixed naming convention so 
that you can generate the name - asking the top level supervisor sounds 
a bit of a bodge.

cheers
Chandru

On 15 Jan 2005, at 04:09, Eric Merritt wrote:

> Guys,
>
>  I am finishing up an implementation of a client for postgresql.
> Overall was pretty simple, the protocol is well documented and Erlang
> is geared for this stuff. However, I do have a couple of questions
> about my supervisor hierarchy.
>
>  Here is how things are set up.
>
> A Supervisor that watchs the top level system process.
>
> The system process implements gen_server and accepts requests for new
> connection_pools and requests for the Pid of an existing connection
> pool. When the system process launches a new pool it uses the
> start_child function for its parent supervisor.  So the hierarchy
> looks like
>
>          Supervisor
>        /            |         \
>       System   CP1   CP2
>
> The thing I don't like about this is that when the system process gets
> a request for a pid it calls which_system on its supervisor and
> scrolls through the list to find the connection_pool by name. This
> kind of parent pointer 'smells' bad.
>
>  Now when the connection_pool gets a request for a connection it needs
> return the PID of an active connection.  If non are available it needs
> to return an error or start a new one depending on its setup.
>
>  This is my question. When the connection_pools starts up its initial
> set of connections where should it put them, under another supervisor?
> If so what should supervise the supervisor? Should it look like this?
>
>
>
>          Supervisor
>        /            |         \         \                       \
>       System   CP1   CP2    CP1-Conn-Sup   CP2-Conn-Sup
>
> Or should it just create a supervisor without an explicit parent 
> supervisor.
>
>
> I hope this is intelligible to you all. Any suggestions are 
> appreciated.
>
> -- 
> I'm a programmer, I don't have to spell correctly; I just have to
> spell consistently
>




More information about the erlang-questions mailing list