I have a supervisor structure that needs a supervisor per (TCP) connection. Now it seems that each supervisor requires it's own unique name, which in turn needs to be an atom (at least that's what I'm gathering from the error messages).
A workaround would be to generate a new atom each time, similar to a suggestion from the erlang-questions list.
Now I learned that atoms are never cleaned up, so there's the possibility of being DoSed by too many connections, exhausting the atom space. How is this done properly?
There are two types of names involved here, registered names for processes and identifiers for supervisor children.
It's not necessary to have a registered name for each supervisor process. There are two functions for starting a supervisor process, supervisor:start_link/2
and supervisor:start_link/3
. start_link/3
starts the supervisor and registers it under the given name, while start_link/2
starts the supervisor without registering a name for it. (If the process doesn't have a registered name, the only way to refer to it is via its pid.)
As for identifiers for supervisor children, if you have a supervisor that will have an unbounded number of child processes (regardless of whether those child processes are workers or supervisors), you'd normally use the special restart type simple_one_for_one
. That means that instead of keeping a list of static child specifications (either returned from the init
callback function or added with the supervisor:start_child
function), the supervisor has a single "template" child specification, and the supervisor:start_child
function creates "anonymous" children based on that template.