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


##########
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");
 // (Advanced) Maximum size of per-query receive-side buffer

Review Comment:
   Renaming the existing BE config key here is a compatibility break. A 
deployment that already sets `doris_scanner_dynamic_interval_ms` in `be.conf` 
will silently fall back to the default after upgrade, because the old key is no 
longer declared anywhere. Since the scanner path is still using the same knob, 
we should keep the old name as an alias (or keep the old key and add a separate 
exec-specific key) instead of repurposing it in place.



##########
be/src/exec/exchange/local_exchanger.cpp:
##########
@@ -487,27 +482,30 @@ Status 
AdaptivePassthroughExchanger::_split_rows(RuntimeState* state,
         for (int32_t i = 1; i <= _num_partitions; ++i) {
             partition_rows_histogram[i] += partition_rows_histogram[i - 1];
         }

Review Comment:
   In adaptive execution this `BlockWrapper` immediately calls 
`LocalExchangeSharedState::update_total_mem_usage()`, and that path indexes 
`sink_deps[sink_ins_idx]`. Passing `-1` here turns the adaptive passthrough 
shuffle branch into an out-of-bounds access as soon as a block is produced.
   
   ```suggestion
       std::shared_ptr<BlockWrapper> new_block_wrapper = 
BlockWrapper::create_shared(
               std::move(data_block), sink_info.local_state->_shared_state, 
sink_info.ins_idx);
   ```



##########
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;
+    }

Review Comment:
   `available_task_slots()` is supposed to clamp the target parallelism into 
the memory-derived window, but this line does the opposite: when memory 
pressure drops `max_tasks` below `min_concurrency`, it raises `expected` back 
up to the larger `min_tasks`. For example, with `min_concurrency=4` and only 
enough memory for one task, this still returns `4`, so the adaptive limiter 
never actually throttles. The previous scanner implementation first lowered the 
minimum to the memory cap before clamping.



-- 
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