Skip to content

Commit

Permalink
fix new write amp io-limiter (tikv#350)
Browse files Browse the repository at this point in the history
Signed-off-by: glorv <[email protected]>
  • Loading branch information
glorv authored Oct 10, 2023
1 parent 0813e37 commit 938c016
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
6 changes: 2 additions & 4 deletions utilities/rate_limiters/write_amp_based_rate_limiter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,8 @@ WriteAmpBasedRateLimiter::WriteAmpBasedRateLimiter(
critical_pace_up_(false),
normal_pace_up_(false),
percent_delta_(0) {
total_requests_[0] = 0;
total_requests_[1] = 0;
total_bytes_through_[0] = 0;
total_bytes_through_[1] = 0;
std::fill(total_requests_, total_requests_ + Env::IO_TOTAL, 0);
std::fill(total_bytes_through_, total_bytes_through_ + Env::IO_TOTAL, 0);
}

WriteAmpBasedRateLimiter::~WriteAmpBasedRateLimiter() {
Expand Down
2 changes: 1 addition & 1 deletion utilities/rate_limiters/write_amp_based_rate_limiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class WriteAmpBasedRateLimiter : public RateLimiter {
WindowSmoother(size_t smooth_window_size, size_t recent_window_size)
: smooth_window_size_(smooth_window_size),
recent_window_size_(recent_window_size),
data_(0, smooth_window_size) {}
data_(smooth_window_size, 0) {}
void AddSample(int64_t v) {
auto recent_cursor =
(cursor_ + 1 + smooth_window_size_ - recent_window_size_) %
Expand Down
21 changes: 20 additions & 1 deletion utilities/rate_limiters/write_amp_based_rate_limiter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,25 @@ TEST_F(WriteAmpBasedRateLimiterTest, Modes) {
}
}

TEST_F(WriteAmpBasedRateLimiterTest, AutoTune) {
auto* thread_env = Env::Default();
WriteAmpBasedRateLimiter limiter(
10000 /* rate_bytes_per_sec */, 1000 * 1000 /* refill_period_us */,
10 /* fairness */, RateLimiter::Mode::kAllIo, Env::Default(),
true /* auto_tuned */, 1 /* secs_per_tune */, 100 /* smooth_window */,
10 /* recent_window */);
limiter.Request(8000 /* bytes */, Env::IO_HIGH, nullptr /* stats */,
RateLimiter::OpType::kWrite);
ASSERT_EQ(8000, limiter.GetTotalBytesThrough(Env::IO_HIGH));

thread_env->SleepForMicroseconds(1000 * 1000);
// request from low io can trigger auto tune.
limiter.Request(1000 /* bytes */, Env::IO_LOW, nullptr /* stats */,
RateLimiter::OpType::kWrite);
ASSERT_EQ(10485760, limiter.GetBytesPerSecond());
// TODO: add more logic for auto-tune
}

#if !(defined(TRAVIS) && defined(OS_MACOSX))
TEST_F(WriteAmpBasedRateLimiterTest, Rate) {
auto* env = Env::Default();
Expand Down Expand Up @@ -154,7 +173,7 @@ TEST_F(WriteAmpBasedRateLimiterTest, LimitChangeTest) {
std::shared_ptr<RateLimiter> limiter =
std::make_shared<WriteAmpBasedRateLimiter>(
target, refill_period, 10, RateLimiter::Mode::kWritesOnly,
Env::Default(), false /* auto_tuned */);
Env::Default(), false /* auto_tuned */, 1, 300, 30);
rocksdb::SyncPoint::GetInstance()->LoadDependency(
{{"WriteAmpBasedRateLimiter::Request",
"WriteAmpBasedRateLimiterTest::LimitChangeTest:changeLimitStart"},
Expand Down

0 comments on commit 938c016

Please sign in to comment.