pub fn new(
        bytes_total_capacity: u64,
        bytes_one_time_burst: u64,
        bytes_complete_refill_time_ms: u64,
        ops_total_capacity: u64,
        ops_one_time_burst: u64,
        ops_complete_refill_time_ms: u64,
    ) -> io::Result<Self> {
        let bytes_token_bucket = TokenBucket::new(
            bytes_total_capacity,
            bytes_one_time_burst,
            bytes_complete_refill_time_ms,
        );

        let ops_token_bucket = TokenBucket::new(
            ops_total_capacity,
            ops_one_time_burst,
            ops_complete_refill_time_ms,
        );

        // We'll need a timer_fd, even if our current config effectively disables rate limiting,
        // because `Self::update_buckets()` might re-enable it later, and we might be
        // seccomp-blocked from creating the timer_fd at that time.
        let timer_fd = TimerFd::new_custom(ClockId::Monotonic, true, true)?;

        Ok(RateLimiter {
            bandwidth: bytes_token_bucket,
            ops: ops_token_bucket,
            timer_fd,
            timer_active: false,
        })
    }
/// Creates a new Rate Limiter that can limit on both bytes/s and ops/s.
///
/// # Arguments
///
/// * `bytes_total_capacity` - the total capacity of the `TokenType::Bytes` token bucket.
/// * `bytes_one_time_burst` - initial extra credit on top of `bytes_total_capacity`,
/// that does not replenish and which can be used for an initial burst of data.
/// * `bytes_complete_refill_time_ms` - number of milliseconds for the `TokenType::Bytes`
/// token bucket to go from zero Bytes to `bytes_total_capacity` Bytes.
/// * `ops_total_capacity` - the total capacity of the `TokenType::Ops` token bucket.
/// * `ops_one_time_burst` - initial extra credit on top of `ops_total_capacity`,
/// that does not replenish and which can be used for an initial burst of data.
/// * `ops_complete_refill_time_ms` - number of milliseconds for the `TokenType::Ops` token
/// bucket to go from zero Ops to `ops_total_capacity` Ops.
///
/// If either bytes/ops *size* or *refill_time* are **zero**, the limiter
/// is **disabled** for that respective token type.
///
/// # Errors
///
/// If the timerfd creation fails, an error is returned.
Creates a new Rate Limiter that can limit on both bytes/s and ops/s.
Creates a new Rate Limiter that can limit on both bytes / s and ops / s .
pub fn new(
        bytes_total_capacity: u64,
        bytes_one_time_burst: u64,
        bytes_complete_refill_time_ms: u64,
        ops_total_capacity: u64,
        ops_one_time_burst: u64,
        ops_complete_refill_time_ms: u64,
    ) -> io::Result<Self> {
        let bytes_token_bucket = TokenBucket::new(
            bytes_total_capacity,
            bytes_one_time_burst,
            bytes_complete_refill_time_ms,
        );
        let ops_token_bucket = TokenBucket::new(
            ops_total_capacity,
            ops_one_time_burst,
            ops_complete_refill_time_ms,
        );
        // We'll need a timer_fd, even if our current config effectively disables rate limiting,
        // because `Self::update_buckets()` might re-enable it later, and we might be
        // seccomp-blocked from creating the timer_fd at that time.
        let timer_fd = TimerFd::new_custom(ClockId::Monotonic, true, true)?;
        Ok(RateLimiter {
            bandwidth: bytes_token_bucket,
            ops: ops_token_bucket,
            timer_fd,
            timer_active: false,
        })
    }
pub fn new ( bytes_total_capacity : u64 , bytes_one_time_burst : u64 , bytes_complete_refill_time_ms : u64 , ops_total_capacity : u64 , ops_one_time_burst : u64 , ops_complete_refill_time_ms : u64 , ) -> io :: Result < Self > { let bytes_token_bucket = TokenBucket :: new ( bytes_total_capacity , bytes_one_time_burst , bytes_complete_refill_time_ms , ) ; let ops_token_bucket = TokenBucket :: new ( ops_total_capacity , ops_one_time_burst , ops_complete_refill_time_ms , ) ; // We'll need a timer_fd, even if our current config effectively disables rate limiting, // because `Self::update_buckets()` might re-enable it later, and we might be // seccomp-blocked from creating the timer_fd at that time. let timer_fd = TimerFd :: new_custom ( ClockId :: Monotonic , true , true ) ? ; Ok ( RateLimiter { bandwidth : bytes_token_bucket , ops : ops_token_bucket , timer_fd , timer_active : false , } ) }
Creates a new Rate Limiter that can limit on both bytes/s and ops/s.
Creates a new Rate Limiter that can limit on both bytes / s and ops / s .
bytes_total_capacity
u64
bytes_one_time_burst
u64
bytes_complete_refill_time_ms
u64
ops_total_capacity
u64
ops_one_time_burst
u64
ops_complete_refill_time_ms
u64
bytes_total_capacity
u64
bytes_one_time_burst
u64
bytes_complete_refill_time_ms
u64
ops_total_capacity
u64
ops_one_time_burst
u64
ops_complete_refill_time_ms
u64
errors
If the timerfd creation fails, an error is returned.
If the timerfd creation fails an error is returned .