[erlang-questions] beginner architectural question

semmit mondo semmitmondo@REDACTED
Tue Nov 11 10:24:25 CET 2014

Hi, I have an application with a structural pattern that comes up again andagain, and I would like to ask you how would you solve this.  My app hastwo kinds of processes:  a singleton that is a server collecting data, andworkers that do some calculation and send the result to the server.There can be any number of workers and there's usually one datacollector server.  I think this is a very simple and common architecture.The problem with this is that the calculators have to know the pid of thecollector and the whole thing has to be supervised. The simplest solution is that under a main supervisor I spawn the collectorserver and register it with a name.  Next to the collector I start anothersupervisor that manages the pool of the calculators and those processessimply use the collectors name as the message destination when they'redone with the jod.  The main supervisor uses one_for_one strategy, whilethe subsupervisor is a simple_one_for_one. I feel that this is not the best I c
 ould do.  Another solution could be touse rest_for_one in the top supervisor, not register a name for thecollector, but push down the pid of the top supervisor to the sub-supervisor, and then in the init function of the sub-supervisor I canask the top supervisor (with a which_children() call) to give me thepid of the collector.  So I can give it to the calculators as an argument.Seems a bit difficult, but has the benefit not using a registered namefor a purely internal use case. There's also a wrong solution with a top supervisor with no staticchildren.  In that case I can start the children manually.  First I canstart the collector, then I have got the pid of it and can use it whenstarting the calculators.  The problem here is that when the collectorgets restarted, the calculators won't have the right pid.  Even if thetop supervisor uses rest_for_one strategy, and the calculators getrestarted, there's no mechanism to start calculators with the newpid of the collector.  
 (I can't give the supervisor a function !
 thatdescribes the way how to restart the whole thing, can I?) This wrong approach can be fixed if the top level supervisor exitswhen the collector or the sub-supervisor fails (that's a {one_for_one,0, 1} supervisor setup) and a plus layer of supervision above thissupervisor gets into play.  But that's just too many layers andsupervisors for a simple thing like this, am I right? I believe that the whole thing boils down to that I have not muchcontrol over the order of child starts and I can't move informationbetween children of the same supervisor.  It would be nice if asupervisor could supply some sort of a local name registry for theprocesses below them but as far as I know there's only a global(node local) one that could be used here. Which architecture would you choose?  Are there other alternativestructures I haven't thought of?  What do you thing which one is thebest approach and why? I'm sorry for the long and beginner question. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20141111/f598cac2/attachment.htm>

More information about the erlang-questions mailing list