7个版本 (1个稳定版)
1.0.0 | 2022年10月2日 |
---|---|
0.8.0 | 2022年9月26日 |
0.7.0 | 2022年9月13日 |
0.6.0 | 2022年8月20日 |
0.3.0 | 2021年10月9日 |
#6 in #scaling
140KB
2.5K SLoC
Tyra (类型化Rust Actor)
Tyra
是一个生产就绪的、跨平台的类型化Actor系统,使用Rust编写。
配置
有关所有配置参数及其默认值,请参阅 default.toml。
可以通过提供 ./config/tyra.toml
来调整配置。
集群
通过当前对 SerializedMessage
的实现,已证明此系统可以集群。一旦发布 1.0.0
,开发将专注于实现适当的集群系统。
运行 cargo run --example serialize 来查看/运行poc实现
基准测试
在 examples 中有几个不同的基准测试,以 benchmark_
开头
最有趣的是(按速度从快到慢排序)
- cargo run --release --example benchmark_single_actor_process_after_send_single_thread
- cargo run --release --example benchmark_single_actor_process_after_send
- cargo run --release --example benchmark_single_actor
- 可能是最常见的场景
- cargo run --release --example benchmark_single_actor_single_thread
- 大致与
benchmark_single_actor
一样快,但某些执行要慢得多
- 大致与
不要仅相信某处发布的随机基准测试,自己动手测试!
尽管如此,发布一些至少能提供一些性能见解的通用数据是有意义的
- 版本:
0.8.0
- CPU:8核心和16线程的Ryzen 1700,运行在3GHz
- tyra 配置
general.default_mailbox_size: 0
(设置固定的 mailbox_size 将进一步提高性能)general.default_message_throughput: 15
(显然也可以针对单个actor使用进行优化,但可能不是一个公平的测量)thread_pool.config.default.threads_max: 10
(由_single_thread
测试覆盖)
- 运行
benchmark_single_actor
- 在至少3.3秒内发送和接收1000万条消息
- 每秒大约3百万条消息
- 在至少3.3秒内发送和接收1000万条消息
- 运行
benchmark_single_actor_process_after_send_single_thread
- 至少700毫秒内发送1000万条消息
- 每秒大约1400万条消息
- 至少750毫秒内接收1000万条消息
- 每秒大约1300万条消息
- 至少700毫秒内发送1000万条消息
- 运行
benchmark_single_actor_process_after_send
- 至少700毫秒内发送1000万条消息
- 每秒大约1400万条消息
- 至少1750毫秒内接收1000万条消息
- 每秒大约570万条消息
- 至少700毫秒内发送1000万条消息
文档
docs.rs 或使用 cargo doc
生成您的文档
快速入门
此代码位于 examples/quickstart.rs,可以使用 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());
}
许可
许可协议为以下之一
- Apache License, Version 2.0 (LICENSE-APACHE 或 https://apache.ac.cn/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT 或 http://opensource.org/licenses/MIT)
任选其一。
贡献
除非您明确说明,否则根据Apache-2.0许可协议定义的,您有意提交的、旨在包含在本作品中的任何贡献,将按上述方式双重许可,不附加任何额外条款或条件。
依赖项
~3.5–10MB
~95K SLoC