Is there a maximum number of child processes a supervisor process can supervise? I'm coming from Elixir, but I imagine the limit (if there is one) would be inherited directly from Erlang.
2 Answers
I'm no expert but found this in the erlang docs:
10.2 System limits
The Erlang language specification puts no limits on number of processes, length of atoms etc., but for performance and memory saving reasons, there will always be limits in a practical implementation of the Erlang language and execution environment.
Processes
The maximum number of simultaneously alive Erlang processes is by default 32768. This limit can be raised up to at most 268435456 processes at startup (see documentation of the system flag +P in the erl(1) documentation). The maximum limit of 268435456 processes will at least on a 32-bit architecture be impossible to reach due to memory shortage.
This doesn't mention gen_server
but it puts an upper bound on the number of concurrent processes in a default erlang system: 32768
. So perhaps the answer to your question is simply 32768 - 1
. :) And you can use the +P switch to increase that number.
-
In the book
Erlang Programming
, early on they have you start 4 million processes on your laptop. As I remember, they took about 45 seconds to spin up.– 7studAug 7, 2019 at 3:04 -
@7stud That is so cool. Especially since that’s, as you said, early on in the book. Good luck doing that anywhere else! :) Were all those processes under a single supervisor? Aug 7, 2019 at 7:04
-
@AshtonWiersdorf, No supervisor. Each process waits in a receive for message that will cause the process to break out of the receive and end.– 7studAug 9, 2019 at 3:48
-
Thank you for your answer! I’m marking the other one as accepted because they answered specifically about supervisor limits. I upvoted yours though because it is still relevant to the question. I wish I could mark them both. :-/ Thanks again! Aug 14, 2019 at 14:02
gen_server
itself doesn't impose any particular restriction on the number of processes it can manage (apart from system limits) but if you add large enough amounts of children, you will (of course) eventually run into performance issues. gen_server
tries to be efficient regarding large number of children by e.g. not storing them in a linear list.
(If you really need to know the exact answer, you're probably designing your system in a suboptimal way, I would say.)
-
This is mostly a curiosity-driven question—I'm not actually building something where I need ONE supervisor to watch all processes. :) Do you have a link to documentation on this? Aug 13, 2019 at 20:51