Skip to main content

LimitsBuilder

Struct LimitsBuilder 

Source
pub struct LimitsBuilder<S: State = Empty> { /* private fields */ }
Expand description

Use builder syntax to set the inputs and finish with build().

Implementations§

Source§

impl<S: State> LimitsBuilder<S>

Source

pub fn build(self) -> Limits
where S: IsComplete,

Finishes building and performs the requested action.

Source

pub fn max_batch_size(self, value: usize) -> LimitsBuilder<SetMaxBatchSize<S>>
where S::MaxBatchSize: IsUnset,

Optional (Some / Option setters). Default: 100.

Limits the maximum size of a batch.

Larger batches usually spread per-batch costs over more items, up to a point, but take longer to process. Where that point is depends on the processor, so measure it.

Defaults to 100.

Source

pub fn maybe_max_batch_size( self, value: Option<usize>, ) -> LimitsBuilder<SetMaxBatchSize<S>>
where S::MaxBatchSize: IsUnset,

Optional (Some / Option setters). Default: 100.

Limits the maximum size of a batch.

Larger batches usually spread per-batch costs over more items, up to a point, but take longer to process. Where that point is depends on the processor, so measure it.

Defaults to 100.

Source

pub fn max_key_concurrency( self, value: usize, ) -> LimitsBuilder<SetMaxKeyConcurrency<S>>
where S::MaxKeyConcurrency: IsUnset,

Optional (Some / Option setters). Default: 10.

Limits the maximum number of batches that can be processed concurrently for a key, including resource acquisition.

It doesn’t limit concurrency across keys: with n active keys, up to n * max_key_concurrency batches can be in flight.

Set it to 1 when the work for a key is serialised anyway, e.g. by a lock taken in acquire_resources(). A higher limit doesn’t help: the extra batches only wait for the lock, holding anything they acquired before it, e.g. a connection.

Defaults to 10.

Source

pub fn maybe_max_key_concurrency( self, value: Option<usize>, ) -> LimitsBuilder<SetMaxKeyConcurrency<S>>
where S::MaxKeyConcurrency: IsUnset,

Optional (Some / Option setters). Default: 10.

Limits the maximum number of batches that can be processed concurrently for a key, including resource acquisition.

It doesn’t limit concurrency across keys: with n active keys, up to n * max_key_concurrency batches can be in flight.

Set it to 1 when the work for a key is serialised anyway, e.g. by a lock taken in acquire_resources(). A higher limit doesn’t help: the extra batches only wait for the lock, holding anything they acquired before it, e.g. a connection.

Defaults to 10.

Source

pub fn max_key_queued_items( self, value: usize, ) -> LimitsBuilder<SetMaxKeyQueuedItems<S>>
where S::MaxKeyQueuedItems: IsUnset,

Optional (Some / Option setters).

Limits the number of items that can be queued for a key. Once reached, new items for the key are rejected, which is how the batcher pushes back on callers.

Items are queued until their batch starts processing, including while resources are being acquired for it.

The limit also bounds how much memory a key’s queued items use. A larger queue absorbs bigger bursts, but uses more memory, and items can wait longer in it. If callers give up after a timeout, an item that would wait longer than that is better rejected straight away, so its caller finds out sooner.

Defaults to max_batch_size * max_key_concurrency * 2.

Source

pub fn maybe_max_key_queued_items( self, value: Option<usize>, ) -> LimitsBuilder<SetMaxKeyQueuedItems<S>>
where S::MaxKeyQueuedItems: IsUnset,

Optional (Some / Option setters).

Limits the number of items that can be queued for a key. Once reached, new items for the key are rejected, which is how the batcher pushes back on callers.

Items are queued until their batch starts processing, including while resources are being acquired for it.

The limit also bounds how much memory a key’s queued items use. A larger queue absorbs bigger bursts, but uses more memory, and items can wait longer in it. If callers give up after a timeout, an item that would wait longer than that is better rejected straight away, so its caller finds out sooner.

Defaults to max_batch_size * max_key_concurrency * 2.

Source

pub fn max_items_awaiting_worker( self, value: usize, ) -> LimitsBuilder<SetMaxItemsAwaitingWorker<S>>
where S::MaxItemsAwaitingWorker: IsUnset,

Optional (Some / Option setters).

Limits the number of items, across all keys, that have been submitted with Batcher::add() but not yet accepted by the background worker. Once this is reached, add() waits for room before submitting its item.

