#ring-buffer #ipc #spsc #mmap #unix

bin+lib ipc_ring

High-performance memory-mapped SPSC ring buffer for Unix IPC

2 unstable releases

0.2.0 Oct 9, 2025
0.1.0 Sep 3, 2025

#1043 in Concurrency

Download history 99/week @ 2025-08-29 33/week @ 2025-09-05 4/week @ 2025-09-12 6/week @ 2025-09-19 30/week @ 2025-09-26 90/week @ 2025-10-03 102/week @ 2025-10-10 10/week @ 2025-10-17 2/week @ 2025-10-24

206 downloads per month

MIT license

52KB
1K SLoC

ipc_ring

Memory-mapped SPSC ring buffer for high-performance inter-process communication on Unix systems.

Performance

MacBook Pro 2021 M1 Pro, 32GB RAM, 1TB NVMe: 16.3M msgs/s, 3.9 GiB/s (256B messages)

{"messages":1000000,"msg_size":256,"elapsed_sec":0.061254,"msgs_per_sec":16325531,"MiB_per_sec":3985.73}

Benchmark Comparison

Tested against ipmpsc (serialized MPSC ring buffer) using 1M messages, 256-byte payloads, 64MB ring capacity on /tmp filesystem:

Library Messages/sec Throughput Ratio
ipc_ring 16.3M 3.9 GiB/s 20.6x
ipmpsc 791K 193 MiB/s 1x

Use ipc_ring when:

  • Single producer/consumer pattern fits your use case
  • Raw byte transfers (no serialization overhead needed)
  • Maximum throughput is critical
  • Streaming pre-formatted data (JSON lines, log entries, etc.)

Comparison limitations:

  • ipmpsc supports multiple producers; ipc_ring is SPSC only
  • ipmpsc provides type-safe serialization; ipc_ring handles raw bytes
  • ipmpsc is cross-platform; ipc_ring is Unix-only
  • Different synchronization mechanisms (lock-free vs mutex-based)

Perfect for: Streaming JSON events to compression/storage processes, high-frequency logging, real-time data pipelines where serialization overhead is unwanted.

Build

cargo build --release

Usage

Writer creates ring:

let mut writer = RingWriter::create("/tmp/ring", 64 * 1024 * 1024)?;
writer.push(b"data", None)?;  // None = block until space

Reader opens existing ring:

let mut reader = RingReader::open("/tmp/ring")?;
let mut buf = Vec::new();
let n = reader.pop(&mut buf, None)?;  // None = block until data

Benchmark

cargo run --release --bin ipc_bench -- --ring /dev/shm/bench --cap 67108864

Technical

  • SPSC: Single producer, single consumer only
  • Lock-free: Atomic operations, no mutexes
  • mmap-backed: Shared memory via file mapping
  • Power-of-two capacity: Required for efficient masking
  • Unix-only: Linux, macOS (uses raw_sync events)

Requirements

  • Unix system (Linux/macOS)
  • Rust 1.70+

Dependencies

~1.2–2MB
~37K SLoC