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 requests per second. This translates to the GCRA parameters τ=1s, T=50ms.
let mut limiter = Limiter::new().capacity(20).weight(1).build::<GCRA>().unwrap(); let now = Instant::now(); let ms = Duration::from_millis(1); assert_eq!(Decision::Yes, limiter.test_and_update(now)); // the first cell is free for i in 0..20 { // Spam a lot: assert_eq!(Decision::Yes, limiter.test_and_update(now), "at {}", i); } // We have exceeded the bucket capacity: assert!(!limiter.test_and_update(now).is_compliant()); // After a sufficient time period, cells are allowed again: assert_eq!(Decision::Yes, limiter.test_and_update(now + ms*50));
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 Decider 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) -> 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
fn build_with(l: &Limiter) -> Result<Self>
[src]
Converts the limiter builder into a concrete decider structure.
fn check(&mut self) -> Decision<Self::T>
[src]
Tests if a single cell can be accomodated now. See test_and_update
.