37 releases

0.11.1 Oct 19, 2024
0.11.0 Aug 16, 2023
0.10.14 Jul 21, 2022
0.10.12 Mar 10, 2022
0.2.0 Jul 31, 2019

#4 in Concurrency

Download history 636062/week @ 2024-08-01 703298/week @ 2024-08-08 692541/week @ 2024-08-15 699195/week @ 2024-08-22 659986/week @ 2024-08-29 729551/week @ 2024-09-05 704796/week @ 2024-09-12 721379/week @ 2024-09-19 757162/week @ 2024-09-26 797002/week @ 2024-10-03 772675/week @ 2024-10-10 870907/week @ 2024-10-17 920930/week @ 2024-10-24 813464/week @ 2024-10-31 835149/week @ 2024-11-07 723979/week @ 2024-11-14

3,462,063 downloads per month
Used in 2,061 crates (482 directly)

Apache-2.0/MIT

80KB
1.5K SLoC

Flume

A blazingly fast multi-producer, multi-consumer channel.

Cargo Documentation License actions-badge Casual Maintenance Intended

use std::thread;

fn main() {
    println!("Hello, world!");

    let (tx, rx) = flume::unbounded();

    thread::spawn(move || {
        (0..10).for_each(|i| {
            tx.send(i).unwrap();
        })
    });

    let received: u32 = rx.iter().sum();

    assert_eq!((0..10).sum::<u32>(), received);
}

Why Flume?

  • Featureful: Unbounded, bounded and rendezvous queues
  • Fast: Always faster than std::sync::mpsc and sometimes crossbeam-channel
  • Safe: No unsafe code anywhere in the codebase!
  • Flexible: Sender and Receiver both implement Send + Sync + Clone
  • Familiar: Drop-in replacement for std::sync::mpsc
  • Capable: Additional features like MPMC support and send timeouts/deadlines
  • Simple: Few dependencies, minimal codebase, fast to compile
  • Asynchronous: async support, including mix 'n match with sync code
  • Ergonomic: Powerful select-like interface

Usage

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

flume = "x.y"

Cargo Features

Flume comes with several optional features:

  • spin: use spinlocks instead of OS-level synchronisation primitives internally for some kind of data access (may be more performant on a small number of platforms for specific workloads)

  • select: Adds support for the Selector API, allowing a thread to wait on several channels/operations at once

  • async: Adds support for the async API, including on otherwise synchronous channels

  • eventual-fairness: Use randomness in the implementation of Selector to avoid biasing/saturating certain events over others

You can enable these features by changing the dependency in your Cargo.toml like so:

flume = { version = "x.y", default-features = false, features = ["async", "select"] }

Benchmarks

Although Flume has its own extensive benchmarks, don't take it from here that Flume is quick. The following graph is from the crossbeam-channel benchmark suite.

Tests were performed on an AMD Ryzen 7 3700x with 8/16 cores running Linux kernel 5.11.2 with the bfq scheduler.

Flume benchmarks (crossbeam benchmark suite)

Status

Flume is in casual maintenance mode. This means that the crate will continue to receive critical security and bug fixes, but heavy feature development has stopped. If you're looking for a new feature, you're welcome to open a PR and I'll try to find the time to review it.

Flume has been great fun to work on, and I'm happy that it's being used successfully by so many people. I consider the crate to be largely feature-complete at this point (bar small details here and there).

License

Flume is licensed under either of:

Dependencies

~135–530KB