github-actions[bot] commented on code in PR #62273:
URL: https://github.com/apache/doris/pull/62273#discussion_r3108260248
##########
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);
Review Comment:
`max_tasks` is the memory-derived upper bound here, so `expected` should
never end up larger than it. Before this refactor,
`ScannerContext::_available_pickup_scanner_count()` first clamped the lower
bound by `max_scanners` and then kept `expected_scanners` inside
`[min_scanners, max_scanners]`. After this change, if memory only allows 1 task
but `min_concurrency` is 4, this returns 4 and both scan scheduling
(`scanner_context.cpp`) and local exchange (`dependency.cpp`) keep too many
tasks runnable under memory pressure. Please clamp to the memory-derived
maximum instead of taking `max(max_tasks, min_tasks)`.
##########
be/src/exec/pipeline/dependency.cpp:
##########
@@ -192,6 +206,26 @@ void
LocalExchangeSharedState::sub_running_source_operators() {
}
}
+void LocalExchangeSharedState::update_total_mem_usage(int64_t delta, int
sink_ins_idx) {
+ if (adaptive_processor) {
+ DCHECK_LT(sink_ins_idx, sink_deps.size());
+ std::unique_lock<std::mutex> lc(le_lock);
+ auto slots = adaptive_processor->available_task_slots(sink_ins_idx);
+ DCHECK_GT(slots, 0);
+
adaptive_processor->adjust_parallelism(exchanger->_running_sink_operators.load(),
slots,
Review Comment:
This adaptive branch no longer uses `mem_usage` / `buffer_mem_limit`; it
only compares the fixed live-sender count (`_running_sink_operators`,
decremented only in `sub_running_sink_operators()`) against
`available_task_slots()`. That breaks byte-level backpressure for single-sender
exchanges: `LocalExchangeSinkLocalState::init()` hardcodes `min_concurrency =
1`, and `MemLimiter::empty_task_slots()` also floors the slot count at 1, so a
1-sender local exchange always reaches `remain = max(0, 1 - 1) = 0` here and
its sink dependency is never blocked no matter how much buffered memory has
accumulated. Before this change, the sender was blocked once `mem_usage >
buffer_mem_limit`.
--
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]