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>
impl<S: State> LimitsBuilder<S>
Sourcepub fn build(self) -> Limitswhere
S: IsComplete,
pub fn build(self) -> Limitswhere
S: IsComplete,
Finishes building and performs the requested action.
Sourcepub fn max_batch_size(self, value: usize) -> LimitsBuilder<SetMaxBatchSize<S>>where
S::MaxBatchSize: IsUnset,
pub fn max_batch_size(self, value: usize) -> LimitsBuilder<SetMaxBatchSize<S>>where
S::MaxBatchSize: IsUnset,
Sourcepub fn maybe_max_batch_size(
self,
value: Option<usize>,
) -> LimitsBuilder<SetMaxBatchSize<S>>where
S::MaxBatchSize: IsUnset,
pub fn maybe_max_batch_size(
self,
value: Option<usize>,
) -> LimitsBuilder<SetMaxBatchSize<S>>where
S::MaxBatchSize: IsUnset,
Sourcepub fn max_key_concurrency(
self,
value: usize,
) -> LimitsBuilder<SetMaxKeyConcurrency<S>>where
S::MaxKeyConcurrency: IsUnset,
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.
Sourcepub fn maybe_max_key_concurrency(
self,
value: Option<usize>,
) -> LimitsBuilder<SetMaxKeyConcurrency<S>>where
S::MaxKeyConcurrency: IsUnset,
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.
Sourcepub fn max_key_queued_items(
self,
value: usize,
) -> LimitsBuilder<SetMaxKeyQueuedItems<S>>where
S::MaxKeyQueuedItems: IsUnset,
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.
Sourcepub fn maybe_max_key_queued_items(
self,
value: Option<usize>,
) -> LimitsBuilder<SetMaxKeyQueuedItems<S>>where
S::MaxKeyQueuedItems: IsUnset,
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.
Sourcepub fn max_items_awaiting_worker(
self,
value: usize,
) -> LimitsBuilder<SetMaxItemsAwaitingWorker<S>>where
S::MaxItemsAwaitingWorker: IsUnset,
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.
Sourcepub fn maybe_max_items_awaiting_worker(
self,
value: Option<usize>,
) -> LimitsBuilder<SetMaxItemsAwaitingWorker<S>>where
S::MaxItemsAwaitingWorker: IsUnset,
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>
impl<S: State> LimitsBuilder<S>
Sourcepub 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
pub fn max_batch_queue_size(
self,
max_batch_queue_size: usize,
) -> LimitsBuilder<SetMaxBatchQueueSize<S>>where
S::MaxBatchQueueSize: IsUnset,
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.
Sourcepub 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
pub fn maybe_max_batch_queue_size(
self,
max_batch_queue_size: Option<usize>,
) -> LimitsBuilder<SetMaxBatchQueueSize<S>>where
S::MaxBatchQueueSize: IsUnset,
use maybe_max_key_queued_items, which counts items
Like max_batch_queue_size, but None leaves it unset.