Decoupling supervisor:start_child from a web front end

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Decoupling supervisor:start_child from a web front end

Andy Richards
Hi all,

What the most appropriate way of calling supervisor:start_child on a remote node when the supervisor module does not exist locally?

I have a scenario where I have a webmachine web front end which needs to spawn a child process via a supervisor on a backend middleware node. My supervisor exists on my target middleware node so I could call from my web tier either...

supervisor:start_child({Name, Node}, [list_of_terms])

...however this duplicates the code in my own target supervisor module start_child function and feels as though I'm coupling my middleware to my front end should my supervisor start_ child function ever change? or I could call...

rpc:call(Node, Module, Function, [Args])

...but this feels a bit clunky and I'm unsure if there is additional overhead with rpc:call compared to the above approach?

What's the best approach ?

Many thanks,

Andy.

Reply | Threaded
Open this post in threaded view
|

Decoupling supervisor:start_child from a web front end

Samuel Elliott
So the supervisor callback module already has a method where you can
get it to start its children? Add another method that allows you to
specify the node/supervisor it should start it off (rather than just
the local one).

The other option is to register the supervisor globally, and then make
your callback module also have a function to start it wherever it is -
the advantage of this is for testing you should be able to pull
everything onto the same node, to save a complex test harness launch
procedure. However, if you have lots of these supervisors, global
registration isn't an option.

Sam

On Wed, May 9, 2012 at 9:58 AM, Andy Richards
<andy.richards.iit> wrote:

> Hi all,
>
> What the most appropriate way of calling supervisor:start_child on a remote node when the supervisor module does not exist locally?
>
> I have a scenario where I have a webmachine web front end which needs to spawn a child process via a supervisor on a backend middleware node. My supervisor exists on my target middleware node so I could call from my web tier either...
>
> supervisor:start_child({Name, Node}, [list_of_terms])
>
> ...however this duplicates the code in my own target supervisor module start_child function and feels as though I'm coupling my middleware to my front end should my supervisor start_ child function ever change? or I could call...
>
> rpc:call(Node, Module, Function, [Args])
>
> ...but this feels a bit clunky and I'm unsure if there is additional overhead with rpc:call compared to the above approach?
>
> What's the best approach ?
>
> Many thanks,
>
> Andy.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions
> http://erlang.org/mailman/listinfo/erlang-questions



--
Samuel Elliott
sam
http://lenary.co.uk/
+44 (0)7891 993 664