pub struct ThreadPerCoreRuntime { /* private fields */ }Expand description
Thread-per-core runtime for parallel event processing.
Manages multiple reactor threads, routing events by key hash to ensure state locality.
Implementations§
Source§impl ThreadPerCoreRuntime
impl ThreadPerCoreRuntime
Sourcepub fn new(config: TpcConfig) -> Result<Self, TpcError>
pub fn new(config: TpcConfig) -> Result<Self, TpcError>
Creates a new runtime with the given configuration.
§Errors
Returns an error if any core thread cannot be spawned.
Sourcepub fn new_with_factory<F>(
config: TpcConfig,
factory: &F,
) -> Result<Self, TpcError>where
F: OperatorFactory,
pub fn new_with_factory<F>(
config: TpcConfig,
factory: &F,
) -> Result<Self, TpcError>where
F: OperatorFactory,
Creates a new runtime with operators from a factory.
The factory is called once per core to create that core’s operators.
§Errors
Returns an error if any core thread cannot be spawned.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Returns true if the runtime is running.
Sourcepub fn submit(&self, event: Event) -> Result<(), TpcError>
pub fn submit(&self, event: Event) -> Result<(), TpcError>
Submits an event for processing.
The event is routed to a core based on its key.
§Errors
Returns an error if the target core’s queue is full.
Sourcepub fn submit_to_core(
&self,
core_id: usize,
event: Event,
) -> Result<(), TpcError>
pub fn submit_to_core( &self, core_id: usize, event: Event, ) -> Result<(), TpcError>
Submits an event to a specific core.
Use this when you’ve already computed the routing.
§Errors
Returns an error if the core’s queue is full or the core_id is invalid.
Sourcepub fn submit_batch(&self, events: Vec<Event>) -> (usize, Option<TpcError>)
pub fn submit_batch(&self, events: Vec<Event>) -> (usize, Option<TpcError>)
Submits a batch of events for processing.
Events are routed to cores based on their keys.
§Errors
Returns the number of successfully submitted events and an error if any event couldn’t be submitted.
Sourcepub fn poll_into(&self, buffer: &mut OutputBuffer, max_per_core: usize) -> usize
pub fn poll_into(&self, buffer: &mut OutputBuffer, max_per_core: usize) -> usize
Polls all cores for outputs into a pre-allocated buffer (zero-allocation).
Returns the total number of outputs collected across all cores.
§Arguments
buffer- Pre-allocated buffer to receive outputs. UseOutputBufferfor optimal performance.max_per_core- Maximum outputs to collect from each core.
§Example
use laminar_core::tpc::OutputBuffer;
// Create buffer once
let mut buffer = OutputBuffer::with_capacity(4096);
// Poll loop - no allocation after warmup
loop {
let count = runtime.poll_into(&mut buffer, 256);
for output in buffer.iter() {
process(output);
}
buffer.clear(); // Reuse buffer
}Sourcepub fn poll_each<F>(&self, max_per_core: usize, f: F) -> usize
pub fn poll_each<F>(&self, max_per_core: usize, f: F) -> usize
Polls all cores with a callback for each output (zero-allocation).
Processing continues until:
- All cores have been polled up to
max_per_core - The callback returns
ControlFlow::Break
Returns the total number of outputs processed.
§Arguments
max_per_core- Maximum outputs to process from each core.f- Callback function for each output. Returntrueto continue,falseto stop.
§Example
// Process outputs without any allocation
let count = runtime.poll_each(256, |output| {
match output {
Output::Event(event) => {
send_to_sink(event);
}
_ => {}
}
true // Continue processing
});
// Or stop early on condition
let count = runtime.poll_each(256, |output| {
if should_stop() {
false // Stop processing
} else {
process(output);
true
}
});Sourcepub fn poll_core(&self, core_id: usize) -> Vec<Output>
pub fn poll_core(&self, core_id: usize) -> Vec<Output>
Polls a specific core for outputs.
§Note
This method allocates memory. For zero-allocation polling, use
poll_core_into or poll_core_each instead.
Sourcepub fn poll_core_into(
&self,
core_id: usize,
buffer: &mut OutputBuffer,
max_count: usize,
) -> usize
pub fn poll_core_into( &self, core_id: usize, buffer: &mut OutputBuffer, max_count: usize, ) -> usize
Polls a specific core into a pre-allocated buffer (zero-allocation).
Returns the number of outputs collected.
Sourcepub fn poll_core_each<F>(&self, core_id: usize, max_count: usize, f: F) -> usize
pub fn poll_core_each<F>(&self, core_id: usize, max_count: usize, f: F) -> usize
Polls a specific core with a callback for each output (zero-allocation).
Returns the number of outputs processed.
Sourcepub fn shutdown(self) -> Result<(), TpcError>
pub fn shutdown(self) -> Result<(), TpcError>
Shuts down the runtime gracefully.
Signals all cores to stop and waits for them to finish.
§Errors
Returns an error if any core cannot be joined cleanly.
Sourcepub fn run_with_handler<F>(&self, handler: F, shutdown: &AtomicBool)
pub fn run_with_handler<F>(&self, handler: F, shutdown: &AtomicBool)
Runs the runtime with a custom output handler.
This is a convenience method that polls outputs and passes them to the handler in a loop until shutdown is signaled.
§Arguments
handler- Function called with batches of outputsshutdown- Atomic flag to signal shutdown
Trait Implementations§
Source§impl Debug for ThreadPerCoreRuntime
impl Debug for ThreadPerCoreRuntime
Auto Trait Implementations§
impl !Freeze for ThreadPerCoreRuntime
impl !RefUnwindSafe for ThreadPerCoreRuntime
impl Send for ThreadPerCoreRuntime
impl Sync for ThreadPerCoreRuntime
impl Unpin for ThreadPerCoreRuntime
impl !UnwindSafe for ThreadPerCoreRuntime
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.