subms-spsc-ring-buffer 0.5.0

submillisecond.com cookbook recipe - concurrency: subms-spsc-ring-buffer. Wait-free SPSC ring buffer with cache-line padded counters and opposite-index caching; sub-50ns enqueue/dequeue on sibling cores.
Documentation
  • Coverage
  • 90%
    9 out of 10 items documented1 out of 9 items with examples
  • Size
  • Source code size: 79.37 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 392.92 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 6s Average build duration of successful builds.
  • all releases: 6s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • kdog007
subms-spsc-ring-buffer-0.5.0 has been yanked.

subms-spsc-ring-buffer (Rust)

Wait-free single-producer single-consumer ring buffer.

Sizing

Power-of-two capacity (rounded up from the request). Index modulo via bitmask, not %. Per-side counter padding to 128 bytes to avoid false sharing across the head/tail line.

Implementation notes

  • Producer caches the consumer head; consumer caches the producer tail. Re-read through the atomic only when the cache says full / empty.
  • Memory ordering: Release on publish (tail/head store), Acquire on the opposite-side load, Relaxed on own-side reads.
  • Producer/Consumer split enforces SPSC at the type level - moving the wrong handle to the wrong thread is a compile error.

Quality bar

  • Reference impl: Java JCTools SpscArrayQueue, Agrona OneToOneConcurrentArrayQueue (Aeron). Rust rtrb.
  • Sub-ms claim under: enqueue/dequeue p99 < 1 ms across 100k ops with capacity 1024, on a 2-core sibling pair.
  • Not claimed: MPMC; multi-core throughput claims on logical (HT) sibling pairs.

Bench numbers

Filled in once the bench is run on the canonical hardware. The cookbook page carries the measured values - never invented.

Consumed by

Timer wheel (subms-timer-wheel) uses an SPSC ring as the schedule-from-any-thread inbox; the timer thread is the consumer.