github-actions[bot] commented on code in PR #62273:
URL: https://github.com/apache/doris/pull/62273#discussion_r3090517560


##########
be/src/exec/common/memory.cpp:
##########
@@ -87,4 +115,96 @@ void MemLimiter::reestimated_block_mem_bytes(int64_t value) 
{
             debug_string(), estimated_block_mem_bytes, old_value, value);
 }
 
+// Report current memory usage to the arbitrator and receive updated memory 
limit.
+// Called periodically (typically by instance 0) to adjust allocation based on 
actual usage.
+void MemLimiter::update_mem_limit() {
+    int64_t old_value = arb_mem_bytes;
+    int64_t new_value = estimated_block_mem_bytes;
+
+    new_value = std::min(new_value, operator_mem_limit);
+    arb_mem_bytes = new_value;
+
+    int64_t new_mem_limit = mem_share_arb->update_mem_bytes(old_value, 
new_value);
+    mem_limit = new_mem_limit;
+
+    VLOG_DEBUG << fmt::format(
+            "update_mem_limit. context = {}, new mem limit = {}, mem bytes = 
{} "
+            "-> {}, mem_share_arb: {}",
+            debug_string(), new_mem_limit, old_value, new_value, 
mem_share_arb->debug_string());
+}
+
+// ==================== AdaptiveTaskProcessor Implementation 
====================
+
+// Calculate available task slots with adaptive adjustment.
+// Combines memory-based limits from MemLimiter with configured min/max bounds.
+//
+// Instance 0 is responsible for triggering memory limit updates to avoid
+// redundant arbitrator calls from parallel instances.
+//
+// Rate limiting: Adjustments only occur every 
`doris_adaptive_tasks_interval_ms`
+// to prevent rapid oscillation in concurrency levels.
+int AdaptiveTaskProcessor::available_task_slots(int ins_idx) {
+    int min_tasks = std::max(1, min_concurrency);
+    int max_tasks = mem_limiter->empty_task_slots(ins_idx);
+    max_tasks = std::min(max_tasks, max_concurrency);
+    if (ins_idx == 0) {
+        // Adjust memory limit via memory share arbitrator
+        mem_limiter->update_mem_limit();
+    }
+
+    int& expected = expected_tasks;
+    int64_t now = UnixMillis();
+    // Avoid frequent adjustment - only adjust every 100ms
+    if (now - adjust_tasks_last_timestamp <= 
config::doris_adaptive_tasks_interval_ms) {
+        return expected;
+    }
+    adjust_tasks_last_timestamp = now;
+    auto old_tasks = expected_tasks;

Review Comment:
   This changes the old scan-side clamp semantics. Before the refactor, scan 
concurrency was clamped into `[min_scanners, max_scanners]` after first 
reducing `min_scanners = min(min_scanners, max_scanners)`. Here we now return 
`max(min_tasks, max_tasks)`, so a user-set `min_scanners_concurrency` can 
override the memory-derived cap. For example, if adaptive scan computes 
`max_tasks = 1` but the session min is 4, `available_task_slots()` returns 4 
and the scheduler keeps four scanners running, which defeats the memory-control 
path being generalized in this PR. This is a regression on the existing scan 
path, not only on the new local-exchange path.



##########
be/src/common/config.cpp:
##########
@@ -345,7 +345,7 @@ DEFINE_mInt32(doris_scanner_row_num, "16384");
 DEFINE_mInt32(doris_scanner_row_bytes, "10485760");
 // single read execute fragment max run time millseconds
 DEFINE_mInt32(doris_scanner_max_run_time_ms, "1000");
-DEFINE_mInt32(doris_scanner_dynamic_interval_ms, "100");
+DEFINE_mInt32(doris_adaptive_tasks_interval_ms, "100");

Review Comment:
   This silently drops compatibility with existing `be.conf` files that already 
tune `doris_scanner_dynamic_interval_ms`. `Properties::load()` keeps unknown 
keys, so after upgrade the old setting just stops being consumed and Doris 
falls back to the default 100ms interval. Since this is a user-visible BE 
config rename, we should keep the old name as an alias (or read both) instead 
of breaking existing deployments.



##########
be/src/exec/common/memory.cpp:
##########
@@ -87,4 +115,96 @@ void MemLimiter::reestimated_block_mem_bytes(int64_t value) 
{
             debug_string(), estimated_block_mem_bytes, old_value, value);
 }
 
