Skip to main content

PoolCircuitBreakerLink

Struct PoolCircuitBreakerLink 

Source
pub struct PoolCircuitBreakerLink { /* private fields */ }
Expand description

连接池-熔断器联动(v7.6.0)

当熔断器触发(Open 状态)时自动缩减池容量, 熔断器恢复(HalfOpen → Closed)时恢复至调优参数。

目标:故障期间错误率降低 ≥ 50%,避免故障期间连接耗尽。

§使用方式

调用方在 CircuitBreaker 状态变化时调用对应方法:

  • CircuitState::Openshrink_pool(factor)
  • CircuitState::Closed(从 HalfOpen 恢复)→ expand_pool()

Implementations§

Source

pub fn new(original_capacity: u32) -> Self

创建新的池-熔断器联动

original_capacity 为调优后的池容量,故障恢复时恢复至此值。

Source

pub fn shrink_pool(&mut self, factor: f64) -> u32

缩减池容量(熔断器 Open 时调用)

factor 为缩容因子(0.0 ~ 1.0),例如 0.5 表示缩减至 50%。 最小容量为 1,避免完全无连接可用。

Source

pub fn expand_pool(&mut self) -> u32

恢复池容量至调优参数(熔断器 Closed 时调用)

Source

pub fn current_capacity(&self) -> u32

当前池容量

Source

pub fn original_capacity(&self) -> u32

原始池容量

Source

pub fn shrink_count(&self) -> u64

缩容次数

Source

pub fn expand_count(&self) -> u64

扩容次数

Source

pub fn is_shrunk(&self) -> bool

是否已缩容

Source

pub fn on_circuit_state_change(&mut self, is_open: bool) -> u32

熔断器状态变化回调

is_open 为 true 时缩容,为 false 时恢复。 返回调整后的池容量。

Trait Implementations§

Source§

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

Formats the value using the given formatter. Read more

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<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