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]

[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]

[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 DeciderImpl 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

impl Decider for GCRA
[src]

[src]

Tests if a single cell can be accomodated at Instant::now(). See check_at. Read more

[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 Builders.

Example:

use ratelimit_meter::{GCRA, Decider, Decision};
let mut gcra: GCRA = GCRA::for_capacity(50).into();
assert_eq!(Decision::Yes, gcra.check().unwrap());

[src]

Performs the conversion.

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());

[src]

Performs the conversion.