bastion
bastion copied to clipboard
Registry for active actors
Is your feature request related to a problem? Please describe. In Elixir / Erlang languages developers has a universal way to register running actors in the system and communicate with them depends of the required use case, for example:
- Communication between the actors is more preferable by names rather then by id, because the id can change in runtime (due unexpected restarts, killing by the supervisor, etc.).
- Has a requirement to broadcast to the certain group of actors defined by a custom dispatching rule or with the usage of PubSub.
- Has a necessity to store properties that can be shared across the actors.
- Can be used as the part of the hot-code swapping feature.
For an inspiration you can look into the current Elixir documentation for registry usage with examples.
Describe the solution you'd like
Use one of available registries out-of-the-box (like in Elixir), initialize and then pass it in the Bastion struct for the usage in the cluster after the start.
However, it also requires to have at least:
- Auto-remove from registries failed / stopped / killed actors
- An implementation of bunch of methods for getting access to the desired registry
- Default trait(s) for any registry for interacting from the actor
Describe alternatives you've considered
Usage of the lazy_static! macro with other any available collections to use (wrapped in Arc's hashmaps/vectors, concurrent collections) for organizing desired communication and sharing data.
What about implementing a registry based on the evmap / ccl crates? Also I think it makes a sense to share my ideas about implementation details:
- Start from the simple case: automatic registration/deletion for actors after creating or being stopped/killed.
- Any actor has an access to this init registry via the registry name, because in the future systems could be organized in the clusters, so that it will make it much easier to handle later on.
- The base registry for handling active actors should be added to the main Bastion struct and will be private field.
- Each actor after it starts, must send a information to the main registry with declaring the used module and function name (e.g. something like (actor_id, my_module::main, "main_func"). This part of the feature will help us not only to handle the active actors, but also build custom dispatch rules on the top of that.
Popping in here, for context. ccl is now deprecated in favor of the dashmap crate.
We were talking about this on Discord, we will go with either dashmap or flurry.