#async-channel #channel #mpmc #mpsc #thread #async

loole

A safe async/sync multi-producer, multi-consumer channel

22 releases

0.4.0 Oct 15, 2024
0.3.1 May 28, 2024
0.3.0 Jan 3, 2024
0.2.1 Dec 15, 2023
0.1.7 Oct 20, 2023

#92 in Concurrency

Download history 35/week @ 2024-08-16 72/week @ 2024-08-23 93/week @ 2024-08-30 42/week @ 2024-09-06 51/week @ 2024-09-13 145/week @ 2024-09-20 59/week @ 2024-09-27 67/week @ 2024-10-04 192/week @ 2024-10-11 100/week @ 2024-10-18 187/week @ 2024-10-25 158/week @ 2024-11-01 265/week @ 2024-11-08 1766/week @ 2024-11-15 1767/week @ 2024-11-22 1458/week @ 2024-11-29

5,338 downloads per month
Used in 2 crates

MIT/Apache

56KB
1K SLoC

Loole

A safe async/sync multi-producer multi-consumer channel.

Github Actions Documentation Cargo License

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());
}

Why Loole?

  • Fast: Excels in high-contention environments with many concurrent producers and consumers. (Benchmark results available below)
  • Featureful: Unbounded, bounded and rendezvous channels
  • Safe: No unsafe code: #![forbid(unsafe_code)]!
  • Capable: Send and receive operations can be blocking (sync) or non-blocking (async)
  • Familiar: Compatible with the Flume's API
  • Simple: Minimal dependencies, fast to compile

Usage

To use Loole, place the following line under the [dependencies] section in your Cargo.toml:

loole = "0.4.0"

Run Benchmarks

Benchmarks measure throughput, which is the number of messages sent and received per second, for messages of 264 bytes each.

To run benchmarks on your local machine, run the following command:

Prior to executing this command, ensure Node.js is installed.

cargo run --release -p benchmark

The above command will generate and update the benchmark images in the README.md file.

Benchmark Results

Benchmark results on:

OS: Ubuntu Linux 23.10, Kernel: 6.5.0-13

CPU: Intel Core i7-13700K (16/24-core/thread)

MPSC

Measures: Messages per second. (higher is better)

Messages size: 264 bytes.

MPSC: sync-sync MPSC: async-async MPSC: async-sync MPSC: sync-async

MPMC

Measures: Messages per second. (higher is better)

Messages size: 264 bytes.

MPMC: sync-sync MPMC: async-async MPMC: async-sync MPMC: sync-async

SPSC

Measures: Messages per second. (higher is better)

Messages size: 264 bytes.

SPSC: sync-sync SPSC: async-async SPSC: async-sync SPSC: sync-async

License

This project is licensed under the MIT license.

Dependencies

~34KB