pub struct BackpressureController { /* private fields */ }Expand description
Backpressure controller for bounded pipeline channels.
Ensures producers block when consumers are overwhelmed, preventing memory explosion and maintaining system stability. Uses tokio semaphores for concurrency limiting.
§Examples
use crawlkit_engine::BackpressureController;
let controller = BackpressureController::new(10);
let permit = controller.acquire().await.unwrap();
assert_eq!(controller.active_count(), 1);
drop(permit);
assert_eq!(controller.active_count(), 0);Implementations§
Source§impl BackpressureController
impl BackpressureController
Sourcepub fn with_channel(max_concurrent: usize, channel_size: usize) -> Self
pub fn with_channel(max_concurrent: usize, channel_size: usize) -> Self
Create with bounded channel for additional backpressure.
Sourcepub async fn acquire(&self) -> Result<BackpressurePermit<'_>, BackpressureError>
pub async fn acquire(&self) -> Result<BackpressurePermit<'_>, BackpressureError>
Sourcepub fn try_acquire(&self) -> Option<BackpressurePermit<'_>>
pub fn try_acquire(&self) -> Option<BackpressurePermit<'_>>
Try to acquire a permit without blocking.
Sourcepub fn active_count(&self) -> usize
pub fn active_count(&self) -> usize
Get number of active tasks.
Sourcepub fn is_at_capacity(&self) -> bool
pub fn is_at_capacity(&self) -> bool
Check if at capacity.
Sourcepub fn is_shut_down(&self) -> bool
pub fn is_shut_down(&self) -> bool
Check if shut down.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for BackpressureController
impl !UnwindSafe for BackpressureController
impl Freeze for BackpressureController
impl Send for BackpressureController
impl Sync for BackpressureController
impl Unpin for BackpressureController
impl UnsafeUnpin for BackpressureController
Blanket Implementations§
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> 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>
Converts
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>
Converts
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