This is a buffer for when the worker itself falls behind, e.g. when the runtime is short of CPU. It is not a queue limit, and on its own it does not shed load:

  • The worker usually accepts items much faster than they are processed. When processing is the bottleneck, the per-key limits reject items and this buffer stays nearly empty.
  • It bounds the buffer, not the number of callers waiting for room. Waiting slows down callers that limit their own concurrency, but callers that spawn a task per request just queue up in those tasks instead.
  • It is shared by all keys, so items for a key whose queue is full still take up room until the worker reads and rejects them.

A larger buffer hides more latency when the worker is overloaded, and a smaller one makes callers wait sooner. To shed load, rely on the per-key limits, and limit how many calls to add() are in flight. Time spent waiting for room is included in the channel_duration reported to MetricsRecorder::item_received().

Defaults to the maximum number of items one key can have in the system, max_batch_size * max_key_concurrency + max_key_queued_items. With many keys and small per-key limits, consider raising it, because the default may be smaller than normal bursts across all keys.

Source

pub fn maybe_max_items_awaiting_worker( self, value: Option<usize>, ) -> LimitsBuilder<SetMaxItemsAwaitingWorker<S>>
where S::MaxItemsAwaitingWorker: IsUnset,

Optional (Some / Option setters).

Limits the number of items, across all keys, that have been submitted with Batcher::add() but not yet accepted by the background worker. Once this is reached, add() waits for room before submitting its item.

This is a buffer for when the worker itself falls behind, e.g. when the runtime is short of CPU. It is not a queue limit, and on its own it does not shed load:

  • The worker usually accepts items much faster than they are processed. When processing is the bottleneck, the per-key limits reject items and this buffer stays nearly empty.
  • It bounds the buffer, not the number of callers waiting for room. Waiting slows down callers that limit their own concurrency, but callers that spawn a task per request just queue up in those tasks instead.
  • It is shared by all keys, so items for a key whose queue is full still take up room until the worker reads and rejects them.

A larger buffer hides more latency when the worker is overloaded, and a smaller one makes callers wait sooner. To shed load, rely on the per-key limits, and limit how many calls to add() are in flight. Time spent waiting for room is included in the channel_duration reported to MetricsRecorder::item_received().

Defaults to the maximum number of items one key can have in the system, max_batch_size * max_key_concurrency + max_key_queued_items. With many keys and small per-key limits, consider raising it, because the default may be smaller than normal bursts across all keys.

Source§

impl<S: State> LimitsBuilder<S>

Source

pub fn max_batch_queue_size( self, max_batch_queue_size: usize, ) -> LimitsBuilder<SetMaxBatchQueueSize<S>>
where S::MaxBatchQueueSize: IsUnset,

👎Deprecated:

use max_key_queued_items, which counts items

Limits the number of items that can be queued for a key to max_batch_queue_size * max_batch_size.

Ignored if max_key_queued_items is set.

Source

pub fn maybe_max_batch_queue_size( self, max_batch_queue_size: Option<usize>, ) -> LimitsBuilder<SetMaxBatchQueueSize<S>>
where S::MaxBatchQueueSize: IsUnset,

👎Deprecated:

use maybe_max_key_queued_items, which counts items

Like max_batch_queue_size, but None leaves it unset.

Auto Trait Implementations§

§

impl<S> Forget for LimitsBuilder<S>

§

impl<S> Freeze for LimitsBuilder<S>
where PhantomData<(fn() -> S, fn() -> PhantomData<Limits>)>: Freeze,

§

impl<S> RefUnwindSafe for LimitsBuilder<S>
where PhantomData<(fn() -> S, fn() -> PhantomData<Limits>)>: RefUnwindSafe,

§

impl<S> Send for LimitsBuilder<S>
where PhantomData<(fn() -> S, fn() -> PhantomData<Limits>)>: Send,

§

impl<S> Sync for LimitsBuilder<S>
where PhantomData<(fn() -> S, fn() -> PhantomData<Limits>)>: Sync,

§

impl<S> Unpin for LimitsBuilder<S>
where PhantomData<(fn() -> S, fn() -> PhantomData<Limits>)>: Unpin,

§

impl<S> UnsafeUnpin for LimitsBuilder<S>
where PhantomData<(fn() -> S, fn() -> PhantomData<Limits>)>: UnsafeUnpin,

§

impl<S> UnwindSafe for LimitsBuilder<S>
where PhantomData<(fn() -> S, fn() -> PhantomData<Limits>)>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more