Hi, elixir programmers (and at first I hope you would excuse my English),
I’m developing a backend server for a video game project. It is basically a real-time multi-agent simulation. Agents are implemented as GenServer, and of course, I make intensive use of Supervisor, DynamicSupervisor, and Registry. That part is fine. I now struggle trying to make multiple simulations under the same supervision tree. The idea is to have a GameSupervisor that can spawn a new instance of the simulation. Each instance is a Supervisor that has some DynamicSupervisor that manage GenServer. Each simulation is totally closed to the outside (eventually, I’ll have to connect the simulations to a socket dispatcher).
The issue that I now encounter is for “dynamic” DynamicSupervisor, and “dynamic” Registry. These ones need to have a proper name, but it can only be atoms. So I’m trying to figure out how to deal with this problem.
My current solution (which is absolutely not optimal, you’ll see why) it create, for Supervisor and Registry only, on runtime atoms, from strings. Agents (GenServer) are registered using Registry mechanism. It could be fine (I won’t create thousands of instances at the same moment) but it will eventually reach the atom number limit.
Here is a picture of an example process diagram that I use now. Elixir.Game is an application, it starts and Instance.Registry and a Game.Supervisor which is a DynamicSupervisor. There, I can spawn an instance (<0.474.0> or <0.510.0>) which are supervisors. Every following node that begins with “Instance*_” is either a Supervisor or a Registry, that have a dynamic name (strong to atom conversion). And then DynamicSupervisors spawn Agents which are registered into the Registry.
(It appear that I don’t have rights to upload images, so here is the link https://asylamba.com/public/media/files/sources/asylamba-build-diagram.png)
What would be the Elixir way of achieving that?