Skip to content

Commit

Permalink
[fix](memtable-limiter) do not block write if load mem usage is low (a…
Browse files Browse the repository at this point in the history
…pache#28602)


Co-authored-by: Yongqiang YANG <98214048+dataroaring@users.noreply.github.com>
  • Loading branch information
kaijchen and dataroaring authored Dec 19, 2023
1 parent 9434ee5 commit 1253ed0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions be/src/common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,10 @@ DEFINE_Int32(load_process_max_memory_limit_percent, "50"); // 50%
// might avoid all load jobs hang at the same time.
DEFINE_Int32(load_process_soft_mem_limit_percent, "80");

// If load memory consumption is within load_process_safe_mem_permit_percent,
// memtable memory limiter will do nothing.
DEFINE_Int32(load_process_safe_mem_permit_percent, "5");

// result buffer cancelled time (unit: second)
DEFINE_mInt32(result_buffer_cancelled_interval_time, "300");

Expand Down
4 changes: 4 additions & 0 deletions be/src/common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,10 @@ DECLARE_Int32(load_process_max_memory_limit_percent); // 50%
// might avoid all load jobs hang at the same time.
DECLARE_Int32(load_process_soft_mem_limit_percent);

// If load memory consumption is within load_process_safe_mem_permit_percent,
// memtable memory limiter will do nothing.
DECLARE_Int32(load_process_safe_mem_permit_percent);

// result buffer cancelled time (unit: second)
DECLARE_mInt32(result_buffer_cancelled_interval_time);

Expand Down
10 changes: 8 additions & 2 deletions be/src/olap/memtable_memory_limiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ MemTableMemoryLimiter::~MemTableMemoryLimiter() {
Status MemTableMemoryLimiter::init(int64_t process_mem_limit) {
_load_hard_mem_limit = calc_process_max_load_memory(process_mem_limit);
_load_soft_mem_limit = _load_hard_mem_limit * config::load_process_soft_mem_limit_percent / 100;
_load_safe_mem_permit =
_load_hard_mem_limit * config::load_process_safe_mem_permit_percent / 100;
g_load_hard_mem_limit.set_value(_load_hard_mem_limit);
g_load_soft_mem_limit.set_value(_load_soft_mem_limit);
_mem_tracker = std::make_unique<MemTrackerLimiter>(MemTrackerLimiter::Type::LOAD,
Expand Down Expand Up @@ -97,10 +99,14 @@ bool MemTableMemoryLimiter::_hard_limit_reached() {
_proc_mem_extra() >= 0;
}

bool MemTableMemoryLimiter::_load_usage_low() {
return _mem_tracker->consumption() <= _load_safe_mem_permit;
}

void MemTableMemoryLimiter::handle_memtable_flush() {
// Check the soft limit.
DCHECK(_load_soft_mem_limit > 0);
if (!_soft_limit_reached()) {
if (!_soft_limit_reached() || _load_usage_low()) {
return;
}
MonotonicStopWatch timer;
Expand Down Expand Up @@ -243,4 +249,4 @@ void MemTableMemoryLimiter::_refresh_mem_tracker() {
}
}

} // namespace doris
} // namespace doris
2 changes: 2 additions & 0 deletions be/src/olap/memtable_memory_limiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class MemTableMemoryLimiter {

bool _soft_limit_reached();
bool _hard_limit_reached();
bool _load_usage_low();
void _flush_active_memtables(int64_t need_flush);
int64_t _flush_memtable(std::weak_ptr<MemTableWriter> writer_to_flush, int64_t threshold);
void _refresh_mem_tracker();
Expand All @@ -68,6 +69,7 @@ class MemTableMemoryLimiter {
std::unique_ptr<MemTrackerLimiter> _mem_tracker;
int64_t _load_hard_mem_limit = -1;
int64_t _load_soft_mem_limit = -1;
int64_t _load_safe_mem_permit = -1;

std::vector<std::weak_ptr<MemTableWriter>> _writers;
std::vector<std::weak_ptr<MemTableWriter>> _active_writers;
Expand Down

0 comments on commit 1253ed0

Please sign in to comment.