Crates.io | tyra |
lib.rs | tyra |
version | 1.0.0 |
source | src |
created_at | 2021-10-09 10:41:46.875081 |
updated_at | 2022-10-02 17:41:20.817335 |
description | Typed Actor System |
homepage | https://github.com/sers-dev/tyra |
repository | https://github.com/sers-dev/tyra |
max_upload_size | |
id | 462762 |
size | 208,612 |
Tyra
is a production ready, cross-platform Typed Actor System Written in Rust.
See default.toml for a list of all configuration parameters and their defaults.
Configuration can be adjusted by providing a ./config/tyra.toml
.
Through the current implementation of the SerializedMessage
it's proven that this system can be clustered.
Development will focus on implementing a proper clustering system once 1.0.0
has been released.
cargo run --example serialize to view/run the poc implementation
There are a few different benchmarks within examples, prefixed with benchmark_
The most interesting things to look at are specifically (ordered from fastest to slowest):
roughly as fast as the benchmark_single_actor
but some executions are much slower
Nonetheless, it makes sense to post some generic data that gives at least some insight into the performance:
0.8.0
general.default_mailbox_size: 0
(setting a fixed mailbox_size would further increase performance)general.default_message_throughput: 15
(obviously could also be optimized for single actor usage, but would probably not be a fair measurement)thread_pool.config.default.threads_max: 10
(overwritten by _single_thread
tests)benchmark_single_actor
benchmark_single_actor_process_after_send_single_thread
benchmark_single_actor_process_after_send
~5.7mil messages per second
docs.rs or generate your own with cargo doc
This code can be found in examples/quickstart.rs and can be executed with cargo run --example quickstart
use tyra::prelude::*;
use std::error::Error;
use std::time::Duration;
// define an `ActorMessage` that can be sent to `Actors` that implement the corresponding `Handler<T>`
struct TestMessage {}
impl TestMessage {
pub fn new() -> Self {
Self {}
}
}
impl ActorMessage for TestMessage {}
// define the actual `Actor` that should process messages
struct TestActor {}
impl TestActor {
pub fn new() -> Self {
Self {}
}
}
impl Actor for TestActor {}
// define a factory that creates the `Actor` for us
struct TestActorFactory {}
impl TestActorFactory {
pub fn new() -> Self {
Self {}
}
}
impl ActorFactory<TestActor> for TestActorFactory {
fn new_actor(&mut self, _context: ActorContext<TestActor>) -> Result<TestActor, Box<dyn Error>> {
Ok(TestActor::new())
}
}
// implement our message for the `Actor`
impl Handler<TestMessage> for TestActor {
fn handle(&mut self, _msg: TestMessage, context: &ActorContext<Self>) -> Result<ActorResult, Box<dyn Error>> {
println!("HELLO WORLD!");
context.system.stop(Duration::from_millis(1000));
Ok(ActorResult::Ok)
}
}
fn main() {
// generate config
let actor_config = TyraConfig::new().unwrap();
// start system with config
let actor_system = ActorSystem::new(actor_config);
// create actor on the system
let actor = actor_system.builder().spawn("test", TestActorFactory::new()).unwrap();
// send a message to the actor
actor.send(TestMessage::new()).unwrap();
// wait for the system to stop
std::process::exit(actor_system.await_shutdown());
}
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.