Skip to main content

Module broadcast

Module broadcast 

Source
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() and unsubscribe()
  • 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

OperationTarget
broadcast()< 100ns (2 subscribers)
read()< 50ns
subscribe()O(1), CAS on slot (Ring 2 only)

Structs§

BroadcastChannel
Broadcast channel for multi-consumer scenarios.
BroadcastConfig
Broadcast channel configuration.
BroadcastConfigBuilder
Builder for BroadcastConfig.
SubscriberInfo
Information about a subscriber.

Enums§

BroadcastError
Broadcast channel errors.
SlowSubscriberPolicy
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.