idi527
Listing processes registered in Registry
Is there a way to list all the processes registered in Registry [0] with the help of via tuple?
There is a way to look up the pid for a given key. But I’d like to get all the processes registered in a particular registry. Maybe I can access its ets table(s) somehow? Or maybe I can register all those processes in a group somehow? But it’s only possible to use unique registries for via calls…
I was thinking about :listeners option on start_link [1] where I would add some genserver which would be storing the names of registered processes, but that would be duplication of data.
[0] https://hexdocs.pm/elixir/master/Registry.html
[1] https://hexdocs.pm/elixir/master/Registry.html#start_link/3
Most Liked
dom
If there’s a lot of rooms, I’d be more worried about the impact of sequentially messaging every single room process (which is what map + get_state does) than about the impact of duplicating the registration.
Have you considered using a duplicate registry, and registering directly in your room’s init rather than using :via? Then you could register with {id, title} as the value and get all the id/titles quickly without adding load to your processes.
josevalim
Registry.lookup/2 would return all entries under a given key for a duplicate registry.
dom
They’re synchronous, but if you call Room.start_link from multiple processes around the same time for the same id, they may all see Registry.match return [] and enter GenServer.start_link, rather than return {:error, {:already_registered, pid}}. There is a window between Registry.match and Registry.register. Unique registry does not have this problem since register also checks if it’s already registered in one atomic operation.







