SIDS - An Actor Model Approach to Data Collection in RUST
This is an experimental actor-model system library built in rust. The repository has a few Mermaid diagrams and exxamples available for you to examine if you are interested in implementing the approach yourself.
Getting Started
Run the example logging demonstration.
git clone https://github.com/professor-greebie/sids
cd sids
cargo run --example loggers
What this does
This project demonstrates a simple approach to building actors in Rust, allowing for some abstraction between Tokio-type and blocking actors.
This is still a project in development, but it does illustrate how you might develop an actor system from scratch in Rust.
Basic Concepts:
An actor - an actor implements an Actor Trait to include a receive function that accepts a message type of Message<MType>.
The Message struct covers the most common Actor behaviors (stop, responses etc.), but you can add more as part of the payload, which is of type MType.
MType can be any base type (String, u32 etc.) or an enum provided that it has Send features and can have static lifetime. Enums are powerful in Rust, so they are highly recommended. See the Rust documentation on enum types for more information
Once you choose an MType, then the ActorSystem will use the same message type throughout the system. Currently, only one MType is allowed, however, with Rust's enums, there is a lot of capacity for variance on the types of messages that can be sent.
let mut actor_system = ;
Starting an actor system initializes the system and runs a 'boss' actor called the Guardian with an id of 0. You can ping the boss using sids::actors::ping_actor_system(&actor_system);
You can add an actor to the system, by creating a structure that implements the Actor trait. All actors in the system must receive a Message.
use Actor;
use Message;
use info;
// you can include some attributes like a name if you wish
;
,
async
Officers will be kept in a vector in the GuardianActor, so its id will be as per the index. In future there will be a better approach to capturing actors by name or type. To send a message to this actor, you simple do:
send_message_to_officer_enum;
Actors may also be blocking in case you need that for collecting data from an http response or something else that requires thread blocking in order to operate. Blocking actors are kept in their own Vector, so indices will need to account for that (for now).
The Future
From a prototype perspective, this is final version of this project, except for performance and safety tweaks.
We will also include some more advanced examples, including using the Actor System to do Actor-Critic Machine Learning work.
Citations
The following resources helped me a lot during the building of this demonstration.
- Mara Bos (2023) Rust Atomics and Locks: Low-level concurrency in Practice. O'Reilly Press.
- Alice Ryhl (2021) Actors with Tokio [Blog Post].