+// Report current memory usage to the arbitrator and receive updated memory 
limit.
+// Called periodically (typically by instance 0) to adjust allocation based on 
actual usage.
+void MemLimiter::update_mem_limit() {
+    int64_t old_value = arb_mem_bytes;
+    int64_t new_value = estimated_block_mem_bytes;
+
+    new_value = std::min(new_value, operator_mem_limit);
+    arb_mem_bytes = new_value;
+
+    int64_t new_mem_limit = mem_share_arb->update_mem_bytes(old_value, 
new_value);
+    mem_limit = new_mem_limit;
+
+    VLOG_DEBUG << fmt::format(
+            "update_mem_limit. context = {}, new mem limit = {}, mem bytes = 
{} "
+            "-> {}, mem_share_arb: {}",
+            debug_string(), new_mem_limit, old_value, new_value, 
mem_share_arb->debug_string());
+}
+
+// ==================== AdaptiveTaskProcessor Implementation 
====================
+
+// Calculate available task slots with adaptive adjustment.
+// Combines memory-based limits from MemLimiter with configured min/max bounds.
+//
+// Instance 0 is responsible for triggering memory limit updates to avoid
+// redundant arbitrator calls from parallel instances.
+//
+// Rate limiting: Adjustments only occur every 
`doris_adaptive_tasks_interval_ms`
+// to prevent rapid oscillation in concurrency levels.
+int AdaptiveTaskProcessor::available_task_slots(int ins_idx) {
+    int min_tasks = std::max(1, min_concurrency);
+    int max_tasks = mem_limiter->empty_task_slots(ins_idx);
+    max_tasks = std::min(max_tasks, max_concurrency);
+    if (ins_idx == 0) {
+        // Adjust memory limit via memory share arbitrator
+        mem_limiter->update_mem_limit();
+    }
+
+    int& expected = expected_tasks;
+    int64_t now = UnixMillis();
+    // Avoid frequent adjustment - only adjust every 100ms
+    if (now - adjust_tasks_last_timestamp <= 
config::doris_adaptive_tasks_interval_ms) {
+        return expected;
+    }
+    adjust_tasks_last_timestamp = now;
+    auto old_tasks = expected_tasks;
+
+    expected = std::max(max_tasks, min_tasks);
+    VLOG_DEBUG << fmt::format(
+            "available_task_slots.  old_tasks = {}, expected tasks = {} "
+            ", min_tasks: {}, max_tasks: {}",
+            old_tasks, expected, min_tasks, max_tasks);
+
+    // TODO(gabriel): Tasks are scheduled adaptively based on the memory usage 
now.
+    return expected;
+}
+
+// Adjust parallelism by blocking/unblocking dependencies based on memory 
pressure.
+//
+// When running_sink_operators > expected:
+//   - Block excess dependencies to reduce parallelism
+//   - Dependencies are stored in a stack for LIFO release
+//
+// When running_sink_operators <= expected:
+//   - Unblock dependencies to allow more parallelism
+//   - LIFO order ensures recently blocked tasks resume first (cache locality)
+void AdaptiveTaskProcessor::adjust_parallelism(int running_sink_operators, int 
expected,
+                                               std::shared_ptr<Dependency> dep,
+                                               std::unique_lock<std::mutex>& 
/* lc */) {

Review Comment:
   `blocking_dependencies.size()` is being used as a proxy for "number of 
blocked sink operators", but this stack can contain the same dependency 
multiple times. `LocalExchangeSharedState::update_total_mem_usage()` passes the 
producing sink dependency on every positive allocation, and 
`AdaptivePassthroughExchanger::_split_rows()` can create several 
`BlockWrapper`s in one sink call. In that case we can push the same 
`sink_deps[sink_ins_idx]` repeatedly until `size() == remain`, even though only 
one task is actually blocked. The exchanger then leaves too many sink operators 
runnable and exceeds the intended concurrency / memory cap. We need 
deduplication per dependency (or another structure keyed by blocked operator) 
here.



##########
be/src/exec/pipeline/dependency.cpp:
##########
@@ -192,6 +206,26 @@ void 
LocalExchangeSharedState::sub_running_source_operators() {
     }
 }
 

Review Comment:
   The adaptive branch bypasses `mem_usage > buffer_mem_limit` entirely. That 
means once BE enters low-memory mode, 
`LocalExchangeSinkOperatorX::set_low_memory_mode()` still tightens 
`buffer_mem_limit`, but the sink no longer uses that emergency cap when 
`enable_adaptive_execution` is on (which FE defaults to true in this PR). Under 
pressure, local exchange can therefore keep buffering up to the normal 
arbitrated share instead of `low_memory_mode_buffer_limit()`. The old path 
blocked immediately on the tightened limit, so this is a real regression in 
low-memory behavior.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to