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]

[src]

Formats the value using the given formatter.

impl Clone for GCRA
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Decider for GCRA
[src]

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.

[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

[src]

Converts the limiter builder into a concrete decider structure.

[src]

Tests if a single cell can be accomodated now. See test_and_update.