pub struct MulticastBuffer<T> { /* private fields */ }Expand description
Pre-allocated SPMC multicast buffer with reference-counted slots.
Provides zero-allocation publish/consume on the hot path. The buffer is constructed in Ring 2 and used in Ring 0.
§Type Parameters
T- The event type. Must beClonefor consumers (typicallyArc<RecordBatch>where clone is an O(1) atomic increment).
§Performance Targets
| Operation | Target |
|---|---|
publish() | < 100ns |
consume() | < 50ns |
Implementations§
Source§impl<T> MulticastBuffer<T>
impl<T> MulticastBuffer<T>
Sourcepub fn publish(&self, value: T) -> Result<(), DagError>
pub fn publish(&self, value: T) -> Result<(), DagError>
Publishes a value to all consumers.
Writes the value into the next available slot and sets the refcount
to consumer_count. All consumers will be able to read this value
via consume().
§Errors
Returns DagError::BackpressureFull if the target slot is still
in use by a slow consumer (backpressure).
§Safety Contract
Must be called from a single writer thread only. The DAG executor enforces this by assigning exactly one producer per shared stage.
Sourcepub fn consume(&self, consumer_idx: usize) -> Option<T>where
T: Clone,
pub fn consume(&self, consumer_idx: usize) -> Option<T>where
T: Clone,
Consumes the next value for a given consumer.
Returns None if no new data is available. Each consumer maintains
its own read position and will receive every published value in order.
§Arguments
consumer_idx- The consumer’s index (0-based, must be <consumer_count)
§Panics
Panics in debug mode if consumer_idx >= consumer_count.
Sourcepub fn consumer_count(&self) -> u32
pub fn consumer_count(&self) -> u32
Returns the number of consumers.
Sourcepub fn write_position(&self) -> u64
pub fn write_position(&self) -> u64
Returns the current write position (total number of publishes).
Sourcepub fn read_position(&self, consumer_idx: usize) -> u64
pub fn read_position(&self, consumer_idx: usize) -> u64
Trait Implementations§
Source§impl<T> Debug for MulticastBuffer<T>
impl<T> Debug for MulticastBuffer<T>
impl<T: Send> Send for MulticastBuffer<T>
impl<T: Send> Sync for MulticastBuffer<T>
Auto Trait Implementations§
impl<T> !Freeze for MulticastBuffer<T>
impl<T> !RefUnwindSafe for MulticastBuffer<T>
impl<T> Unpin for MulticastBuffer<T>
impl<T> UnsafeUnpin for MulticastBuffer<T>
impl<T> UnwindSafe for MulticastBuffer<T>where
T: UnwindSafe,
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more