<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jul 28, 2016 at 7:47 AM, Giovanni Giorgi <span dir="ltr"><<a href="mailto:jj@gioorgi.com" target="_blank">jj@gioorgi.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Now the question is: Is a correct approach?</blockquote></div><br></div><div class="gmail_extra">The key observation is: "How do you want to handle error in the processes?" That is, you have a Main process and several Ticker processes. What should happen if the Main process crashes or goes away? What should happen if a Ticker process crashes or goes away? This can guide a solution.<br><br></div><div class="gmail_extra">You could simply run the tickers as Torben suggests and then spawn_link them under the main process. This means, by default, if any ticker or the main process crashes, so does everyone else.<br><br></div><div class="gmail_extra">You could also use an asymmetric solution: spawn_monitor the tickers and have the tickers monitor the main process. This allows you to handle the case where you want to restart a crashing ticker for instance, but you have to write the logic yourself.<br><br></div><div class="gmail_extra">In general, spawning processes without knowing where they are only works for processes which are guaranteed to terminate. Otherwise, you end up with process leaks.<br><br></div><div class="gmail_extra">The final solution is to use a supervision tree: have a main_sup with children MainProcess and TickerPool, the latter being a simple_one_for_one supervisor. Each ticker is added into the TickerPool with supervisor:start_child. It is the the most complex solution, but it has an advantage over the simpler methods: it encodes a *policy* in the supervisors for handling failure modes. That is, you can tolerate some tickers dying, but not too many before trying to restart larger parts of the system.<br><br></div><div class="gmail_extra">So the TL;DR is to think about the failure mode of the application and write it accordingly.<br></div><div class="gmail_extra"><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">J.</div>
</div></div>