Skip to content

Commit

Permalink
rename some variables and change default value to 30
Browse files Browse the repository at this point in the history
Signed-off-by: Lloyd-Pottiger <yan1579196623@gmail.com>
  • Loading branch information
Lloyd-Pottiger committed Aug 3, 2022
1 parent e304dea commit 820766b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
26 changes: 13 additions & 13 deletions dbms/src/Encryption/RateLimiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,15 +302,15 @@ ReadLimiter::ReadLimiter(
Int64 ReadLimiter::getAvailableBalance()
{
Int64 bytes = get_read_bytes();
if (bytes < last_stat_bytes)
if (unlikely(bytes < last_stat_bytes))
{
LOG_FMT_WARNING(
log,
"last_stat: {} current_stat: {}",
last_stat_bytes,
bytes);
}
else if (bytes == last_stat_bytes)
else if (likely(bytes == last_stat_bytes))
{
return available_balance;
}
Expand Down Expand Up @@ -364,18 +364,18 @@ void ReadLimiter::refillAndAlloc()
}
}

IORateLimiter::IORateLimiter(UInt64 update_io_stat_period_ms_)
IORateLimiter::IORateLimiter(UInt64 update_read_info_period_ms_)
: log(Logger::get("IORateLimiter"))
, stop(false)
, update_io_stat_period_ms(update_io_stat_period_ms_)
, update_read_info_period_ms(update_read_info_period_ms_)
{}

IORateLimiter::~IORateLimiter()
{
stop.store(true, std::memory_order_relaxed);
if (auto_tune_and_get_io_info_thread.joinable())
if (auto_tune_and_get_read_info_thread.joinable())
{
auto_tune_and_get_io_info_thread.join();
auto_tune_and_get_read_info_thread.join();
}
}

Expand Down Expand Up @@ -600,28 +600,28 @@ void IORateLimiter::setStop()

void IORateLimiter::runAutoTune()
{
auto auto_tune_and_get_io_info_worker = [&]() {
auto auto_tune_and_get_read_info_worker = [&]() {
using time_point = std::chrono::time_point<std::chrono::system_clock>;
using clock = std::chrono::system_clock;
time_point auto_tune_time = clock::now();
time_point update_io_stat_time = auto_tune_time;
time_point update_read_info_time = auto_tune_time;
while (!stop.load(std::memory_order_relaxed))
{
std::this_thread::sleep_for(std::chrono::milliseconds(update_io_stat_period_ms));
std::this_thread::sleep_for(std::chrono::milliseconds(update_read_info_period_ms));
auto now_time_point = clock::now();
if ((io_config.auto_tune_sec > 0) && (now_time_point - auto_tune_time > std::chrono::seconds(io_config.auto_tune_sec)))
if ((io_config.auto_tune_sec > 0) && (now_time_point - auto_tune_time >= std::chrono::seconds(io_config.auto_tune_sec)))
{
autoTune();
auto_tune_time = now_time_point;
}
if ((bg_read_limiter || fg_read_limiter) && (now_time_point - update_io_stat_time > std::chrono::milliseconds(update_io_stat_period_ms)))
if ((bg_read_limiter || fg_read_limiter) && likely(now_time_point - update_read_info_time >= std::chrono::milliseconds(update_read_info_period_ms)))
{
getCurrentIOInfo();
update_io_stat_time = now_time_point;
update_read_info_time = now_time_point;
}
}
};
auto_tune_and_get_io_info_thread = std::thread(auto_tune_and_get_io_info_worker);
auto_tune_and_get_read_info_thread = std::thread(auto_tune_and_get_read_info_worker);
}

std::unique_ptr<IOLimitTuner> IORateLimiter::createIOLimitTuner()
Expand Down
8 changes: 4 additions & 4 deletions dbms/src/Encryption/RateLimiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,11 @@ using ReadLimiterPtr = std::shared_ptr<ReadLimiter>;
//
// Constructor parameters:
//
// `update_io_stat_period_ms` is the interval between calling getCurrentIOInfo. Default is 200ms.
// `update_read_info_period_ms` is the interval between calling getCurrentIOInfo. Default is 30ms.
class IORateLimiter
{
public:
explicit IORateLimiter(UInt64 update_io_stat_period_ms = 200);
explicit IORateLimiter(UInt64 update_read_info_period_ms_ = 30);
~IORateLimiter();

WriteLimiterPtr getWriteLimiter();
Expand Down Expand Up @@ -248,9 +248,9 @@ class IORateLimiter
LoggerPtr log;

std::atomic<bool> stop;
std::thread auto_tune_and_get_io_info_thread;
std::thread auto_tune_and_get_read_info_thread;
ReadInfo read_info;
const UInt64 update_io_stat_period_ms;
const UInt64 update_read_info_period_ms;

// Noncopyable and nonmovable.
DISALLOW_COPY_AND_MOVE(IORateLimiter);
Expand Down

0 comments on commit 820766b

Please sign in to comment.