[erlang-questions] to supervise or not to supervise

Mihai Balea <>
Fri Mar 20 22:31:27 CET 2009


On Mar 20, 2009, at 3:42 PM, steve ellis wrote:

> New to supervision trees and trying to figure out when to use them  
> (and when not to)...
>
> I have bunch of spawned processes created through spawn_link. Want  
> these processes to say running indefinitely. If one exits in an  
> error state, we want to restart it N times. After N, we want to  
> error log it, and stop trying to restart it. Perfect job for a  
> one_to_one supervisor right?
>
> Well sort of. The problem is that when the max restarts for the  
> error process is reached, the supervisor terminates all its children  
> and itself. Ouch! (At least in our case). We'd rather that the  
> supervisor just keep supervising all the children that are ok and  
> not swallow everything up.
>
> The Design Principles appear to be saying that swallowing everything  
> up is what supervisors are supposed to do when max restarts is  
> reached which leaves me a little puzzled. Why would you want to kill  
> the supervisor just because a child process is causing trouble?  
> Seems a little harsh.
>
> Is this a case of me thinking supervisors are good for too many  
> things? Is it that our case is better handled by simply spawning  
> these processes and trapping exits on them, and restarting/error  
> logging in the trap exit?

As far as I know, the standard supervisor cannot behave the way you  
want it to.

So, at least until this type of behavior is added to the standard  
supervisor, you can work around it with double layers of supervision.  
Basically have one dedicated supervisor for each process you want to  
supervise and, in turn, each dedicated supervisor is set up as a  
transient child to one big supervisor.

Mihai



More information about the erlang-questions mailing list