PitchHut
Log in / Sign up
chute
51 views
Effortlessly manage concurrent data streams with a lock-free broadcast queue.
Pitch

Chute is a high-performance mpmc/spmc lock-free broadcast queue designed for efficient message passing in concurrent programming. Its unbounded dynamic size and shared structure ensure that all consumers receive every message sent, allowing for parallel processing without message duplication. Choose Chute for faster, simpler inter-thread communication.

Description

Introducing Chute: A Lock-Free Broadcast Queue
Chute is a highly efficient multi-producer multi-consumer (mpmc) and single-producer multi-consumer (spmc) lock-free broadcast queue, designed to enhance your concurrent programming capabilities. It ensures that all consumers receive every message sent to the queue from the moment they subscribe, without the overhead associated with traditional locking mechanisms.

Key Features

  • Lock-Free Consumers: Consume messages without the performance penalties of standard locks.
  • High-Throughput Producers: Mpmc producers can write simultaneously without contention, optimizing throughput.
  • Ordered Message Delivery: While mpmc producers are unordered, messages from a single spmc producer are delivered in order.
  • Dynamic Sizing: The queue can expand indefinitely as needed, accommodating variable workloads.
  • Shared Access: All readers and writers operate on the same queue instance without unnecessary duplications.
  • No Cloning: Messages are accessed directly without cloning, simplifying memory management and enhancing speed.

Performance

Chute boasts blazing-fast read operations by allowing consumers to read data directly from memory, utilizing atomic read instructions to determine the next data slice. Below is a benchmarking setup showcasing Chute's superior performance:

const WRITERS         : usize = 4;
const WRITER_MESSAGES : usize = 100;
const MESSAGES        : usize = WRITERS * WRITER_MESSAGES;
const READERS         : usize = 4;
let queue = chute::mpmc::Queue::new();

std::thread::scope(|s| {
    // READ threads
    for _ in 0..READERS {
        let mut reader = queue.reader();
        s.spawn(move || {
            let mut sum = 0;
            for _ in 0..MESSAGES {
                let msg = loop {
                    if let Some(msg) = reader.next() {
                        break msg;
                    }
                };
                sum += msg;
            }
            assert_eq!(sum, (0..MESSAGES).sum());
        });
    }        
    // WRITE threads
    for t in 0..WRITERS {
        let mut writer = queue.writer();
        s.spawn(move || {
            for i in 0..WRITER_MESSAGES {
                writer.push(t * WRITER_MESSAGES + i);
            }             
        });
    }
});

Benchmark Results

Chute has undergone rigorous benchmarking against conventional channels, demonstrating remarkable efficiency at scale. Explore detailed benchmark results and comparisons in the benchmarks section.

Implementation Details

Chute represents a significant evolution from the previous rc_event_queue, offering true lockless functionality for mpmc writers. Discover the underlying principles of Chute's design and operation at our How It Works page.

Testing & Limitations

Chute's library is extensively tested using fuzzy testing and the Miri testing framework. However, it does have some limitations, including the inability to disconnect slow readers, which may lead to unbounded queue growth if not managed. Additionally, all message blocks are currently of uniform size, a feature that may be optimized in future releases.