提交 b345b366 编写于 作者: J Jay Edgar

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
上级 dff4c48e
......@@ -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_;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册