diff --git a/util/rate_limiter.h b/util/rate_limiter.h index d413d9c6e3..ea2975d643 100644 --- a/util/rate_limiter.h +++ b/util/rate_limiter.h @@ -9,6 +9,7 @@ #pragma once +#include #include #include #include "port/port.h" @@ -60,12 +61,15 @@ class GenericRateLimiter : public RateLimiter { private: void Refill(); int64_t CalculateRefillBytesPerPeriod(int64_t rate_bytes_per_sec) { - return rate_bytes_per_sec * refill_period_us_ / 1000000; + return std::max(kMinRefillBytesPerPeriod, + rate_bytes_per_sec * refill_period_us_ / 1000000); } // This mutex guard all internal states mutable port::Mutex request_mutex_; + const int64_t kMinRefillBytesPerPeriod = 100; + const int64_t refill_period_us_; // This variable can be changed dynamically. std::atomic refill_bytes_per_period_;