Git Product home page Git Product logo

crossfire-rs's Introduction

Crossfire

Build Status License Cargo Documentation Rust 1.36+

This crate provide channels used between async-async or async-blocking code, in all direction. Implmented with lockless in mind, low level is based on crossbeam-channel

Performance

Faster than channel in std or mpsc in tokio, slightly slower than crossbeam itself (since async overhead to wake up sender or receiver).

Run the benchmark tests to see for yourself:

cargo test performance --release -- --nocapture --test-threads=1

APIs

Usage

Add this to your Cargo.toml:

[dependencies]
crossfire = "0.1"
extern crate crossfire;
extern crate tokio;

use crossfire::mpsc;

// async-async

let (tx, rx) = mpsc::bounded_future_both::<i32>(100);
tokio::spawn(async move {
    for i in 0i32..10000 {
        let _ = tx.send(i).await;
        println!("sent {}", i);
    }
});

loop {
    if let Ok(_i) = rx.recv().await {
        println!("recv {}", _i);
    } else {
        println!("rx closed");
        break;
    }
}

mpmc & mpsc package is almost the same, while mpsc has some optimization becauses it assumes only one consumer.

Error types are re-exposed from crossbeam-channel.

Compatibility

Supports stable Rust. Mainly tested on tokio-0.2 (Not tested on async-std or other runtime). future::select and timeout work fine, but it takes advantage of runtime behavior not documented by Rust official.

Refer to rust-lang/rust#73002

Memory overhead

While using mp tx or mp rx, there's memory overhead to pass along wakers for pending async producer or consumer. Since waker is small, the overhead can be ignored if your channel is busy. Canceled wakers will be eventually cleanup by later send/receive event. If the channel is used for close notification (which never trigger), currently there's hard coded threshold to clean up those canceled wakers.

Stability

This channel implementation serves in various components of our storage engine, you are welcome to rely on it.

crossfire-rs's People

Contributors

frostyplanet 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.