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 examples available for you to examine if you are interested in implementing the approach yourself.
Getting Started
Run the example logging demonstration:
For a streaming example, run:
What This Does
This project demonstrates a practical approach to building concurrent systems in Rust using:
- Actor Model: A message-passing architecture with isolated, concurrent actors
- Streaming Pipelines: Functional reactive programming patterns for data processing
The project allows for abstraction between Tokio-based asynchronous actors and blocking actors, providing a flexible foundation for concurrent application development.
Basic Concepts
An actor implements an Actor<MType, Response> trait that includes a receive function accepting a message type of Message<MType, Response>.
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
Response is any enum that actors use to send return messages back to the sender. A generic ResponseMessage can be used by default.
Once you choose an MType, the ActorSystem uses the same message type throughout the system. Currently, only one MType is allowed; however, with Rust's enums, there is significant capacity for variance in message types.
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<MType> trait. All actors must receive a Message<MType>.
use Actor;
use ;
use info;
// you can include some attributes like a name if you wish
;
async
## Streaming Module
The streaming module provides a functional reactive programming approach to data processing built on top of the actor system. It allows you to create pipelines that process data through various transformations in a non-blocking, efficient manner.
### Key Components
**Source**: Entry point for data into the pipeline. Generates or reads data and emits it downstream.
**Flow**: Transforms messages as they pass through. Can modify, filter, or enrich data in the pipeline.
**Sink**: Terminal point in a pipeline that consumes messages and performs side effects .
**Materializer**: Executes the pipeline by connecting sources, flows, and sinks within the actor system.
### Streaming Example
```bash
# Run the streaming example with the feature enabled
cargo run --example source --features streaming
This example demonstrates:
use ;
async
Building with Streaming
The streaming module is an optional feature. To build and test with streaming enabled:
# Build with streaming
# Run tests with streaming
Testing and Coverage
The project includes comprehensive test coverage across all modules:
- Streaming module: 36 tests
- Actor module: 30 tests
- Actor System module: 19 tests
- Total: 85 tests
Running Tests
# Run all tests with streaming feature
# Run specific module tests
Configuration
This library can be configured using a TOML file. Keep your real config out of git and copy the example:
Example snippet:
[]
= 100
= 5000
Usage in code:
use SidsConfig;
let config = load_from_file
.expect;
let mut actor_system = start_actor_system_with_config;
Code Coverage
The project uses cargo-llvm-cov for code coverage analysis, configured to comply with institutional file system constraints.
Quick start:
.\run-coverage.ps1
This will automatically:
- Install
cargo-llvm-covif needed - Run tests with coverage instrumentation
- Generate an HTML coverage report
- Open the report in your browser
- Keep all artifacts within the project directory
For more details, see COVERAGE.md.
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].