Struct ratelimit_meter::GCRA
[−]
[src]
pub struct GCRA { /* fields omitted */ }
Implements the virtual scheduling description of the Generic Cell Rate Algorithm, attributed to ITU-T in recommendation I.371 Traffic control and congestion control in B-ISDN; from Wikipedia.
Example
In this example, we construct a rate-limiter with the GCR algorithm that can accomodate 20 cells per second. This translates to the GCRA parameters τ=1s, T=50ms (that's 1s / 20 cells).
let mut limiter = GCRA::for_capacity(20).cell_weight(1).build(); let now = Instant::now(); let ms = Duration::from_millis(1); assert_eq!(Decision::Yes, limiter.check_at(now).unwrap()); // the first cell is free for i in 0..20 { // Spam a lot: assert_eq!(Decision::Yes, limiter.check_at(now).unwrap(), "at {}", i); } // We have exceeded the bucket capacity: assert!(!limiter.check_at(now).unwrap().is_compliant()); // After a sufficient time period, cells are allowed again: assert_eq!(Decision::Yes, limiter.check_at(now + ms*50).unwrap());
Methods
impl GCRA
[src]
fn for_capacity(capacity: u32) -> Builder
[src]
Constructs a builder object for a GCRA rate-limiter with the
given capacity per second, at cell weight=1. See
Builder
for options.
Trait Implementations
impl Debug for GCRA
[src]
impl Clone for GCRA
[src]
fn clone(&self) -> GCRA
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl DeciderImpl for GCRA
[src]
type T = Instant
In GCRA, negative decisions come with the time at which the next cell was expected to arrive; client code of GCRA can use this to decide what to do with the non-conforming cell.
fn test_and_update(&mut self, t0: Instant) -> Result<Decision<Instant>>
[src]
Tests if a single cell can be accomodated in the rate limiter at the instant at
and updates the rate-limiter to account for the weight of the cell. Read more
impl Decider for GCRA
[src]
fn check(&mut self) -> Result<Decision<Self::T>>
[src]
Tests if a single cell can be accomodated at Instant::now()
. See check_at
. Read more
fn check_at(&mut self, at: Instant) -> Result<Decision<Self::T>>
[src]
Tests is a single cell can be accomodated at the given time stamp. Read more
impl From<Builder> for GCRA
[src]
Allows converting from a GCRA builder directly into a
GCRA decider. Same as
the borrowed implementation, except for
owned Builder
s.
Example:
use ratelimit_meter::{GCRA, Decider, Decision}; let mut gcra: GCRA = GCRA::for_capacity(50).into(); assert_eq!(Decision::Yes, gcra.check().unwrap());
impl<'a> From<&'a mut Builder> for GCRA
[src]
Allows converting a GCRA builder directly into a GCRA decider.
Example:
use ratelimit_meter::{GCRA, Decider, Decision}; let mut gcra: GCRA = GCRA::for_capacity(50).cell_weight(2).into(); assert_eq!(Decision::Yes, gcra.check().unwrap());