[Media] fanring: a Rust MPMC channel that scales to 150M items/s
![[Media] fanring: a Rust MPMC channel that scales to 150M items/s](https://i.redd.it/a90poh1zgbnh1.png)
fanring is a typed in-process MPSC/MPMC channel built around one bounded SPSC yring per producer. Producers never fight over a shared queue tail. Sender registration is dynamic and has no configured limit. Both channel types have nonblocking, blocking, timeout, and deadline
operations.
Performance. On an i7-8700B, u64 MPMC throughput rises from 71.4M items/s at 1 producer / 1 consumer to 96.8M at 4P/4C and 149.6M at 4P/8C. The 4P/4C run measured crossbeam-channel at 20.3M, flume at 5.2M, and kanal at 21.9M. MPSC reaches 66.8M with four producers.
MPSC chart,
MPMC chart
Blocking wake latency is around 9 µs p50 for fanring, similar tocrossbeam-channel and flume.
MPSC chart,
MPMC chart
How it works. Each sender writes into its own ring. Hierarchical bitmaps find ready lanes without scanning every producer. MPSC drains them directly. MPMC takes batches of up to 64 items, keeping them private with one receiver or making them stealable with several. send and recv handle batching internally. The ordinary producer path avoids shared locks. Registration, receiver work distribution, and parking use short locked sections.
Tradeoffs. Capacity is a high-water mark per producer, not one global
channel bound. MPMC staging can temporarily exceed the sum of ring capacities. MPSC preserves FIFO within each producer lane. MPMC ordering is relaxed. There is no async API yet.
fanring uses #![forbid(unsafe_code)]. Ring storage is delegated to yring. Validation includes Loom, Miri, ThreadSanitizer, and >6h of
fuzzing and randomized stress testing.