[erlang-patches] Add supervisor:start_child/3 to limit the number of children

Vance Shipley vances@REDACTED
Wed Apr 10 14:08:12 CEST 2013


On Tue, Apr 09, 2013 at 04:10:27PM +0200, Siri Hansen wrote:
}  Is this feature mostly for use with simple_one_for_one supervisors? 

My current use case scenario is, yes.

}  I believe (possibly faulty??) that these are the most common supervisor for
}  which many children are repeatedly restarted as a part of normal execution.

Yes, I would agree.

}  Could you say something more about your use case? Other input on this?
  
In my case we are creating a child worker process to manage the lifecycle 
of a transaction.  We process thousands of transactions per second.  A 
transaction may take tens of milliseconds or tens of seconds.  We require
a limit on the number of possible ongoing transactions.

}  Regarding the implementation, one could say that the behavior differs a
}  little bit for different types of supervisors and child restart types.

It differs a little bit.  My description was:

   "If Limit or more children are already specified for the supervisor
    start_child/3 returns {error,child_limit}."

My implementation counts the child specifications.

}  * simple_one_for_one supervisor (all child restart types) -> Limit is
}  compared to the number of alive children.
}  * other supervisor type, temporary children -> Limit is compared to the
}  number of alive children.
}  * other supervisor type, non-temporary children -> Limit is compared to the
}  number of child specs.
  
Effectively yes, however it's really just the number of child_spec() as
we are not using is_process_alive/1 to prove it.  Really it's a limit on
the number of child_spec() which may exist.

}  The very least we need to consider is if this is the correct behavior, and
}  if so I think it needs to be mentioned in the documentation. Or should the
}  feature be restricted to simple_one_for_one supervisors (or is it only me?)?

I didn't see any reason to restrict it to simple_one_for_one supervisors.
You could use supervisor:start_child/2 to add thousands of children to a
one_for_one supervisor.  If you were doing that you might just want to 
limit the number of such child_spec() being added.

What do you think about Richard's suggestion that start_child/3 should
take an Options::list() argument instead with {child_limit, N::pos_integer()}
as the only currently defined option?

-- 
	-Vance



More information about the erlang-patches mailing list