2016-02-09 23:12:00 +00:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-15 23:03:42 +00:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
generic rate limiter
Summary:
A generic rate limiter that can be shared by threads and rocksdb
instances. Will use this to smooth out write traffic generated by
compaction and flush. This will help us get better p99 behavior on flash
storage.
Test Plan:
unit test output
==== Test RateLimiterTest.Rate
request size [1 - 1023], limit 10 KB/sec, actual rate: 10.374969 KB/sec, elapsed 2002265
request size [1 - 2047], limit 20 KB/sec, actual rate: 20.771242 KB/sec, elapsed 2002139
request size [1 - 4095], limit 40 KB/sec, actual rate: 41.285299 KB/sec, elapsed 2202424
request size [1 - 8191], limit 80 KB/sec, actual rate: 81.371605 KB/sec, elapsed 2402558
request size [1 - 16383], limit 160 KB/sec, actual rate: 162.541268 KB/sec, elapsed 3303500
Reviewers: yhchiang, igor, sdong
Reviewed By: sdong
Subscribers: leveldb
Differential Revision: https://reviews.facebook.net/D19359
2014-07-08 18:41:57 +00:00
|
|
|
//
|
|
|
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
|
2017-10-05 02:02:22 +00:00
|
|
|
#include <chrono>
|
2019-09-20 19:00:55 +00:00
|
|
|
#include <cinttypes>
|
2021-08-31 17:59:14 +00:00
|
|
|
#include <cstdint>
|
generic rate limiter
Summary:
A generic rate limiter that can be shared by threads and rocksdb
instances. Will use this to smooth out write traffic generated by
compaction and flush. This will help us get better p99 behavior on flash
storage.
Test Plan:
unit test output
==== Test RateLimiterTest.Rate
request size [1 - 1023], limit 10 KB/sec, actual rate: 10.374969 KB/sec, elapsed 2002265
request size [1 - 2047], limit 20 KB/sec, actual rate: 20.771242 KB/sec, elapsed 2002139
request size [1 - 4095], limit 40 KB/sec, actual rate: 41.285299 KB/sec, elapsed 2202424
request size [1 - 8191], limit 80 KB/sec, actual rate: 81.371605 KB/sec, elapsed 2402558
request size [1 - 16383], limit 160 KB/sec, actual rate: 162.541268 KB/sec, elapsed 3303500
Reviewers: yhchiang, igor, sdong
Reviewed By: sdong
Subscribers: leveldb
Differential Revision: https://reviews.facebook.net/D19359
2014-07-08 18:41:57 +00:00
|
|
|
#include <limits>
|
2017-10-05 02:02:22 +00:00
|
|
|
|
|
|
|
#include "db/db_test_util.h"
|
2021-09-10 15:35:59 +00:00
|
|
|
#include "port/port.h"
|
2021-01-26 06:07:26 +00:00
|
|
|
#include "rocksdb/system_clock.h"
|
2023-08-30 01:39:10 +00:00
|
|
|
#include "test_util/mock_time_env.h"
|
2019-05-30 18:21:38 +00:00
|
|
|
#include "test_util/sync_point.h"
|
|
|
|
#include "test_util/testharness.h"
|
2019-05-31 00:39:43 +00:00
|
|
|
#include "util/random.h"
|
2023-05-17 18:27:09 +00:00
|
|
|
#include "util/rate_limiter_impl.h"
|
generic rate limiter
Summary:
A generic rate limiter that can be shared by threads and rocksdb
instances. Will use this to smooth out write traffic generated by
compaction and flush. This will help us get better p99 behavior on flash
storage.
Test Plan:
unit test output
==== Test RateLimiterTest.Rate
request size [1 - 1023], limit 10 KB/sec, actual rate: 10.374969 KB/sec, elapsed 2002265
request size [1 - 2047], limit 20 KB/sec, actual rate: 20.771242 KB/sec, elapsed 2002139
request size [1 - 4095], limit 40 KB/sec, actual rate: 41.285299 KB/sec, elapsed 2202424
request size [1 - 8191], limit 80 KB/sec, actual rate: 81.371605 KB/sec, elapsed 2402558
request size [1 - 16383], limit 160 KB/sec, actual rate: 162.541268 KB/sec, elapsed 3303500
Reviewers: yhchiang, igor, sdong
Reviewed By: sdong
Subscribers: leveldb
Differential Revision: https://reviews.facebook.net/D19359
2014-07-08 18:41:57 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
generic rate limiter
Summary:
A generic rate limiter that can be shared by threads and rocksdb
instances. Will use this to smooth out write traffic generated by
compaction and flush. This will help us get better p99 behavior on flash
storage.
Test Plan:
unit test output
==== Test RateLimiterTest.Rate
request size [1 - 1023], limit 10 KB/sec, actual rate: 10.374969 KB/sec, elapsed 2002265
request size [1 - 2047], limit 20 KB/sec, actual rate: 20.771242 KB/sec, elapsed 2002139
request size [1 - 4095], limit 40 KB/sec, actual rate: 41.285299 KB/sec, elapsed 2202424
request size [1 - 8191], limit 80 KB/sec, actual rate: 81.371605 KB/sec, elapsed 2402558
request size [1 - 16383], limit 160 KB/sec, actual rate: 162.541268 KB/sec, elapsed 3303500
Reviewers: yhchiang, igor, sdong
Reviewed By: sdong
Subscribers: leveldb
Differential Revision: https://reviews.facebook.net/D19359
2014-07-08 18:41:57 +00:00
|
|
|
|
2016-10-13 21:26:12 +00:00
|
|
|
// TODO(yhchiang): the rate will not be accurate when we run test in parallel.
|
2021-09-17 15:52:20 +00:00
|
|
|
class RateLimiterTest : public testing::Test {
|
|
|
|
protected:
|
|
|
|
~RateLimiterTest() override {
|
|
|
|
SyncPoint::GetInstance()->DisableProcessing();
|
|
|
|
SyncPoint::GetInstance()->ClearAllCallBacks();
|
|
|
|
}
|
|
|
|
};
|
generic rate limiter
Summary:
A generic rate limiter that can be shared by threads and rocksdb
instances. Will use this to smooth out write traffic generated by
compaction and flush. This will help us get better p99 behavior on flash
storage.
Test Plan:
unit test output
==== Test RateLimiterTest.Rate
request size [1 - 1023], limit 10 KB/sec, actual rate: 10.374969 KB/sec, elapsed 2002265
request size [1 - 2047], limit 20 KB/sec, actual rate: 20.771242 KB/sec, elapsed 2002139
request size [1 - 4095], limit 40 KB/sec, actual rate: 41.285299 KB/sec, elapsed 2202424
request size [1 - 8191], limit 80 KB/sec, actual rate: 81.371605 KB/sec, elapsed 2402558
request size [1 - 16383], limit 160 KB/sec, actual rate: 162.541268 KB/sec, elapsed 3303500
Reviewers: yhchiang, igor, sdong
Reviewed By: sdong
Subscribers: leveldb
Differential Revision: https://reviews.facebook.net/D19359
2014-07-08 18:41:57 +00:00
|
|
|
|
2016-05-27 23:14:24 +00:00
|
|
|
TEST_F(RateLimiterTest, OverflowRate) {
|
2022-05-05 20:08:21 +00:00
|
|
|
GenericRateLimiter limiter(std::numeric_limits<int64_t>::max(), 1000, 10,
|
2021-01-26 06:07:26 +00:00
|
|
|
RateLimiter::Mode::kWritesOnly,
|
|
|
|
SystemClock::Default(), false /* auto_tuned */);
|
2016-05-27 23:14:24 +00:00
|
|
|
ASSERT_GT(limiter.GetSingleBurstBytes(), 1000000000ll);
|
|
|
|
}
|
|
|
|
|
2015-03-17 21:08:00 +00:00
|
|
|
TEST_F(RateLimiterTest, StartStop) {
|
2016-08-17 07:42:35 +00:00
|
|
|
std::unique_ptr<RateLimiter> limiter(NewGenericRateLimiter(100, 100, 10));
|
generic rate limiter
Summary:
A generic rate limiter that can be shared by threads and rocksdb
instances. Will use this to smooth out write traffic generated by
compaction and flush. This will help us get better p99 behavior on flash
storage.
Test Plan:
unit test output
==== Test RateLimiterTest.Rate
request size [1 - 1023], limit 10 KB/sec, actual rate: 10.374969 KB/sec, elapsed 2002265
request size [1 - 2047], limit 20 KB/sec, actual rate: 20.771242 KB/sec, elapsed 2002139
request size [1 - 4095], limit 40 KB/sec, actual rate: 41.285299 KB/sec, elapsed 2202424
request size [1 - 8191], limit 80 KB/sec, actual rate: 81.371605 KB/sec, elapsed 2402558
request size [1 - 16383], limit 160 KB/sec, actual rate: 162.541268 KB/sec, elapsed 3303500
Reviewers: yhchiang, igor, sdong
Reviewed By: sdong
Subscribers: leveldb
Differential Revision: https://reviews.facebook.net/D19359
2014-07-08 18:41:57 +00:00
|
|
|
}
|
|
|
|
|
2021-08-31 17:59:14 +00:00
|
|
|
TEST_F(RateLimiterTest, GetTotalBytesThrough) {
|
|
|
|
std::unique_ptr<RateLimiter> limiter(NewGenericRateLimiter(
|
2021-09-17 15:52:20 +00:00
|
|
|
200 /* rate_bytes_per_sec */, 1000 * 1000 /* refill_period_us */,
|
2021-08-31 17:59:14 +00:00
|
|
|
10 /* fairness */));
|
|
|
|
for (int i = Env::IO_LOW; i <= Env::IO_TOTAL; ++i) {
|
|
|
|
ASSERT_EQ(limiter->GetTotalBytesThrough(static_cast<Env::IOPriority>(i)),
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
|
2021-09-17 15:52:20 +00:00
|
|
|
std::int64_t request_byte = 200;
|
2021-08-31 17:59:14 +00:00
|
|
|
std::int64_t request_byte_sum = 0;
|
|
|
|
for (int i = Env::IO_LOW; i < Env::IO_TOTAL; ++i) {
|
|
|
|
limiter->Request(request_byte, static_cast<Env::IOPriority>(i),
|
|
|
|
nullptr /* stats */, RateLimiter::OpType::kWrite);
|
|
|
|
request_byte_sum += request_byte;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = Env::IO_LOW; i < Env::IO_TOTAL; ++i) {
|
|
|
|
EXPECT_EQ(limiter->GetTotalBytesThrough(static_cast<Env::IOPriority>(i)),
|
|
|
|
request_byte)
|
|
|
|
<< "Failed to track total_bytes_through_ correctly when IOPriority = "
|
|
|
|
<< static_cast<Env::IOPriority>(i);
|
|
|
|
}
|
|
|
|
EXPECT_EQ(limiter->GetTotalBytesThrough(Env::IO_TOTAL), request_byte_sum)
|
|
|
|
<< "Failed to track total_bytes_through_ correctly when IOPriority = "
|
|
|
|
"Env::IO_TOTAL";
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(RateLimiterTest, GetTotalRequests) {
|
|
|
|
std::unique_ptr<RateLimiter> limiter(NewGenericRateLimiter(
|
2021-09-17 15:52:20 +00:00
|
|
|
200 /* rate_bytes_per_sec */, 1000 * 1000 /* refill_period_us */,
|
2021-08-31 17:59:14 +00:00
|
|
|
10 /* fairness */));
|
|
|
|
for (int i = Env::IO_LOW; i <= Env::IO_TOTAL; ++i) {
|
|
|
|
ASSERT_EQ(limiter->GetTotalRequests(static_cast<Env::IOPriority>(i)), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::int64_t total_requests_sum = 0;
|
|
|
|
for (int i = Env::IO_LOW; i < Env::IO_TOTAL; ++i) {
|
2021-09-17 15:52:20 +00:00
|
|
|
limiter->Request(200, static_cast<Env::IOPriority>(i), nullptr /* stats */,
|
2021-08-31 17:59:14 +00:00
|
|
|
RateLimiter::OpType::kWrite);
|
|
|
|
total_requests_sum += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = Env::IO_LOW; i < Env::IO_TOTAL; ++i) {
|
|
|
|
EXPECT_EQ(limiter->GetTotalRequests(static_cast<Env::IOPriority>(i)), 1)
|
|
|
|
<< "Failed to track total_requests_ correctly when IOPriority = "
|
|
|
|
<< static_cast<Env::IOPriority>(i);
|
|
|
|
}
|
|
|
|
EXPECT_EQ(limiter->GetTotalRequests(Env::IO_TOTAL), total_requests_sum)
|
|
|
|
<< "Failed to track total_requests_ correctly when IOPriority = "
|
|
|
|
"Env::IO_TOTAL";
|
|
|
|
}
|
|
|
|
|
2021-09-10 15:35:59 +00:00
|
|
|
TEST_F(RateLimiterTest, GetTotalPendingRequests) {
|
2021-09-17 15:52:20 +00:00
|
|
|
std::unique_ptr<RateLimiter> limiter(NewGenericRateLimiter(
|
|
|
|
200 /* rate_bytes_per_sec */, 1000 * 1000 /* refill_period_us */,
|
|
|
|
10 /* fairness */));
|
2021-09-23 02:35:05 +00:00
|
|
|
int64_t total_pending_requests = 0;
|
2021-09-10 15:35:59 +00:00
|
|
|
for (int i = Env::IO_LOW; i <= Env::IO_TOTAL; ++i) {
|
2021-09-23 02:35:05 +00:00
|
|
|
ASSERT_OK(limiter->GetTotalPendingRequests(
|
|
|
|
&total_pending_requests, static_cast<Env::IOPriority>(i)));
|
|
|
|
ASSERT_EQ(total_pending_requests, 0);
|
2021-09-10 15:35:59 +00:00
|
|
|
}
|
|
|
|
// This is a variable for making sure the following callback is called
|
|
|
|
// and the assertions in it are indeed excuted
|
2021-09-17 15:52:20 +00:00
|
|
|
bool nonzero_pending_requests_verified = false;
|
2021-09-10 15:35:59 +00:00
|
|
|
SyncPoint::GetInstance()->SetCallBack(
|
|
|
|
"GenericRateLimiter::Request:PostEnqueueRequest", [&](void* arg) {
|
|
|
|
port::Mutex* request_mutex = (port::Mutex*)arg;
|
|
|
|
// We temporarily unlock the mutex so that the following
|
|
|
|
// GetTotalPendingRequests() can acquire it
|
|
|
|
request_mutex->Unlock();
|
2021-09-23 02:35:05 +00:00
|
|
|
for (int i = Env::IO_LOW; i <= Env::IO_TOTAL; ++i) {
|
|
|
|
EXPECT_OK(limiter->GetTotalPendingRequests(
|
|
|
|
&total_pending_requests, static_cast<Env::IOPriority>(i)))
|
|
|
|
<< "Failed to return total pending requests for priority level = "
|
|
|
|
<< static_cast<Env::IOPriority>(i);
|
|
|
|
if (i == Env::IO_USER || i == Env::IO_TOTAL) {
|
|
|
|
EXPECT_EQ(total_pending_requests, 1)
|
|
|
|
<< "Failed to correctly return total pending requests for "
|
|
|
|
"priority level = "
|
|
|
|
<< static_cast<Env::IOPriority>(i);
|
|
|
|
} else {
|
|
|
|
EXPECT_EQ(total_pending_requests, 0)
|
|
|
|
<< "Failed to correctly return total pending requests for "
|
|
|
|
"priority level = "
|
|
|
|
<< static_cast<Env::IOPriority>(i);
|
|
|
|
}
|
|
|
|
}
|
2021-09-10 15:35:59 +00:00
|
|
|
// We lock the mutex again so that the request thread can resume running
|
|
|
|
// with the mutex locked
|
|
|
|
request_mutex->Lock();
|
2021-09-17 15:52:20 +00:00
|
|
|
nonzero_pending_requests_verified = true;
|
2021-09-10 15:35:59 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
SyncPoint::GetInstance()->EnableProcessing();
|
2021-09-17 15:52:20 +00:00
|
|
|
limiter->Request(200, Env::IO_USER, nullptr /* stats */,
|
2021-09-10 15:35:59 +00:00
|
|
|
RateLimiter::OpType::kWrite);
|
2021-09-17 15:52:20 +00:00
|
|
|
ASSERT_EQ(nonzero_pending_requests_verified, true);
|
2021-09-23 02:35:05 +00:00
|
|
|
for (int i = Env::IO_LOW; i <= Env::IO_TOTAL; ++i) {
|
|
|
|
EXPECT_OK(limiter->GetTotalPendingRequests(&total_pending_requests,
|
|
|
|
static_cast<Env::IOPriority>(i)))
|
|
|
|
<< "Failed to return total pending requests for priority level = "
|
|
|
|
<< static_cast<Env::IOPriority>(i);
|
|
|
|
EXPECT_EQ(total_pending_requests, 0)
|
|
|
|
<< "Failed to correctly return total pending requests for priority "
|
|
|
|
"level = "
|
|
|
|
<< static_cast<Env::IOPriority>(i);
|
|
|
|
}
|
2021-09-10 15:35:59 +00:00
|
|
|
SyncPoint::GetInstance()->DisableProcessing();
|
|
|
|
SyncPoint::GetInstance()->ClearCallBack(
|
|
|
|
"GenericRateLimiter::Request:PostEnqueueRequest");
|
|
|
|
}
|
|
|
|
|
2017-06-13 21:51:22 +00:00
|
|
|
TEST_F(RateLimiterTest, Modes) {
|
|
|
|
for (auto mode : {RateLimiter::Mode::kWritesOnly,
|
|
|
|
RateLimiter::Mode::kReadsOnly, RateLimiter::Mode::kAllIo}) {
|
2021-01-26 06:07:26 +00:00
|
|
|
GenericRateLimiter limiter(2000 /* rate_bytes_per_sec */,
|
|
|
|
1000 * 1000 /* refill_period_us */,
|
|
|
|
10 /* fairness */, mode, SystemClock::Default(),
|
|
|
|
false /* auto_tuned */);
|
2017-06-13 21:51:22 +00:00
|
|
|
limiter.Request(1000 /* bytes */, Env::IO_HIGH, nullptr /* stats */,
|
|
|
|
RateLimiter::OpType::kRead);
|
|
|
|
if (mode == RateLimiter::Mode::kWritesOnly) {
|
|
|
|
ASSERT_EQ(0, limiter.GetTotalBytesThrough(Env::IO_HIGH));
|
|
|
|
} else {
|
|
|
|
ASSERT_EQ(1000, limiter.GetTotalBytesThrough(Env::IO_HIGH));
|
|
|
|
}
|
|
|
|
|
|
|
|
limiter.Request(1000 /* bytes */, Env::IO_HIGH, nullptr /* stats */,
|
|
|
|
RateLimiter::OpType::kWrite);
|
|
|
|
if (mode == RateLimiter::Mode::kAllIo) {
|
|
|
|
ASSERT_EQ(2000, limiter.GetTotalBytesThrough(Env::IO_HIGH));
|
|
|
|
} else {
|
|
|
|
ASSERT_EQ(1000, limiter.GetTotalBytesThrough(Env::IO_HIGH));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-31 17:59:14 +00:00
|
|
|
TEST_F(RateLimiterTest, GeneratePriorityIterationOrder) {
|
|
|
|
std::unique_ptr<RateLimiter> limiter(NewGenericRateLimiter(
|
2021-09-17 15:52:20 +00:00
|
|
|
200 /* rate_bytes_per_sec */, 1000 * 1000 /* refill_period_us */,
|
2021-08-31 17:59:14 +00:00
|
|
|
10 /* fairness */));
|
|
|
|
|
|
|
|
bool possible_random_one_in_fairness_results_for_high_mid_pri[4][2] = {
|
|
|
|
{false, false}, {false, true}, {true, false}, {true, true}};
|
|
|
|
std::vector<Env::IOPriority> possible_priority_iteration_orders[4] = {
|
|
|
|
{Env::IO_USER, Env::IO_HIGH, Env::IO_MID, Env::IO_LOW},
|
|
|
|
{Env::IO_USER, Env::IO_HIGH, Env::IO_LOW, Env::IO_MID},
|
|
|
|
{Env::IO_USER, Env::IO_MID, Env::IO_LOW, Env::IO_HIGH},
|
|
|
|
{Env::IO_USER, Env::IO_LOW, Env::IO_MID, Env::IO_HIGH}};
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
2021-09-17 15:52:20 +00:00
|
|
|
// These are variables for making sure the following callbacks are called
|
|
|
|
// and the assertion in the last callback is indeed excuted
|
|
|
|
bool high_pri_iterated_after_mid_low_pri_set = false;
|
|
|
|
bool mid_pri_itereated_after_low_pri_set = false;
|
|
|
|
bool pri_iteration_order_verified = false;
|
2021-08-31 17:59:14 +00:00
|
|
|
SyncPoint::GetInstance()->SetCallBack(
|
2022-07-19 16:31:14 +00:00
|
|
|
"GenericRateLimiter::GeneratePriorityIterationOrderLocked::"
|
2021-08-31 17:59:14 +00:00
|
|
|
"PostRandomOneInFairnessForHighPri",
|
|
|
|
[&](void* arg) {
|
|
|
|
bool* high_pri_iterated_after_mid_low_pri = (bool*)arg;
|
|
|
|
*high_pri_iterated_after_mid_low_pri =
|
|
|
|
possible_random_one_in_fairness_results_for_high_mid_pri[i][0];
|
2021-09-17 15:52:20 +00:00
|
|
|
high_pri_iterated_after_mid_low_pri_set = true;
|
2021-08-31 17:59:14 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
SyncPoint::GetInstance()->SetCallBack(
|
2022-07-19 16:31:14 +00:00
|
|
|
"GenericRateLimiter::GeneratePriorityIterationOrderLocked::"
|
2021-08-31 17:59:14 +00:00
|
|
|
"PostRandomOneInFairnessForMidPri",
|
|
|
|
[&](void* arg) {
|
|
|
|
bool* mid_pri_itereated_after_low_pri = (bool*)arg;
|
|
|
|
*mid_pri_itereated_after_low_pri =
|
|
|
|
possible_random_one_in_fairness_results_for_high_mid_pri[i][1];
|
2021-09-17 15:52:20 +00:00
|
|
|
mid_pri_itereated_after_low_pri_set = true;
|
2021-08-31 17:59:14 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
SyncPoint::GetInstance()->SetCallBack(
|
2022-07-19 16:31:14 +00:00
|
|
|
"GenericRateLimiter::GeneratePriorityIterationOrderLocked::"
|
2021-08-31 17:59:14 +00:00
|
|
|
"PreReturnPriIterationOrder",
|
|
|
|
[&](void* arg) {
|
|
|
|
std::vector<Env::IOPriority>* pri_iteration_order =
|
|
|
|
(std::vector<Env::IOPriority>*)arg;
|
|
|
|
EXPECT_EQ(*pri_iteration_order, possible_priority_iteration_orders[i])
|
|
|
|
<< "Failed to generate priority iteration order correctly when "
|
|
|
|
"high_pri_iterated_after_mid_low_pri = "
|
|
|
|
<< possible_random_one_in_fairness_results_for_high_mid_pri[i][0]
|
|
|
|
<< ", mid_pri_itereated_after_low_pri = "
|
|
|
|
<< possible_random_one_in_fairness_results_for_high_mid_pri[i][1]
|
|
|
|
<< std::endl;
|
2021-09-17 15:52:20 +00:00
|
|
|
pri_iteration_order_verified = true;
|
2021-08-31 17:59:14 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
SyncPoint::GetInstance()->EnableProcessing();
|
2021-09-17 15:52:20 +00:00
|
|
|
limiter->Request(200 /* request max bytes to drain so that refill and order
|
2021-08-31 17:59:14 +00:00
|
|
|
generation will be triggered every time
|
|
|
|
GenericRateLimiter::Request() is called */
|
|
|
|
,
|
|
|
|
Env::IO_USER, nullptr /* stats */,
|
|
|
|
RateLimiter::OpType::kWrite);
|
2021-09-17 15:52:20 +00:00
|
|
|
ASSERT_EQ(high_pri_iterated_after_mid_low_pri_set, true);
|
|
|
|
ASSERT_EQ(mid_pri_itereated_after_low_pri_set, true);
|
|
|
|
ASSERT_EQ(pri_iteration_order_verified, true);
|
|
|
|
SyncPoint::GetInstance()->DisableProcessing();
|
|
|
|
SyncPoint::GetInstance()->ClearCallBack(
|
2022-07-19 16:31:14 +00:00
|
|
|
"GenericRateLimiter::GeneratePriorityIterationOrderLocked::"
|
2021-09-17 15:52:20 +00:00
|
|
|
"PreReturnPriIterationOrder");
|
|
|
|
SyncPoint::GetInstance()->ClearCallBack(
|
2022-07-19 16:31:14 +00:00
|
|
|
"GenericRateLimiter::GeneratePriorityIterationOrderLocked::"
|
2021-09-17 15:52:20 +00:00
|
|
|
"PostRandomOneInFairnessForMidPri");
|
|
|
|
SyncPoint::GetInstance()->ClearCallBack(
|
2022-07-19 16:31:14 +00:00
|
|
|
"GenericRateLimiter::GeneratePriorityIterationOrderLocked::"
|
2021-09-17 15:52:20 +00:00
|
|
|
"PostRandomOneInFairnessForHighPri");
|
2021-08-31 17:59:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-17 21:08:00 +00:00
|
|
|
TEST_F(RateLimiterTest, Rate) {
|
generic rate limiter
Summary:
A generic rate limiter that can be shared by threads and rocksdb
instances. Will use this to smooth out write traffic generated by
compaction and flush. This will help us get better p99 behavior on flash
storage.
Test Plan:
unit test output
==== Test RateLimiterTest.Rate
request size [1 - 1023], limit 10 KB/sec, actual rate: 10.374969 KB/sec, elapsed 2002265
request size [1 - 2047], limit 20 KB/sec, actual rate: 20.771242 KB/sec, elapsed 2002139
request size [1 - 4095], limit 40 KB/sec, actual rate: 41.285299 KB/sec, elapsed 2202424
request size [1 - 8191], limit 80 KB/sec, actual rate: 81.371605 KB/sec, elapsed 2402558
request size [1 - 16383], limit 160 KB/sec, actual rate: 162.541268 KB/sec, elapsed 3303500
Reviewers: yhchiang, igor, sdong
Reviewed By: sdong
Subscribers: leveldb
Differential Revision: https://reviews.facebook.net/D19359
2014-07-08 18:41:57 +00:00
|
|
|
auto* env = Env::Default();
|
|
|
|
struct Arg {
|
2014-11-11 21:47:22 +00:00
|
|
|
Arg(int32_t _target_rate, int _burst)
|
2021-08-04 17:42:49 +00:00
|
|
|
: limiter(NewGenericRateLimiter(_target_rate /* rate_bytes_per_sec */,
|
|
|
|
100 * 1000 /* refill_period_us */,
|
|
|
|
10 /* fairness */)),
|
|
|
|
request_size(_target_rate /
|
|
|
|
10 /* refill period here is 1/10 second */),
|
2014-10-31 18:59:54 +00:00
|
|
|
burst(_burst) {}
|
generic rate limiter
Summary:
A generic rate limiter that can be shared by threads and rocksdb
instances. Will use this to smooth out write traffic generated by
compaction and flush. This will help us get better p99 behavior on flash
storage.
Test Plan:
unit test output
==== Test RateLimiterTest.Rate
request size [1 - 1023], limit 10 KB/sec, actual rate: 10.374969 KB/sec, elapsed 2002265
request size [1 - 2047], limit 20 KB/sec, actual rate: 20.771242 KB/sec, elapsed 2002139
request size [1 - 4095], limit 40 KB/sec, actual rate: 41.285299 KB/sec, elapsed 2202424
request size [1 - 8191], limit 80 KB/sec, actual rate: 81.371605 KB/sec, elapsed 2402558
request size [1 - 16383], limit 160 KB/sec, actual rate: 162.541268 KB/sec, elapsed 3303500
Reviewers: yhchiang, igor, sdong
Reviewed By: sdong
Subscribers: leveldb
Differential Revision: https://reviews.facebook.net/D19359
2014-07-08 18:41:57 +00:00
|
|
|
std::unique_ptr<RateLimiter> limiter;
|
2014-11-11 21:47:22 +00:00
|
|
|
int32_t request_size;
|
generic rate limiter
Summary:
A generic rate limiter that can be shared by threads and rocksdb
instances. Will use this to smooth out write traffic generated by
compaction and flush. This will help us get better p99 behavior on flash
storage.
Test Plan:
unit test output
==== Test RateLimiterTest.Rate
request size [1 - 1023], limit 10 KB/sec, actual rate: 10.374969 KB/sec, elapsed 2002265
request size [1 - 2047], limit 20 KB/sec, actual rate: 20.771242 KB/sec, elapsed 2002139
request size [1 - 4095], limit 40 KB/sec, actual rate: 41.285299 KB/sec, elapsed 2202424
request size [1 - 8191], limit 80 KB/sec, actual rate: 81.371605 KB/sec, elapsed 2402558
request size [1 - 16383], limit 160 KB/sec, actual rate: 162.541268 KB/sec, elapsed 3303500
Reviewers: yhchiang, igor, sdong
Reviewed By: sdong
Subscribers: leveldb
Differential Revision: https://reviews.facebook.net/D19359
2014-07-08 18:41:57 +00:00
|
|
|
int burst;
|
|
|
|
};
|
|
|
|
|
|
|
|
auto writer = [](void* p) {
|
2021-01-26 06:07:26 +00:00
|
|
|
const auto& thread_clock = SystemClock::Default();
|
generic rate limiter
Summary:
A generic rate limiter that can be shared by threads and rocksdb
instances. Will use this to smooth out write traffic generated by
compaction and flush. This will help us get better p99 behavior on flash
storage.
Test Plan:
unit test output
==== Test RateLimiterTest.Rate
request size [1 - 1023], limit 10 KB/sec, actual rate: 10.374969 KB/sec, elapsed 2002265
request size [1 - 2047], limit 20 KB/sec, actual rate: 20.771242 KB/sec, elapsed 2002139
request size [1 - 4095], limit 40 KB/sec, actual rate: 41.285299 KB/sec, elapsed 2202424
request size [1 - 8191], limit 80 KB/sec, actual rate: 81.371605 KB/sec, elapsed 2402558
request size [1 - 16383], limit 160 KB/sec, actual rate: 162.541268 KB/sec, elapsed 3303500
Reviewers: yhchiang, igor, sdong
Reviewed By: sdong
Subscribers: leveldb
Differential Revision: https://reviews.facebook.net/D19359
2014-07-08 18:41:57 +00:00
|
|
|
auto* arg = static_cast<Arg*>(p);
|
|
|
|
// Test for 2 seconds
|
2021-01-26 06:07:26 +00:00
|
|
|
auto until = thread_clock->NowMicros() + 2 * 1000000;
|
|
|
|
Random r((uint32_t)(thread_clock->NowNanos() %
|
2014-10-31 18:59:54 +00:00
|
|
|
std::numeric_limits<uint32_t>::max()));
|
2021-01-26 06:07:26 +00:00
|
|
|
while (thread_clock->NowMicros() < until) {
|
2021-08-31 17:59:14 +00:00
|
|
|
for (int i = 0; i < static_cast<int>(r.Skewed(arg->burst * 2) + 1); ++i) {
|
|
|
|
arg->limiter->Request(r.Uniform(arg->request_size - 1) + 1,
|
|
|
|
Env::IO_USER, nullptr /* stats */,
|
|
|
|
RateLimiter::OpType::kWrite);
|
|
|
|
}
|
|
|
|
|
generic rate limiter
Summary:
A generic rate limiter that can be shared by threads and rocksdb
instances. Will use this to smooth out write traffic generated by
compaction and flush. This will help us get better p99 behavior on flash
storage.
Test Plan:
unit test output
==== Test RateLimiterTest.Rate
request size [1 - 1023], limit 10 KB/sec, actual rate: 10.374969 KB/sec, elapsed 2002265
request size [1 - 2047], limit 20 KB/sec, actual rate: 20.771242 KB/sec, elapsed 2002139
request size [1 - 4095], limit 40 KB/sec, actual rate: 41.285299 KB/sec, elapsed 2202424
request size [1 - 8191], limit 80 KB/sec, actual rate: 81.371605 KB/sec, elapsed 2402558
request size [1 - 16383], limit 160 KB/sec, actual rate: 162.541268 KB/sec, elapsed 3303500
Reviewers: yhchiang, igor, sdong
Reviewed By: sdong
Subscribers: leveldb
Differential Revision: https://reviews.facebook.net/D19359
2014-07-08 18:41:57 +00:00
|
|
|
for (int i = 0; i < static_cast<int>(r.Skewed(arg->burst) + 1); ++i) {
|
|
|
|
arg->limiter->Request(r.Uniform(arg->request_size - 1) + 1,
|
2017-06-13 21:51:22 +00:00
|
|
|
Env::IO_HIGH, nullptr /* stats */,
|
|
|
|
RateLimiter::OpType::kWrite);
|
generic rate limiter
Summary:
A generic rate limiter that can be shared by threads and rocksdb
instances. Will use this to smooth out write traffic generated by
compaction and flush. This will help us get better p99 behavior on flash
storage.
Test Plan:
unit test output
==== Test RateLimiterTest.Rate
request size [1 - 1023], limit 10 KB/sec, actual rate: 10.374969 KB/sec, elapsed 2002265
request size [1 - 2047], limit 20 KB/sec, actual rate: 20.771242 KB/sec, elapsed 2002139
request size [1 - 4095], limit 40 KB/sec, actual rate: 41.285299 KB/sec, elapsed 2202424
request size [1 - 8191], limit 80 KB/sec, actual rate: 81.371605 KB/sec, elapsed 2402558
request size [1 - 16383], limit 160 KB/sec, actual rate: 162.541268 KB/sec, elapsed 3303500
Reviewers: yhchiang, igor, sdong
Reviewed By: sdong
Subscribers: leveldb
Differential Revision: https://reviews.facebook.net/D19359
2014-07-08 18:41:57 +00:00
|
|
|
}
|
2021-08-31 17:59:14 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < static_cast<int>(r.Skewed(arg->burst / 2 + 1) + 1);
|
|
|
|
++i) {
|
|
|
|
arg->limiter->Request(r.Uniform(arg->request_size - 1) + 1, Env::IO_MID,
|
|
|
|
nullptr /* stats */, RateLimiter::OpType::kWrite);
|
|
|
|
}
|
|
|
|
|
2017-03-03 01:40:24 +00:00
|
|
|
arg->limiter->Request(r.Uniform(arg->request_size - 1) + 1, Env::IO_LOW,
|
2017-06-13 21:51:22 +00:00
|
|
|
nullptr /* stats */, RateLimiter::OpType::kWrite);
|
generic rate limiter
Summary:
A generic rate limiter that can be shared by threads and rocksdb
instances. Will use this to smooth out write traffic generated by
compaction and flush. This will help us get better p99 behavior on flash
storage.
Test Plan:
unit test output
==== Test RateLimiterTest.Rate
request size [1 - 1023], limit 10 KB/sec, actual rate: 10.374969 KB/sec, elapsed 2002265
request size [1 - 2047], limit 20 KB/sec, actual rate: 20.771242 KB/sec, elapsed 2002139
request size [1 - 4095], limit 40 KB/sec, actual rate: 41.285299 KB/sec, elapsed 2202424
request size [1 - 8191], limit 80 KB/sec, actual rate: 81.371605 KB/sec, elapsed 2402558
request size [1 - 16383], limit 160 KB/sec, actual rate: 162.541268 KB/sec, elapsed 3303500
Reviewers: yhchiang, igor, sdong
Reviewed By: sdong
Subscribers: leveldb
Differential Revision: https://reviews.facebook.net/D19359
2014-07-08 18:41:57 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-12-02 23:15:17 +00:00
|
|
|
int samples = 0;
|
|
|
|
int samples_at_minimum = 0;
|
|
|
|
|
2015-03-18 22:35:55 +00:00
|
|
|
for (int i = 1; i <= 16; i *= 2) {
|
2014-11-11 21:47:22 +00:00
|
|
|
int32_t target = i * 1024 * 10;
|
generic rate limiter
Summary:
A generic rate limiter that can be shared by threads and rocksdb
instances. Will use this to smooth out write traffic generated by
compaction and flush. This will help us get better p99 behavior on flash
storage.
Test Plan:
unit test output
==== Test RateLimiterTest.Rate
request size [1 - 1023], limit 10 KB/sec, actual rate: 10.374969 KB/sec, elapsed 2002265
request size [1 - 2047], limit 20 KB/sec, actual rate: 20.771242 KB/sec, elapsed 2002139
request size [1 - 4095], limit 40 KB/sec, actual rate: 41.285299 KB/sec, elapsed 2202424
request size [1 - 8191], limit 80 KB/sec, actual rate: 81.371605 KB/sec, elapsed 2402558
request size [1 - 16383], limit 160 KB/sec, actual rate: 162.541268 KB/sec, elapsed 3303500
Reviewers: yhchiang, igor, sdong
Reviewed By: sdong
Subscribers: leveldb
Differential Revision: https://reviews.facebook.net/D19359
2014-07-08 18:41:57 +00:00
|
|
|
Arg arg(target, i / 4 + 1);
|
2015-03-18 22:35:55 +00:00
|
|
|
int64_t old_total_bytes_through = 0;
|
|
|
|
for (int iter = 1; iter <= 2; ++iter) {
|
|
|
|
// second iteration changes the target dynamically
|
|
|
|
if (iter == 2) {
|
|
|
|
target *= 2;
|
|
|
|
arg.limiter->SetBytesPerSecond(target);
|
|
|
|
}
|
|
|
|
auto start = env->NowMicros();
|
|
|
|
for (int t = 0; t < i; ++t) {
|
|
|
|
env->StartThread(writer, &arg);
|
|
|
|
}
|
|
|
|
env->WaitForJoin();
|
generic rate limiter
Summary:
A generic rate limiter that can be shared by threads and rocksdb
instances. Will use this to smooth out write traffic generated by
compaction and flush. This will help us get better p99 behavior on flash
storage.
Test Plan:
unit test output
==== Test RateLimiterTest.Rate
request size [1 - 1023], limit 10 KB/sec, actual rate: 10.374969 KB/sec, elapsed 2002265
request size [1 - 2047], limit 20 KB/sec, actual rate: 20.771242 KB/sec, elapsed 2002139
request size [1 - 4095], limit 40 KB/sec, actual rate: 41.285299 KB/sec, elapsed 2202424
request size [1 - 8191], limit 80 KB/sec, actual rate: 81.371605 KB/sec, elapsed 2402558
request size [1 - 16383], limit 160 KB/sec, actual rate: 162.541268 KB/sec, elapsed 3303500
Reviewers: yhchiang, igor, sdong
Reviewed By: sdong
Subscribers: leveldb
Differential Revision: https://reviews.facebook.net/D19359
2014-07-08 18:41:57 +00:00
|
|
|
|
2015-03-18 22:35:55 +00:00
|
|
|
auto elapsed = env->NowMicros() - start;
|
|
|
|
double rate =
|
|
|
|
(arg.limiter->GetTotalBytesThrough() - old_total_bytes_through) *
|
|
|
|
1000000.0 / elapsed;
|
|
|
|
old_total_bytes_through = arg.limiter->GetTotalBytesThrough();
|
|
|
|
fprintf(stderr,
|
|
|
|
"request size [1 - %" PRIi32 "], limit %" PRIi32
|
|
|
|
" KB/sec, actual rate: %lf KB/sec, elapsed %.2lf seconds\n",
|
|
|
|
arg.request_size - 1, target / 1024, rate / 1024,
|
|
|
|
elapsed / 1000000.0);
|
generic rate limiter
Summary:
A generic rate limiter that can be shared by threads and rocksdb
instances. Will use this to smooth out write traffic generated by
compaction and flush. This will help us get better p99 behavior on flash
storage.
Test Plan:
unit test output
==== Test RateLimiterTest.Rate
request size [1 - 1023], limit 10 KB/sec, actual rate: 10.374969 KB/sec, elapsed 2002265
request size [1 - 2047], limit 20 KB/sec, actual rate: 20.771242 KB/sec, elapsed 2002139
request size [1 - 4095], limit 40 KB/sec, actual rate: 41.285299 KB/sec, elapsed 2202424
request size [1 - 8191], limit 80 KB/sec, actual rate: 81.371605 KB/sec, elapsed 2402558
request size [1 - 16383], limit 160 KB/sec, actual rate: 162.541268 KB/sec, elapsed 3303500
Reviewers: yhchiang, igor, sdong
Reviewed By: sdong
Subscribers: leveldb
Differential Revision: https://reviews.facebook.net/D19359
2014-07-08 18:41:57 +00:00
|
|
|
|
2020-12-02 23:15:17 +00:00
|
|
|
++samples;
|
|
|
|
if (rate / target >= 0.80) {
|
|
|
|
++samples_at_minimum;
|
|
|
|
}
|
2016-10-13 21:26:12 +00:00
|
|
|
ASSERT_LE(rate / target, 1.25);
|
2015-03-18 22:35:55 +00:00
|
|
|
}
|
generic rate limiter
Summary:
A generic rate limiter that can be shared by threads and rocksdb
instances. Will use this to smooth out write traffic generated by
compaction and flush. This will help us get better p99 behavior on flash
storage.
Test Plan:
unit test output
==== Test RateLimiterTest.Rate
request size [1 - 1023], limit 10 KB/sec, actual rate: 10.374969 KB/sec, elapsed 2002265
request size [1 - 2047], limit 20 KB/sec, actual rate: 20.771242 KB/sec, elapsed 2002139
request size [1 - 4095], limit 40 KB/sec, actual rate: 41.285299 KB/sec, elapsed 2202424
request size [1 - 8191], limit 80 KB/sec, actual rate: 81.371605 KB/sec, elapsed 2402558
request size [1 - 16383], limit 160 KB/sec, actual rate: 162.541268 KB/sec, elapsed 3303500
Reviewers: yhchiang, igor, sdong
Reviewed By: sdong
Subscribers: leveldb
Differential Revision: https://reviews.facebook.net/D19359
2014-07-08 18:41:57 +00:00
|
|
|
}
|
2020-12-02 23:15:17 +00:00
|
|
|
|
2022-09-05 05:15:14 +00:00
|
|
|
// This can fail due to slow execution speed, like when using valgrind or in
|
|
|
|
// heavily loaded CI environments
|
2020-12-02 23:15:17 +00:00
|
|
|
bool skip_minimum_rate_check =
|
2022-09-05 05:15:14 +00:00
|
|
|
#if (defined(CIRCLECI) && defined(OS_MACOSX)) || defined(ROCKSDB_VALGRIND_RUN)
|
2020-12-02 23:15:17 +00:00
|
|
|
true;
|
|
|
|
#else
|
|
|
|
getenv("SANDCASTLE");
|
2017-06-14 21:51:37 +00:00
|
|
|
#endif
|
2020-12-02 23:15:17 +00:00
|
|
|
if (skip_minimum_rate_check) {
|
|
|
|
fprintf(stderr, "Skipped minimum rate check (%d / %d passed)\n",
|
|
|
|
samples_at_minimum, samples);
|
|
|
|
} else {
|
|
|
|
ASSERT_EQ(samples_at_minimum, samples);
|
|
|
|
}
|
|
|
|
}
|
generic rate limiter
Summary:
A generic rate limiter that can be shared by threads and rocksdb
instances. Will use this to smooth out write traffic generated by
compaction and flush. This will help us get better p99 behavior on flash
storage.
Test Plan:
unit test output
==== Test RateLimiterTest.Rate
request size [1 - 1023], limit 10 KB/sec, actual rate: 10.374969 KB/sec, elapsed 2002265
request size [1 - 2047], limit 20 KB/sec, actual rate: 20.771242 KB/sec, elapsed 2002139
request size [1 - 4095], limit 40 KB/sec, actual rate: 41.285299 KB/sec, elapsed 2202424
request size [1 - 8191], limit 80 KB/sec, actual rate: 81.371605 KB/sec, elapsed 2402558
request size [1 - 16383], limit 160 KB/sec, actual rate: 162.541268 KB/sec, elapsed 3303500
Reviewers: yhchiang, igor, sdong
Reviewed By: sdong
Subscribers: leveldb
Differential Revision: https://reviews.facebook.net/D19359
2014-07-08 18:41:57 +00:00
|
|
|
|
fix rate limiter to avoid starvation
Summary:
The current implementation of rate limiter has the possibility to introduce resource starvation when change its limit.
This diff aims to fix this problem by consuming request bytes partially.
Test Plan:
```
./rate_limiter_test
[==========] Running 4 tests from 1 test case.
[----------] Global test environment set-up.
[----------] 4 tests from RateLimiterTest
[ RUN ] RateLimiterTest.OverflowRate
[ OK ] RateLimiterTest.OverflowRate (0 ms)
[ RUN ] RateLimiterTest.StartStop
[ OK ] RateLimiterTest.StartStop (0 ms)
[ RUN ] RateLimiterTest.Rate
request size [1 - 1023], limit 10 KB/sec, actual rate: 10.355712 KB/sec, elapsed 2.00 seconds
request size [1 - 1023], limit 20 KB/sec, actual rate: 19.136564 KB/sec, elapsed 2.00 seconds
request size [1 - 2047], limit 20 KB/sec, actual rate: 20.783976 KB/sec, elapsed 2.10 seconds
request size [1 - 2047], limit 40 KB/sec, actual rate: 39.308144 KB/sec, elapsed 2.10 seconds
request size [1 - 4095], limit 40 KB/sec, actual rate: 40.318349 KB/sec, elapsed 2.20 seconds
request size [1 - 4095], limit 80 KB/sec, actual rate: 79.667396 KB/sec, elapsed 2.20 seconds
request size [1 - 8191], limit 80 KB/sec, actual rate: 81.807158 KB/sec, elapsed 2.30 seconds
request size [1 - 8191], limit 160 KB/sec, actual rate: 160.659761 KB/sec, elapsed 2.20 seconds
request size [1 - 16383], limit 160 KB/sec, actual rate: 160.700990 KB/sec, elapsed 3.00 seconds
request size [1 - 16383], limit 320 KB/sec, actual rate: 317.639481 KB/sec, elapsed 2.50 seconds
[ OK ] RateLimiterTest.Rate (22618 ms)
[ RUN ] RateLimiterTest.LimitChangeTest
[COMPLETE] request size 10 KB, new limit 20KB/sec, refill period 1000 ms
[COMPLETE] request size 10 KB, new limit 5KB/sec, refill period 1000 ms
[COMPLETE] request size 20 KB, new limit 40KB/sec, refill period 1000 ms
[COMPLETE] request size 20 KB, new limit 10KB/sec, refill period 1000 ms
[COMPLETE] request size 40 KB, new limit 80KB/sec, refill period 1000 ms
[COMPLETE] request size 40 KB, new limit 20KB/sec, refill period 1000 ms
[COMPLETE] request size 80 KB, new limit 160KB/sec, refill period 1000 ms
[COMPLETE] request size 80 KB, new limit 40KB/sec, refill period 1000 ms
[COMPLETE] request size 160 KB, new limit 320KB/sec, refill period 1000 ms
[COMPLETE] request size 160 KB, new limit 80KB/sec, refill period 1000 ms
[ OK ] RateLimiterTest.LimitChangeTest (5002 ms)
[----------] 4 tests from RateLimiterTest (27620 ms total)
[----------] Global test environment tear-down
[==========] 4 tests from 1 test case ran. (27621 ms total)
[ PASSED ] 4 tests.
```
Reviewers: sdong, IslamAbdelRahman, yiwu, andrewkr
Reviewed By: andrewkr
Subscribers: andrewkr, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D60207
2016-07-01 07:16:29 +00:00
|
|
|
TEST_F(RateLimiterTest, LimitChangeTest) {
|
|
|
|
// starvation test when limit changes to a smaller value
|
|
|
|
int64_t refill_period = 1000 * 1000;
|
|
|
|
auto* env = Env::Default();
|
2020-02-20 20:07:53 +00:00
|
|
|
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->EnableProcessing();
|
fix rate limiter to avoid starvation
Summary:
The current implementation of rate limiter has the possibility to introduce resource starvation when change its limit.
This diff aims to fix this problem by consuming request bytes partially.
Test Plan:
```
./rate_limiter_test
[==========] Running 4 tests from 1 test case.
[----------] Global test environment set-up.
[----------] 4 tests from RateLimiterTest
[ RUN ] RateLimiterTest.OverflowRate
[ OK ] RateLimiterTest.OverflowRate (0 ms)
[ RUN ] RateLimiterTest.StartStop
[ OK ] RateLimiterTest.StartStop (0 ms)
[ RUN ] RateLimiterTest.Rate
request size [1 - 1023], limit 10 KB/sec, actual rate: 10.355712 KB/sec, elapsed 2.00 seconds
request size [1 - 1023], limit 20 KB/sec, actual rate: 19.136564 KB/sec, elapsed 2.00 seconds
request size [1 - 2047], limit 20 KB/sec, actual rate: 20.783976 KB/sec, elapsed 2.10 seconds
request size [1 - 2047], limit 40 KB/sec, actual rate: 39.308144 KB/sec, elapsed 2.10 seconds
request size [1 - 4095], limit 40 KB/sec, actual rate: 40.318349 KB/sec, elapsed 2.20 seconds
request size [1 - 4095], limit 80 KB/sec, actual rate: 79.667396 KB/sec, elapsed 2.20 seconds
request size [1 - 8191], limit 80 KB/sec, actual rate: 81.807158 KB/sec, elapsed 2.30 seconds
request size [1 - 8191], limit 160 KB/sec, actual rate: 160.659761 KB/sec, elapsed 2.20 seconds
request size [1 - 16383], limit 160 KB/sec, actual rate: 160.700990 KB/sec, elapsed 3.00 seconds
request size [1 - 16383], limit 320 KB/sec, actual rate: 317.639481 KB/sec, elapsed 2.50 seconds
[ OK ] RateLimiterTest.Rate (22618 ms)
[ RUN ] RateLimiterTest.LimitChangeTest
[COMPLETE] request size 10 KB, new limit 20KB/sec, refill period 1000 ms
[COMPLETE] request size 10 KB, new limit 5KB/sec, refill period 1000 ms
[COMPLETE] request size 20 KB, new limit 40KB/sec, refill period 1000 ms
[COMPLETE] request size 20 KB, new limit 10KB/sec, refill period 1000 ms
[COMPLETE] request size 40 KB, new limit 80KB/sec, refill period 1000 ms
[COMPLETE] request size 40 KB, new limit 20KB/sec, refill period 1000 ms
[COMPLETE] request size 80 KB, new limit 160KB/sec, refill period 1000 ms
[COMPLETE] request size 80 KB, new limit 40KB/sec, refill period 1000 ms
[COMPLETE] request size 160 KB, new limit 320KB/sec, refill period 1000 ms
[COMPLETE] request size 160 KB, new limit 80KB/sec, refill period 1000 ms
[ OK ] RateLimiterTest.LimitChangeTest (5002 ms)
[----------] 4 tests from RateLimiterTest (27620 ms total)
[----------] Global test environment tear-down
[==========] 4 tests from 1 test case ran. (27621 ms total)
[ PASSED ] 4 tests.
```
Reviewers: sdong, IslamAbdelRahman, yiwu, andrewkr
Reviewed By: andrewkr
Subscribers: andrewkr, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D60207
2016-07-01 07:16:29 +00:00
|
|
|
struct Arg {
|
|
|
|
Arg(int32_t _request_size, Env::IOPriority _pri,
|
|
|
|
std::shared_ptr<RateLimiter> _limiter)
|
|
|
|
: request_size(_request_size), pri(_pri), limiter(_limiter) {}
|
|
|
|
int32_t request_size;
|
|
|
|
Env::IOPriority pri;
|
|
|
|
std::shared_ptr<RateLimiter> limiter;
|
|
|
|
};
|
|
|
|
|
|
|
|
auto writer = [](void* p) {
|
|
|
|
auto* arg = static_cast<Arg*>(p);
|
2017-06-13 21:51:22 +00:00
|
|
|
arg->limiter->Request(arg->request_size, arg->pri, nullptr /* stats */,
|
|
|
|
RateLimiter::OpType::kWrite);
|
fix rate limiter to avoid starvation
Summary:
The current implementation of rate limiter has the possibility to introduce resource starvation when change its limit.
This diff aims to fix this problem by consuming request bytes partially.
Test Plan:
```
./rate_limiter_test
[==========] Running 4 tests from 1 test case.
[----------] Global test environment set-up.
[----------] 4 tests from RateLimiterTest
[ RUN ] RateLimiterTest.OverflowRate
[ OK ] RateLimiterTest.OverflowRate (0 ms)
[ RUN ] RateLimiterTest.StartStop
[ OK ] RateLimiterTest.StartStop (0 ms)
[ RUN ] RateLimiterTest.Rate
request size [1 - 1023], limit 10 KB/sec, actual rate: 10.355712 KB/sec, elapsed 2.00 seconds
request size [1 - 1023], limit 20 KB/sec, actual rate: 19.136564 KB/sec, elapsed 2.00 seconds
request size [1 - 2047], limit 20 KB/sec, actual rate: 20.783976 KB/sec, elapsed 2.10 seconds
request size [1 - 2047], limit 40 KB/sec, actual rate: 39.308144 KB/sec, elapsed 2.10 seconds
request size [1 - 4095], limit 40 KB/sec, actual rate: 40.318349 KB/sec, elapsed 2.20 seconds
request size [1 - 4095], limit 80 KB/sec, actual rate: 79.667396 KB/sec, elapsed 2.20 seconds
request size [1 - 8191], limit 80 KB/sec, actual rate: 81.807158 KB/sec, elapsed 2.30 seconds
request size [1 - 8191], limit 160 KB/sec, actual rate: 160.659761 KB/sec, elapsed 2.20 seconds
request size [1 - 16383], limit 160 KB/sec, actual rate: 160.700990 KB/sec, elapsed 3.00 seconds
request size [1 - 16383], limit 320 KB/sec, actual rate: 317.639481 KB/sec, elapsed 2.50 seconds
[ OK ] RateLimiterTest.Rate (22618 ms)
[ RUN ] RateLimiterTest.LimitChangeTest
[COMPLETE] request size 10 KB, new limit 20KB/sec, refill period 1000 ms
[COMPLETE] request size 10 KB, new limit 5KB/sec, refill period 1000 ms
[COMPLETE] request size 20 KB, new limit 40KB/sec, refill period 1000 ms
[COMPLETE] request size 20 KB, new limit 10KB/sec, refill period 1000 ms
[COMPLETE] request size 40 KB, new limit 80KB/sec, refill period 1000 ms
[COMPLETE] request size 40 KB, new limit 20KB/sec, refill period 1000 ms
[COMPLETE] request size 80 KB, new limit 160KB/sec, refill period 1000 ms
[COMPLETE] request size 80 KB, new limit 40KB/sec, refill period 1000 ms
[COMPLETE] request size 160 KB, new limit 320KB/sec, refill period 1000 ms
[COMPLETE] request size 160 KB, new limit 80KB/sec, refill period 1000 ms
[ OK ] RateLimiterTest.LimitChangeTest (5002 ms)
[----------] 4 tests from RateLimiterTest (27620 ms total)
[----------] Global test environment tear-down
[==========] 4 tests from 1 test case ran. (27621 ms total)
[ PASSED ] 4 tests.
```
Reviewers: sdong, IslamAbdelRahman, yiwu, andrewkr
Reviewed By: andrewkr
Subscribers: andrewkr, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D60207
2016-07-01 07:16:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (uint32_t i = 1; i <= 16; i <<= 1) {
|
|
|
|
int32_t target = i * 1024 * 10;
|
|
|
|
// refill per second
|
|
|
|
for (int iter = 0; iter < 2; iter++) {
|
|
|
|
std::shared_ptr<RateLimiter> limiter =
|
2017-10-05 02:02:22 +00:00
|
|
|
std::make_shared<GenericRateLimiter>(
|
|
|
|
target, refill_period, 10, RateLimiter::Mode::kWritesOnly,
|
2021-01-26 06:07:26 +00:00
|
|
|
SystemClock::Default(), false /* auto_tuned */);
|
2022-07-19 16:31:14 +00:00
|
|
|
// After "GenericRateLimiter::Request:1" the mutex is held until the bytes
|
|
|
|
// are refilled. This test could be improved to change the limit when lock
|
|
|
|
// is released in `TimedWait()`.
|
2020-02-20 20:07:53 +00:00
|
|
|
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->LoadDependency(
|
fix rate limiter to avoid starvation
Summary:
The current implementation of rate limiter has the possibility to introduce resource starvation when change its limit.
This diff aims to fix this problem by consuming request bytes partially.
Test Plan:
```
./rate_limiter_test
[==========] Running 4 tests from 1 test case.
[----------] Global test environment set-up.
[----------] 4 tests from RateLimiterTest
[ RUN ] RateLimiterTest.OverflowRate
[ OK ] RateLimiterTest.OverflowRate (0 ms)
[ RUN ] RateLimiterTest.StartStop
[ OK ] RateLimiterTest.StartStop (0 ms)
[ RUN ] RateLimiterTest.Rate
request size [1 - 1023], limit 10 KB/sec, actual rate: 10.355712 KB/sec, elapsed 2.00 seconds
request size [1 - 1023], limit 20 KB/sec, actual rate: 19.136564 KB/sec, elapsed 2.00 seconds
request size [1 - 2047], limit 20 KB/sec, actual rate: 20.783976 KB/sec, elapsed 2.10 seconds
request size [1 - 2047], limit 40 KB/sec, actual rate: 39.308144 KB/sec, elapsed 2.10 seconds
request size [1 - 4095], limit 40 KB/sec, actual rate: 40.318349 KB/sec, elapsed 2.20 seconds
request size [1 - 4095], limit 80 KB/sec, actual rate: 79.667396 KB/sec, elapsed 2.20 seconds
request size [1 - 8191], limit 80 KB/sec, actual rate: 81.807158 KB/sec, elapsed 2.30 seconds
request size [1 - 8191], limit 160 KB/sec, actual rate: 160.659761 KB/sec, elapsed 2.20 seconds
request size [1 - 16383], limit 160 KB/sec, actual rate: 160.700990 KB/sec, elapsed 3.00 seconds
request size [1 - 16383], limit 320 KB/sec, actual rate: 317.639481 KB/sec, elapsed 2.50 seconds
[ OK ] RateLimiterTest.Rate (22618 ms)
[ RUN ] RateLimiterTest.LimitChangeTest
[COMPLETE] request size 10 KB, new limit 20KB/sec, refill period 1000 ms
[COMPLETE] request size 10 KB, new limit 5KB/sec, refill period 1000 ms
[COMPLETE] request size 20 KB, new limit 40KB/sec, refill period 1000 ms
[COMPLETE] request size 20 KB, new limit 10KB/sec, refill period 1000 ms
[COMPLETE] request size 40 KB, new limit 80KB/sec, refill period 1000 ms
[COMPLETE] request size 40 KB, new limit 20KB/sec, refill period 1000 ms
[COMPLETE] request size 80 KB, new limit 160KB/sec, refill period 1000 ms
[COMPLETE] request size 80 KB, new limit 40KB/sec, refill period 1000 ms
[COMPLETE] request size 160 KB, new limit 320KB/sec, refill period 1000 ms
[COMPLETE] request size 160 KB, new limit 80KB/sec, refill period 1000 ms
[ OK ] RateLimiterTest.LimitChangeTest (5002 ms)
[----------] 4 tests from RateLimiterTest (27620 ms total)
[----------] Global test environment tear-down
[==========] 4 tests from 1 test case ran. (27621 ms total)
[ PASSED ] 4 tests.
```
Reviewers: sdong, IslamAbdelRahman, yiwu, andrewkr
Reviewed By: andrewkr
Subscribers: andrewkr, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D60207
2016-07-01 07:16:29 +00:00
|
|
|
{{"GenericRateLimiter::Request",
|
|
|
|
"RateLimiterTest::LimitChangeTest:changeLimitStart"},
|
|
|
|
{"RateLimiterTest::LimitChangeTest:changeLimitEnd",
|
2022-07-19 16:31:14 +00:00
|
|
|
"GenericRateLimiter::Request:1"}});
|
fix rate limiter to avoid starvation
Summary:
The current implementation of rate limiter has the possibility to introduce resource starvation when change its limit.
This diff aims to fix this problem by consuming request bytes partially.
Test Plan:
```
./rate_limiter_test
[==========] Running 4 tests from 1 test case.
[----------] Global test environment set-up.
[----------] 4 tests from RateLimiterTest
[ RUN ] RateLimiterTest.OverflowRate
[ OK ] RateLimiterTest.OverflowRate (0 ms)
[ RUN ] RateLimiterTest.StartStop
[ OK ] RateLimiterTest.StartStop (0 ms)
[ RUN ] RateLimiterTest.Rate
request size [1 - 1023], limit 10 KB/sec, actual rate: 10.355712 KB/sec, elapsed 2.00 seconds
request size [1 - 1023], limit 20 KB/sec, actual rate: 19.136564 KB/sec, elapsed 2.00 seconds
request size [1 - 2047], limit 20 KB/sec, actual rate: 20.783976 KB/sec, elapsed 2.10 seconds
request size [1 - 2047], limit 40 KB/sec, actual rate: 39.308144 KB/sec, elapsed 2.10 seconds
request size [1 - 4095], limit 40 KB/sec, actual rate: 40.318349 KB/sec, elapsed 2.20 seconds
request size [1 - 4095], limit 80 KB/sec, actual rate: 79.667396 KB/sec, elapsed 2.20 seconds
request size [1 - 8191], limit 80 KB/sec, actual rate: 81.807158 KB/sec, elapsed 2.30 seconds
request size [1 - 8191], limit 160 KB/sec, actual rate: 160.659761 KB/sec, elapsed 2.20 seconds
request size [1 - 16383], limit 160 KB/sec, actual rate: 160.700990 KB/sec, elapsed 3.00 seconds
request size [1 - 16383], limit 320 KB/sec, actual rate: 317.639481 KB/sec, elapsed 2.50 seconds
[ OK ] RateLimiterTest.Rate (22618 ms)
[ RUN ] RateLimiterTest.LimitChangeTest
[COMPLETE] request size 10 KB, new limit 20KB/sec, refill period 1000 ms
[COMPLETE] request size 10 KB, new limit 5KB/sec, refill period 1000 ms
[COMPLETE] request size 20 KB, new limit 40KB/sec, refill period 1000 ms
[COMPLETE] request size 20 KB, new limit 10KB/sec, refill period 1000 ms
[COMPLETE] request size 40 KB, new limit 80KB/sec, refill period 1000 ms
[COMPLETE] request size 40 KB, new limit 20KB/sec, refill period 1000 ms
[COMPLETE] request size 80 KB, new limit 160KB/sec, refill period 1000 ms
[COMPLETE] request size 80 KB, new limit 40KB/sec, refill period 1000 ms
[COMPLETE] request size 160 KB, new limit 320KB/sec, refill period 1000 ms
[COMPLETE] request size 160 KB, new limit 80KB/sec, refill period 1000 ms
[ OK ] RateLimiterTest.LimitChangeTest (5002 ms)
[----------] 4 tests from RateLimiterTest (27620 ms total)
[----------] Global test environment tear-down
[==========] 4 tests from 1 test case ran. (27621 ms total)
[ PASSED ] 4 tests.
```
Reviewers: sdong, IslamAbdelRahman, yiwu, andrewkr
Reviewed By: andrewkr
Subscribers: andrewkr, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D60207
2016-07-01 07:16:29 +00:00
|
|
|
Arg arg(target, Env::IO_HIGH, limiter);
|
|
|
|
// The idea behind is to start a request first, then before it refills,
|
|
|
|
// update limit to a different value (2X/0.5X). No starvation should
|
|
|
|
// be guaranteed under any situation
|
|
|
|
// TODO(lightmark): more test cases are welcome.
|
|
|
|
env->StartThread(writer, &arg);
|
|
|
|
int32_t new_limit = (target << 1) >> (iter << 1);
|
|
|
|
TEST_SYNC_POINT("RateLimiterTest::LimitChangeTest:changeLimitStart");
|
|
|
|
arg.limiter->SetBytesPerSecond(new_limit);
|
|
|
|
TEST_SYNC_POINT("RateLimiterTest::LimitChangeTest:changeLimitEnd");
|
|
|
|
env->WaitForJoin();
|
|
|
|
fprintf(stderr,
|
|
|
|
"[COMPLETE] request size %" PRIi32 " KB, new limit %" PRIi32
|
|
|
|
"KB/sec, refill period %" PRIi64 " ms\n",
|
|
|
|
target / 1024, new_limit / 1024, refill_period / 1000);
|
|
|
|
}
|
|
|
|
}
|
2021-09-17 15:52:20 +00:00
|
|
|
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing();
|
fix rate limiter to avoid starvation
Summary:
The current implementation of rate limiter has the possibility to introduce resource starvation when change its limit.
This diff aims to fix this problem by consuming request bytes partially.
Test Plan:
```
./rate_limiter_test
[==========] Running 4 tests from 1 test case.
[----------] Global test environment set-up.
[----------] 4 tests from RateLimiterTest
[ RUN ] RateLimiterTest.OverflowRate
[ OK ] RateLimiterTest.OverflowRate (0 ms)
[ RUN ] RateLimiterTest.StartStop
[ OK ] RateLimiterTest.StartStop (0 ms)
[ RUN ] RateLimiterTest.Rate
request size [1 - 1023], limit 10 KB/sec, actual rate: 10.355712 KB/sec, elapsed 2.00 seconds
request size [1 - 1023], limit 20 KB/sec, actual rate: 19.136564 KB/sec, elapsed 2.00 seconds
request size [1 - 2047], limit 20 KB/sec, actual rate: 20.783976 KB/sec, elapsed 2.10 seconds
request size [1 - 2047], limit 40 KB/sec, actual rate: 39.308144 KB/sec, elapsed 2.10 seconds
request size [1 - 4095], limit 40 KB/sec, actual rate: 40.318349 KB/sec, elapsed 2.20 seconds
request size [1 - 4095], limit 80 KB/sec, actual rate: 79.667396 KB/sec, elapsed 2.20 seconds
request size [1 - 8191], limit 80 KB/sec, actual rate: 81.807158 KB/sec, elapsed 2.30 seconds
request size [1 - 8191], limit 160 KB/sec, actual rate: 160.659761 KB/sec, elapsed 2.20 seconds
request size [1 - 16383], limit 160 KB/sec, actual rate: 160.700990 KB/sec, elapsed 3.00 seconds
request size [1 - 16383], limit 320 KB/sec, actual rate: 317.639481 KB/sec, elapsed 2.50 seconds
[ OK ] RateLimiterTest.Rate (22618 ms)
[ RUN ] RateLimiterTest.LimitChangeTest
[COMPLETE] request size 10 KB, new limit 20KB/sec, refill period 1000 ms
[COMPLETE] request size 10 KB, new limit 5KB/sec, refill period 1000 ms
[COMPLETE] request size 20 KB, new limit 40KB/sec, refill period 1000 ms
[COMPLETE] request size 20 KB, new limit 10KB/sec, refill period 1000 ms
[COMPLETE] request size 40 KB, new limit 80KB/sec, refill period 1000 ms
[COMPLETE] request size 40 KB, new limit 20KB/sec, refill period 1000 ms
[COMPLETE] request size 80 KB, new limit 160KB/sec, refill period 1000 ms
[COMPLETE] request size 80 KB, new limit 40KB/sec, refill period 1000 ms
[COMPLETE] request size 160 KB, new limit 320KB/sec, refill period 1000 ms
[COMPLETE] request size 160 KB, new limit 80KB/sec, refill period 1000 ms
[ OK ] RateLimiterTest.LimitChangeTest (5002 ms)
[----------] 4 tests from RateLimiterTest (27620 ms total)
[----------] Global test environment tear-down
[==========] 4 tests from 1 test case ran. (27621 ms total)
[ PASSED ] 4 tests.
```
Reviewers: sdong, IslamAbdelRahman, yiwu, andrewkr
Reviewed By: andrewkr
Subscribers: andrewkr, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D60207
2016-07-01 07:16:29 +00:00
|
|
|
}
|
|
|
|
|
2023-05-10 17:18:36 +00:00
|
|
|
TEST_F(RateLimiterTest, AvailableByteSizeExhaustTest) {
|
|
|
|
SpecialEnv special_env(Env::Default(), /*time_elapse_only_sleep*/ true);
|
|
|
|
const std::chrono::seconds kTimePerRefill(1);
|
|
|
|
|
|
|
|
// This test makes sure available_bytes_ get exhausted first before queuing
|
|
|
|
// any remaining bytes when requested_bytes > available_bytes
|
|
|
|
const int64_t available_bytes_per_period = 500;
|
|
|
|
|
|
|
|
std::shared_ptr<RateLimiter> limiter = std::make_shared<GenericRateLimiter>(
|
|
|
|
available_bytes_per_period,
|
|
|
|
std::chrono::microseconds(kTimePerRefill).count(), 10 /* fairness */,
|
|
|
|
RateLimiter::Mode::kWritesOnly, special_env.GetSystemClock(),
|
|
|
|
false /* auto_tuned */);
|
|
|
|
|
|
|
|
// Step 1. Request 100 and wait for the refill
|
|
|
|
// so that the remaining available bytes are 400
|
|
|
|
limiter->Request(100, Env::IO_USER, nullptr /* stats */,
|
|
|
|
RateLimiter::OpType::kWrite);
|
|
|
|
special_env.SleepForMicroseconds(
|
|
|
|
static_cast<int>(std::chrono::microseconds(kTimePerRefill).count()));
|
|
|
|
|
|
|
|
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
|
|
|
|
"GenericRateLimiter::Request:PostEnqueueRequest", [&](void* arg) {
|
|
|
|
port::Mutex* request_mutex = (port::Mutex*)arg;
|
|
|
|
request_mutex->Unlock();
|
|
|
|
// Step 3. Check GetTotalBytesThrough = available_bytes_per_period
|
|
|
|
// to make sure that the first request (100) and the part of the second
|
|
|
|
// request (400) made through when the remaining of the second request
|
|
|
|
// got queued
|
|
|
|
ASSERT_EQ(available_bytes_per_period,
|
|
|
|
limiter->GetTotalBytesThrough(Env::IO_USER));
|
|
|
|
request_mutex->Lock();
|
|
|
|
});
|
|
|
|
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->EnableProcessing();
|
|
|
|
|
|
|
|
// Step 2. Request 500, which is greater than the remaining available bytes
|
|
|
|
// (400)
|
|
|
|
limiter->Request(500, Env::IO_USER, nullptr /* stats */,
|
|
|
|
RateLimiter::OpType::kWrite);
|
|
|
|
|
|
|
|
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing();
|
|
|
|
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->ClearCallBack(
|
|
|
|
"GenericRateLimiter::Request:PostEnqueueRequest");
|
|
|
|
}
|
|
|
|
|
2017-10-05 02:02:22 +00:00
|
|
|
TEST_F(RateLimiterTest, AutoTuneIncreaseWhenFull) {
|
|
|
|
const std::chrono::seconds kTimePerRefill(1);
|
|
|
|
const int kRefillsPerTune = 100; // needs to match util/rate_limiter.cc
|
|
|
|
|
2023-08-30 01:39:10 +00:00
|
|
|
auto mock_clock =
|
|
|
|
std::make_shared<MockSystemClock>(Env::Default()->GetSystemClock());
|
2017-10-05 02:02:22 +00:00
|
|
|
|
|
|
|
auto stats = CreateDBStatistics();
|
|
|
|
std::unique_ptr<RateLimiter> rate_limiter(new GenericRateLimiter(
|
|
|
|
1000 /* rate_bytes_per_sec */,
|
|
|
|
std::chrono::microseconds(kTimePerRefill).count(), 10 /* fairness */,
|
2023-08-30 01:39:10 +00:00
|
|
|
RateLimiter::Mode::kWritesOnly, mock_clock, true /* auto_tuned */));
|
2017-10-05 02:02:22 +00:00
|
|
|
|
|
|
|
// verify rate limit increases after a sequence of periods where rate limiter
|
|
|
|
// is always drained
|
|
|
|
int64_t orig_bytes_per_sec = rate_limiter->GetSingleBurstBytes();
|
|
|
|
rate_limiter->Request(orig_bytes_per_sec, Env::IO_HIGH, stats.get(),
|
|
|
|
RateLimiter::OpType::kWrite);
|
2023-08-30 01:39:10 +00:00
|
|
|
while (std::chrono::microseconds(mock_clock->NowMicros()) <=
|
2017-10-05 02:02:22 +00:00
|
|
|
kRefillsPerTune * kTimePerRefill) {
|
|
|
|
rate_limiter->Request(orig_bytes_per_sec, Env::IO_HIGH, stats.get(),
|
|
|
|
RateLimiter::OpType::kWrite);
|
|
|
|
}
|
|
|
|
int64_t new_bytes_per_sec = rate_limiter->GetSingleBurstBytes();
|
|
|
|
ASSERT_GT(new_bytes_per_sec, orig_bytes_per_sec);
|
|
|
|
|
|
|
|
// decreases after a sequence of periods where rate limiter is not drained
|
|
|
|
orig_bytes_per_sec = new_bytes_per_sec;
|
2023-08-30 01:39:10 +00:00
|
|
|
mock_clock->SleepForMicroseconds(static_cast<int>(
|
2017-10-05 02:02:22 +00:00
|
|
|
kRefillsPerTune * std::chrono::microseconds(kTimePerRefill).count()));
|
|
|
|
// make a request so tuner can be triggered
|
|
|
|
rate_limiter->Request(1 /* bytes */, Env::IO_HIGH, stats.get(),
|
|
|
|
RateLimiter::OpType::kWrite);
|
|
|
|
new_bytes_per_sec = rate_limiter->GetSingleBurstBytes();
|
|
|
|
ASSERT_LT(new_bytes_per_sec, orig_bytes_per_sec);
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
generic rate limiter
Summary:
A generic rate limiter that can be shared by threads and rocksdb
instances. Will use this to smooth out write traffic generated by
compaction and flush. This will help us get better p99 behavior on flash
storage.
Test Plan:
unit test output
==== Test RateLimiterTest.Rate
request size [1 - 1023], limit 10 KB/sec, actual rate: 10.374969 KB/sec, elapsed 2002265
request size [1 - 2047], limit 20 KB/sec, actual rate: 20.771242 KB/sec, elapsed 2002139
request size [1 - 4095], limit 40 KB/sec, actual rate: 41.285299 KB/sec, elapsed 2202424
request size [1 - 8191], limit 80 KB/sec, actual rate: 81.371605 KB/sec, elapsed 2402558
request size [1 - 16383], limit 160 KB/sec, actual rate: 162.541268 KB/sec, elapsed 3303500
Reviewers: yhchiang, igor, sdong
Reviewed By: sdong
Subscribers: leveldb
Differential Revision: https://reviews.facebook.net/D19359
2014-07-08 18:41:57 +00:00
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
2022-10-18 07:35:35 +00:00
|
|
|
ROCKSDB_NAMESPACE::port::InstallStackTraceHandler();
|
2015-03-17 21:08:00 +00:00
|
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
|
|
return RUN_ALL_TESTS();
|
generic rate limiter
Summary:
A generic rate limiter that can be shared by threads and rocksdb
instances. Will use this to smooth out write traffic generated by
compaction and flush. This will help us get better p99 behavior on flash
storage.
Test Plan:
unit test output
==== Test RateLimiterTest.Rate
request size [1 - 1023], limit 10 KB/sec, actual rate: 10.374969 KB/sec, elapsed 2002265
request size [1 - 2047], limit 20 KB/sec, actual rate: 20.771242 KB/sec, elapsed 2002139
request size [1 - 4095], limit 40 KB/sec, actual rate: 41.285299 KB/sec, elapsed 2202424
request size [1 - 8191], limit 80 KB/sec, actual rate: 81.371605 KB/sec, elapsed 2402558
request size [1 - 16383], limit 160 KB/sec, actual rate: 162.541268 KB/sec, elapsed 3303500
Reviewers: yhchiang, igor, sdong
Reviewed By: sdong
Subscribers: leveldb
Differential Revision: https://reviews.facebook.net/D19359
2014-07-08 18:41:57 +00:00
|
|
|
}
|