pub struct PoolCircuitBreakerLink { /* private fields */ }Expand description
连接池-熔断器联动(v7.6.0)
当熔断器触发(Open 状态)时自动缩减池容量, 熔断器恢复(HalfOpen → Closed)时恢复至调优参数。
目标:故障期间错误率降低 ≥ 50%,避免故障期间连接耗尽。
§使用方式
调用方在 CircuitBreaker 状态变化时调用对应方法:
CircuitState::Open→shrink_pool(factor)CircuitState::Closed(从 HalfOpen 恢复)→expand_pool()
Implementations§
Source§impl PoolCircuitBreakerLink
impl PoolCircuitBreakerLink
Sourcepub fn shrink_pool(&mut self, factor: f64) -> u32
pub fn shrink_pool(&mut self, factor: f64) -> u32
缩减池容量(熔断器 Open 时调用)
factor 为缩容因子(0.0 ~ 1.0),例如 0.5 表示缩减至 50%。
最小容量为 1,避免完全无连接可用。
Sourcepub fn expand_pool(&mut self) -> u32
pub fn expand_pool(&mut self) -> u32
恢复池容量至调优参数(熔断器 Closed 时调用)
Sourcepub fn current_capacity(&self) -> u32
pub fn current_capacity(&self) -> u32
当前池容量
Sourcepub fn original_capacity(&self) -> u32
pub fn original_capacity(&self) -> u32
原始池容量
Sourcepub fn shrink_count(&self) -> u64
pub fn shrink_count(&self) -> u64
缩容次数
Sourcepub fn expand_count(&self) -> u64
pub fn expand_count(&self) -> u64
扩容次数
Sourcepub fn on_circuit_state_change(&mut self, is_open: bool) -> u32
pub fn on_circuit_state_change(&mut self, is_open: bool) -> u32
熔断器状态变化回调
当 is_open 为 true 时缩容,为 false 时恢复。
返回调整后的池容量。
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for PoolCircuitBreakerLink
impl RefUnwindSafe for PoolCircuitBreakerLink
impl Send for PoolCircuitBreakerLink
impl Sync for PoolCircuitBreakerLink
impl Unpin for PoolCircuitBreakerLink
impl UnsafeUnpin for PoolCircuitBreakerLink
impl UnwindSafe for PoolCircuitBreakerLink
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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