Struct tower::balance::pool::Builder

source ·
pub struct Builder { /* private fields */ }
Expand description

A builder that lets you configure how a Pool determines whether the underlying service is loaded or not. See the module-level documentation and the builder’s methods for details.

Implementations§

source§

impl Builder

source

pub fn new() -> Self

Create a new builder with default values for all load settings.

If you just want to use the defaults, you can just use Pool::new.

source

pub fn underutilized_below(&mut self, low: f64) -> &mut Self

When the estimated load (see the module-level docs) drops below this threshold, and there are at least two services active, a service is removed.

The default value is 0.01. That is, when one in every 100 poll_ready calls return Pending, then the underlying service is considered underutilized.

source

pub fn loaded_above(&mut self, high: f64) -> &mut Self

When the estimated load (see the module-level docs) exceeds this threshold, and no service is currently in the process of being added, a new service is scheduled to be added to the underlying Balance.

The default value is 0.5. That is, when every other call to poll_ready returns Pending, then the underlying service is considered highly loaded.

source

pub fn initial(&mut self, init: f64) -> &mut Self

The initial estimated load average.

This is also the value that the estimated load will be reset to whenever a service is added or removed.

The default value is 0.1.

source

pub fn urgency(&mut self, alpha: f64) -> &mut Self

How aggressively the estimated load average is updated.

This is the α parameter of the formula for the exponential moving average, and dictates how quickly new samples of the current load affect the estimated load. If the value is closer to 1, newer samples affect the load average a lot (when α is 1, the load average is immediately set to the current load). If the value is closer to 0, newer samples affect the load average very little at a time.

The given value is clamped to [0,1].

The default value is 0.05, meaning, in very approximate terms, that each new load sample affects the estimated load by 5%.

source

pub fn max_services(&mut self, limit: Option<usize>) -> &mut Self

The maximum number of backing Service instances to maintain.

When the limit is reached, the load estimate is clamped to the high load threshhold, and no new service is spawned.

No maximum limit is imposed by default.

source

pub fn build<MS, Target, Request>( &self, make_service: MS, target: Target, ) -> Pool<MS, Target, Request>
where MS: MakeService<Target, Request>, MS::Service: Load, <MS::Service as Load>::Metric: Debug, MS::MakeError: Into<BoxError>, MS::Error: Into<BoxError>, Target: Clone,

See Pool::new.

Trait Implementations§

source§

impl Clone for Builder

source§

fn clone(&self) -> Builder

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Builder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Builder

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Copy for Builder

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

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