16个版本

0.6.1 2024年8月2日
0.6.0 2023年11月24日
0.5.6 2023年11月20日
0.5.3 2022年10月11日
0.1.0 2021年3月6日

#237 in 网络编程

Download history 2/week @ 2024-06-10 2/week @ 2024-07-01 18/week @ 2024-07-22 104/week @ 2024-07-29 29/week @ 2024-08-05 27/week @ 2024-08-12

每月178次下载
用于 s2gpp

Apache-2.0

135KB
3.5K SLoC

crates.io Tests on main License Dependency Status Downloads

Actix-Telepathy

actix-remoteAkka Cluster的启发,Actix-Telepathy是Rust actor框架Actix的扩展。它使Rust用户能够在actor框架内构建分布式应用程序。

版本匹配

actix -telepathy -telepathy-derive
0.10 0.1 0.1
0.11 0.2 0.1
0.12 0.3 0.2
0.12 0.4 0.3
0.13 0.5 0.3
0.13.1 0.6.0 0.3.4
0.13.5 0.6.1 0.3.4

测试

运行被忽略的测试,因为这些测试本身会运行多个线程。

cargo test -- --ignored --test-threads=1

用法

连接变体

我们支持以下两种连接变体。它们定义了节点如何加入集群。每个变体都有优点和缺点。请仔细选择!

SingleSeed 假设所有节点都有相同的种子节点(除了种子节点本身,它没有种子节点)。如果添加另一个节点,它将通过种子节点添加到集群中。如果节点有不同的种子节点,则可能会出现错误。此变体建议用于快速连接设置,但不建议在种子节点不一定总是可用的情况下使用。(此变体是默认的。)

Gossip 可以将节点相互连接。每个节点都可以有不同的种子节点。当加入集群时,节点将连接到其种子节点并接收即将加入的节点数。该节点的种子节点然后将加入节点的信息通过Gossip协议发送给其他节点。因此,种子节点随机选择3个节点并将信息发送给它们。这3个节点将连接到加入的节点。然后这3个节点将信息发送给其他3个节点,依此类推。如果种子节点不一定总是可用,则建议使用此变体。如果集群非常大,不建议使用此变体,因为Gossip协议所需的时间会随着集群的大小而增加。

Cluster::new_with_connection_protocol("127.0.0.1:1992".parse().unwrap(), vec![/*...*/], ConnectionProtocol::Gossip)

发送远程消息

Actix支持发送消息到Addr<impl Actor>do_sendtry_sendsend

对于RemoteMessage,此crate目前只支持do_send。此外,我们引入了wait_send方法,当NetworkInterface发送了RemoteMessage时,该方法将返回消息响应。这并不意味着RemoteMessage已到达,而只是表明它已被发送。

关于如何实现远程响应以及在RemoteAddr上使用send方法的想法和讨论,请参阅讨论页面

Cargo.toml

[dependencies]
actix = "0.13.1"
actix-telepathy = "0.6.1"

main.rs

use actix_rt;
use actix_telepathy::prelude::*;
use actix::prelude::*;
use tokio;
use std::net::{ToSocketAddrs, SocketAddr};

#[actix_rt::main]
async fn main() {
    let bind_addr = "127.0.0.1:1992".parse().unwrap();
    let seed_nodes = vec![];
    let _cluster = Cluster::new(bind_addr, seed_nodes);

    tokio::signal::ctrl_c().await.unwrap();
    println!("Ctrl-C received, shutting down");
    System::current().stop();
}

论文

我们关于此项目的论文已在此处发表,并进行了实验,以展示其与Akka和Orleans的竞争力。

请在使用时考虑引用此作品!

@inproceedings{10.1145/3623506.3623575,
    author = {Wenig, Phillip and Papenbrock, Thorsten},
    title = {Actix-Telepathy},
    year = {2023},
    isbn = {9798400704000},
    publisher = {Association for Computing Machinery},
    address = {New York, NY, USA},
    url = {https://doi.org/10.1145/3623506.3623575},
    doi = {10.1145/3623506.3623575},
    abstract = {The actor programming model supports the development of concurrent applications by encapsulating state and behavior into independent actors. Each actor is a computational entity with strictly private state and behavior. Actors communicate via asynchronous messaging and, in this way, require neither shared memory nor locking. This makes the actor model suitable not only for parallel programming but also for distributed applications engineering. The Rust programming language is a statically-typed language that gained a lot of attention in the past years due to its efficient, economical and safe memory management. To ease the development of parallel applications, several actor model frameworks have been built for Rust. However, no actively maintained Rust actor framework provides the necessary features to write distributed applications. For this reason, we propose an extension for Rust’s Actix library, called Actix-Telepathy, that enables remote messaging and offers clustering support. It allows developers to setup remote actors that can communicate across a computer network with the help of a straight forward and easy to understand interface. Our evaluation demonstrates that Actix-Telepathy competes well in remote messaging performance and memory consumption with other actor libraries, such as Scala’s popular Akka library.},
    booktitle = {Proceedings of the 10th ACM SIGPLAN International Workshop on Reactive and Event-Based Languages and Systems},
    pages = {14–24},
    numpages = {11},
    keywords = {Distributed Computing, Rust, Actor Model},
    location = {Cascais, Portugal},
    series = {REBLS 2023}
}

依赖项

~10–20MB
~291K SLoC