Code Monkey home page Code Monkey logo

loole's Introduction

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

Producers can send and consumers can receive messages asynchronously or synchronously.

Usage

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

loole = "0.3.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

Loole is licensed under either of:

loole's People

Contributors

asonix avatar mahdi-shojaee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

loole's Issues

`recv_timeout` has a memory leak

fn test_loole() {
    let (tx, rx) = loole::bounded::<Vec<[usize; 10000]>>(10);
    {
        let rx = rx.clone();
        let max_wait_timeout = std::time::Duration::from_nanos(5);
        let _ = std::thread::spawn(move || {
            loop {
                let t = match rx.recv_timeout(max_wait_timeout) {
                    Ok(a) => { a }
                    Err(RecvTimeoutError::Timeout) => {
                        continue;
                    }
                    Err(RecvTimeoutError::Disconnected) => {
                        break;
                    }
                };
            }
        }).join();
    }
}

Memory will continue to grow

Benchmarks?

Hi,

Looking at the benchmark charts, I have to say that my interest is piqued!
Do you have any plans of providing the source code of your benchmarks so others can replicate them?

Best,

Implement Stream and Sink

Stream for Receiver and Sink for Sender would be really convenient for some use cases. Flume does it too.

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.