pub struct LeakBucket {
pub(crate) scale: AtomicU64,
pub(crate) ltat: AtomicU64,
pub(crate) origin: Instant,
pub(crate) total_allowed_quotas: AtomicU64,
pub(crate) total_waited_nanos: AtomicI64,
}Expand description
A GCRA-like leak bucket visual scheduler that never deny request even whose weight is larger than tau and only count TAT.
Fields§
§scale: AtomicU64Weight scale per 1.0 unit quota in nanosecond.
scale is always non-zero.
scale = rate / 1 (in second)
ltat: AtomicU64Last request’s TAT (Theoretical Arrival Time) in nanosecond.
origin: InstantZero time instant.
total_allowed_quotas: AtomicU64Total allowed quotas.
total_waited_nanos: AtomicI64Total waited nanos.
Implementations§
Source§impl LeakBucket
impl LeakBucket
pub(crate) const NANO: u64 = 1_000_000_000u64
Sourcepub(crate) fn scale(rate: NonZeroU64) -> u64
pub(crate) fn scale(rate: NonZeroU64) -> u64
calculate the weight scale per 1.0 unit quota in nanosecond.
Sourcepub(crate) fn new(rate: NonZeroU64) -> Self
pub(crate) fn new(rate: NonZeroU64) -> Self
Create a new GCRA-like leak bucket visual scheduler with given rate.
Sourcepub(crate) fn check(&self, quota: u64) -> Result<(), Duration>
pub(crate) fn check(&self, quota: u64) -> Result<(), Duration>
Check if the request with the given quota is supposed to be allowed at the moment.
On success, the quota will be consumed. The caller is supposed to proceed the quota.
On failure, the minimal duration to retry check() is returned.
Sourcepub(crate) fn _avg_wait_nanos_per_quota(&self) -> i64
pub(crate) fn _avg_wait_nanos_per_quota(&self) -> i64
Average wait time per quota.
Positive value indicates waits, negative value indicates there is spare rate limit.
Sourcepub(crate) fn _reset_stats(&self)
pub(crate) fn _reset_stats(&self)
Reset statistics.
Sourcepub(crate) fn _update(&self, rate: NonZeroU64)
pub(crate) fn _update(&self, rate: NonZeroU64)
Update rate limit with the given rate.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for LeakBucket
impl RefUnwindSafe for LeakBucket
impl Send for LeakBucket
impl Sync for LeakBucket
impl Unpin for LeakBucket
impl UnwindSafe for LeakBucket
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
§impl<T> Downcast for Twhere
T: AsAny + ?Sized,
impl<T> Downcast for Twhere
T: AsAny + ?Sized,
§fn downcast_ref<T>(&self) -> Option<&T>where
T: AsAny,
fn downcast_ref<T>(&self) -> Option<&T>where
T: AsAny,
Any.§fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: AsAny,
fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: AsAny,
Any.§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
type Err = Infallible
fn into_result(self) -> Result<T, <T as IntoResult<T>>::Err>
Source§impl<M> MetricVecRelabelExt for M
impl<M> MetricVecRelabelExt for M
Source§fn relabel(
self,
metric_level: MetricLevel,
relabel_threshold: MetricLevel,
) -> RelabeledMetricVec<M>
fn relabel( self, metric_level: MetricLevel, relabel_threshold: MetricLevel, ) -> RelabeledMetricVec<M>
RelabeledMetricVec::with_metric_level.Source§fn relabel_n(
self,
metric_level: MetricLevel,
relabel_threshold: MetricLevel,
relabel_num: usize,
) -> RelabeledMetricVec<M>
fn relabel_n( self, metric_level: MetricLevel, relabel_threshold: MetricLevel, relabel_num: usize, ) -> RelabeledMetricVec<M>
RelabeledMetricVec::with_metric_level_relabel_n.Source§fn relabel_debug_1(
self,
relabel_threshold: MetricLevel,
) -> RelabeledMetricVec<M>
fn relabel_debug_1( self, relabel_threshold: MetricLevel, ) -> RelabeledMetricVec<M>
RelabeledMetricVec::with_metric_level_relabel_n with metric_level set to
MetricLevel::Debug and relabel_num set to 1.