21 个版本
0.3.1 | 2024年5月28日 |
---|---|
0.3.0 | 2024年1月3日 |
0.2.1 | 2023年12月15日 |
0.1.16 | 2023年12月11日 |
0.1.7 | 2023年10月20日 |
#237 在 并发
每月417 次下载
用于 io-pipe
46KB
907 行
Loole
一个安全的多生产者、多消费者异步/同步通道。
fn main() {
let (tx, rx) = loole::unbounded();
std::thread::spawn(move || {
for i in 0..10 {
tx.send(i).unwrap();
}
});
let mut sum = 0;
while let Ok(i) = rx.recv() {
sum += i;
}
assert_eq!(sum, (0..10).sum());
}
生产者可以异步或同步地发送消息,消费者可以异步或同步地接收消息。
用法
要使用 Loole,请在您的 Cargo.toml
文件的 [dependencies]
部分下添加以下行
loole = "0.3.0"
运行基准测试
基准测试测量吞吐量,即每秒发送和接收的消息数,每条消息大小为 264 字节。
要在您的本地机器上运行基准测试,请运行以下命令
在执行此命令之前,请确保已安装 Node.js。
cargo run --release -p benchmark
上述命令将在 README.md 文件中生成和更新基准测试图像。
基准测试结果
基准测试结果
操作系统:Ubuntu Linux 23.10,内核:6.5.0-13
CPU:Intel Core i7-13700K (16/24核/线程)
MPSC
指标:每秒消息数。 (越高越好)
消息大小:264 字节。
MPMC
指标:每秒消息数。 (越高越好)
消息大小:264 字节。
SPSC
指标:每秒消息数。 (越高越好)
消息大小:264 字节。
许可证
Loole 的许可证为以下之一
-
Apache 许可证 2.0 (https://apache.ac.cn/licenses/LICENSE-2.0)
-
MIT 许可证 (http://opensource.org/licenses/MIT)