pub struct MemoryLimitLayer<M>where
M: AvailableMemory,{ /* private fields */ }Expand description
Enforces a limit on the underlying service when a memory Threshold is met.
A common use case is to load shed (reject requests), once the threshold is met. For doing so you must add tower’s load_shed layer.
Otherwise the service enqueues requests until the memory is available again.
Implementations§
Source§impl<M> MemoryLimitLayer<M>where
M: AvailableMemory,
impl<M> MemoryLimitLayer<M>where
M: AvailableMemory,
Sourcepub fn available_memory(&self) -> Result<usize, BoxError>
pub fn available_memory(&self) -> Result<usize, BoxError>
Get the available memory. Can be used to validate the inner memory stat provder before adding the layer.
Sourcepub const fn new(threshold: Threshold, provider: M) -> Self
pub const fn new(threshold: Threshold, provider: M) -> Self
Create a new concurrency limit layer with a default MemoryLimitLayer::retry_interval of 50ms.
Sourcepub fn with_retry_interval(self, retry_interval: Duration) -> Self
pub fn with_retry_interval(self, retry_interval: Duration) -> Self
Set a custom MemoryLimitLayer::retry_interval which determines when the next memory check is performed, if the threshold is exceeded.
Trait Implementations§
Source§impl<M> Clone for MemoryLimitLayer<M>where
M: AvailableMemory + Clone,
impl<M> Clone for MemoryLimitLayer<M>where
M: AvailableMemory + Clone,
Source§fn clone(&self) -> MemoryLimitLayer<M>
fn clone(&self) -> MemoryLimitLayer<M>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<M> Debug for MemoryLimitLayer<M>where
M: AvailableMemory + Debug,
impl<M> Debug for MemoryLimitLayer<M>where
M: AvailableMemory + Debug,
Source§impl<S, M> Layer<S> for MemoryLimitLayer<M>where
M: AvailableMemory,
impl<S, M> Layer<S> for MemoryLimitLayer<M>where
M: AvailableMemory,
Auto Trait Implementations§
impl<M> Freeze for MemoryLimitLayer<M>where
M: Freeze,
impl<M> RefUnwindSafe for MemoryLimitLayer<M>where
M: RefUnwindSafe,
impl<M> Send for MemoryLimitLayer<M>
impl<M> Sync for MemoryLimitLayer<M>where
M: Sync,
impl<M> Unpin for MemoryLimitLayer<M>where
M: Unpin,
impl<M> UnwindSafe for MemoryLimitLayer<M>where
M: UnwindSafe,
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