mirror of
https://git.proxmox.com/git/proxmox
synced 2025-08-07 11:06:02 +00:00
RateLimiter: add update_rate method
This commit is contained in:
parent
0c27d5da17
commit
2f221df863
@ -34,6 +34,17 @@ impl RateLimiter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Update rate and bucket size
|
||||||
|
pub fn update_rate(&mut self, rate: u64, bucket_size: u64) {
|
||||||
|
self.rate = rate;
|
||||||
|
|
||||||
|
if bucket_size < self.bucket_size && self.consumed_tokens > bucket_size {
|
||||||
|
self.consumed_tokens = bucket_size; // start again
|
||||||
|
}
|
||||||
|
|
||||||
|
self.bucket_size = bucket_size;
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the average rate (since `start_time`)
|
/// Returns the average rate (since `start_time`)
|
||||||
pub fn average_rate(&self, current_time: Instant) -> f64 {
|
pub fn average_rate(&self, current_time: Instant) -> f64 {
|
||||||
let time_diff = current_time.saturating_duration_since(self.start_time).as_secs_f64();
|
let time_diff = current_time.saturating_duration_since(self.start_time).as_secs_f64();
|
||||||
|
Loading…
Reference in New Issue
Block a user