Expand description
Broadcast Channel for multi-consumer streaming.
BroadcastChannel<T> implements a shared ring buffer with per-subscriber cursors
for single-producer, multiple-consumer (SPMC) broadcast. Designed for Ring 0 hot path:
zero allocations after construction, lock-free reads and writes.
§Design
- Pre-allocated ring buffer with power-of-2 capacity and bitmask indexing
- Lock-free hot path:
broadcast(),read(),slowest_cursor()use only atomics - Fixed-size cursor array with O(1) direct indexing by subscriber ID
- Cache-padded cursor slots (64-byte aligned) to prevent false sharing
- Single producer via
broadcast() - Dynamic subscribers via
subscribe()andunsubscribe() - Configurable slow subscriber policies:
Block,DropSlow,SkipForSlow - Per-subscriber lag tracking for backpressure monitoring
§Key Principle
Broadcast is derived from query plan analysis, not user configuration. The planner determines when multiple MVs read from the same source and auto-upgrades to broadcast mode.
§Safety
The single-writer invariant is upheld by the DAG executor, which ensures
exactly one thread calls broadcast() on any given channel. Multiple threads
may call read() with distinct subscriber IDs.
§Performance Targets
| Operation | Target |
|---|---|
broadcast() | < 100ns (2 subscribers) |
read() | < 50ns |
subscribe() | O(1), CAS on slot (Ring 2 only) |
Structs§
- Broadcast
Channel - Broadcast channel for multi-consumer scenarios.
- Broadcast
Config - Broadcast channel configuration.
- Broadcast
Config Builder - Builder for
BroadcastConfig. - Subscriber
Info - Information about a subscriber.
Enums§
- Broadcast
Error - Broadcast channel errors.
- Slow
Subscriber Policy - Slow subscriber handling policy.
Constants§
- DEFAULT_
BROADCAST_ CAPACITY - Default buffer capacity (power of 2).
- DEFAULT_
LAG_ WARNING_ THRESHOLD - Default lag warning threshold.
- DEFAULT_
MAX_ SUBSCRIBERS - Default maximum subscribers.
- DEFAULT_
SLOW_ SUBSCRIBER_ TIMEOUT - Default slow subscriber timeout.