Skip to main content

Crate nexus_queue

Crate nexus_queue 

Source
Expand description

High-performance lock-free queues for latency-critical applications.

nexus-queue provides bounded queues optimized for trading systems and other low-latency workloads:

  • spsc: Single-producer single-consumer queue with cached indices
  • mpsc: Multi-producer single-consumer queue with Vyukov-style turn counters

§Quick Start

// SPSC - one producer, one consumer
use nexus_queue::spsc;

let (mut tx, mut rx) = spsc::ring_buffer::<u64>(1024);
tx.push(42).unwrap();
assert_eq!(rx.pop(), Some(42));
// MPSC - multiple producers, one consumer
use nexus_queue::mpsc;

let (mut tx, mut rx) = mpsc::bounded::<u64>(1024);
let mut tx2 = tx.clone();  // Clone for second producer

tx.push(1).unwrap();
tx2.push(2).unwrap();

assert!(rx.pop().is_some());
assert!(rx.pop().is_some());

§Design

§SPSC

Uses cached head/tail indices with separate cache lines to avoid false sharing. Producer and consumer each maintain a local copy of the other’s index, only refreshing from the atomic when their cache indicates the queue is full (producer) or empty (consumer).

§MPSC

Uses CAS-based slot claiming with Vyukov-style turn counters. Producers compete via CAS on the tail index, then wait for their slot’s turn counter before writing. This provides backpressure (try_push fails when full) without blocking.

Both designs perform well on multi-socket NUMA systems where cache line ownership is important for latency.

Modules§

mpsc
Multi-producer single-consumer bounded queue.
spsc
Single-producer single-consumer bounded queue.

Structs§

Full
Error returned when pushing to a full queue.