Coder Social home page Coder Social logo

btodell / flume Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zesterer/flume

0.0 1.0 0.0 594 KB

A safe and fast multi-producer, multi-consumer channel.

Home Page: https://crates.io/crates/flume

License: Apache License 2.0

Rust 100.00%

flume's Introduction

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"] }

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)

License

Flume is licensed under either of:

flume's People

Contributors

aeledfyr avatar bwoods avatar coolreader18 avatar cwfitzgerald avatar dylan-dpc avatar ericmcbride avatar gauthamastro avatar hippobaro avatar hobofan avatar imberflur avatar inetic avatar kyrias avatar lrazovic avatar lu-zero avatar lunacookies avatar maboesanman avatar matklad avatar mbrubeck avatar mullr avatar natsukagami avatar nivkner avatar phil-opp avatar restioson avatar rofrol avatar rzheka avatar sherlock-holo avatar stonks3141 avatar tavianator avatar tesuji avatar zesterer avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.