Add a minimum value for the refill bytes per period value
Summary: If the user specified a small enough value for the rate limiter's bytes per second, the calculation for the number of refill bytes per period could become zero which would effectively cause the server to hang forever. Test Plan: Existing tests Reviewers: sdong, yhchiang, igor Reviewed By: igor Subscribers: leveldb, andrewkr, dhruba Differential Revision: https://reviews.facebook.net/D56631
This commit is contained in:
parent
dff4c48ede
commit
b345b36620
@ -9,6 +9,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <deque>
|
||||
#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<int64_t> refill_bytes_per_period_;
|
||||
|
Loading…
Reference in New Issue
Block a user