pub async fn async_consume(&self, sample: Sample) -> Duration {
        let cpu_dur = if sample.cpu_time > Duration::ZERO {
            self.cputime_limiter
                .consume_duration(sample.cpu_time.as_micros() as usize)
        } else {
            Duration::ZERO
        };

        let w_bw_dur = if sample.write_bytes > 0 {
            self.write_bandwidth_limiter
                .consume_duration(sample.write_bytes)
        } else {
            Duration::ZERO
        };

        let r_bw_dur = if sample.read_bytes > 0 {
            self.read_bandwidth_limiter
                .consume_duration(sample.read_bytes)
        } else {
            Duration::ZERO
        };

        let max_dur = std::cmp::max(cpu_dur, std::cmp::max(w_bw_dur, r_bw_dur));
        let should_delay = if max_dur > sample.cpu_time {
            max_dur - sample.cpu_time
        } else {
            Duration::ZERO
        };
        let exec_delay = std::cmp::min(MAX_QUOTA_DELAY, should_delay);

        if !exec_delay.is_zero() {
            GLOBAL_TIMER_HANDLE
                .delay(std::time::Instant::now() + exec_delay)
                .compat()
                .await
                .unwrap();
        }

        exec_delay
    }
// To consume a sampler and return delayed duration.
// If the sampler is null, the speed limiter will just return ZERO.
To consume a sampler and return delayed duration.
If the sampler is null, the speed limiter will just return ZERO.
To consume a sampler and return delayed duration . If the sampler is null the speed limiter will just return ZERO .
pub async fn async_consume(&self, sample: Sample) -> Duration {
        let cpu_dur = if sample.cpu_time > Duration::ZERO {
            self.cputime_limiter
                .consume_duration(sample.cpu_time.as_micros() as usize)
        } else {
            Duration::ZERO
        };
        let w_bw_dur = if sample.write_bytes > 0 {
            self.write_bandwidth_limiter
                .consume_duration(sample.write_bytes)
        } else {
            Duration::ZERO
        };
        let r_bw_dur = if sample.read_bytes > 0 {
            self.read_bandwidth_limiter
                .consume_duration(sample.read_bytes)
        } else {
            Duration::ZERO
        };
        let max_dur = std::cmp::max(cpu_dur, std::cmp::max(w_bw_dur, r_bw_dur));
        let should_delay = if max_dur > sample.cpu_time {
            max_dur - sample.cpu_time
        } else {
            Duration::ZERO
        };
        let exec_delay = std::cmp::min(MAX_QUOTA_DELAY, should_delay);
        if !exec_delay.is_zero() {
            GLOBAL_TIMER_HANDLE
                .delay(std::time::Instant::now() + exec_delay)
                .compat()
                .await
                .unwrap();
        }
        exec_delay
    }
pub async fn async_consume ( & self , sample : Sample ) -> Duration { let cpu_dur = if sample . cpu_time > Duration :: ZERO { self . cputime_limiter . consume_duration ( sample . cpu_time . as_micros ( ) as usize ) } else { Duration :: ZERO } ; let w_bw_dur = if sample . write_bytes > 0 { self . write_bandwidth_limiter . consume_duration ( sample . write_bytes ) } else { Duration :: ZERO } ; let r_bw_dur = if sample . read_bytes > 0 { self . read_bandwidth_limiter . consume_duration ( sample . read_bytes ) } else { Duration :: ZERO } ; let max_dur = std :: cmp :: max ( cpu_dur , std :: cmp :: max ( w_bw_dur , r_bw_dur ) ) ; let should_delay = if max_dur > sample . cpu_time { max_dur - sample . cpu_time } else { Duration :: ZERO } ; let exec_delay = std :: cmp :: min ( MAX_QUOTA_DELAY , should_delay ) ; if ! exec_delay . is_zero ( ) { GLOBAL_TIMER_HANDLE . delay ( std :: time :: Instant :: now ( ) + exec_delay ) . compat ( ) . await . unwrap ( ) ; } exec_delay }
To consume a sampler and return delayed duration.
To consume a sampler and return delayed duration .
&self
sample
Sample
&self
sample
Sample