Skip to content

feat(query): add spill backoff with sleep for low-memory queries under global pressure#19655

Open
dqhl76 wants to merge 5 commits intodatabendlabs:mainfrom
dqhl76:dqhl76/cherry-pick-3c4c6d5
Open

feat(query): add spill backoff with sleep for low-memory queries under global pressure#19655
dqhl76 wants to merge 5 commits intodatabendlabs:mainfrom
dqhl76:dqhl76/cherry-pick-3c4c6d5

Conversation

@dqhl76
Copy link
Copy Markdown
Collaborator

@dqhl76 dqhl76 commented Apr 2, 2026

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

When global memory pressure triggers spilling, low-memory queries can now sleep with exponential backoff before actually spilling. This gives the system time to reclaim memory from heavier queries, avoiding unnecessary spill I/O for lightweight queries that aren't major contributors to memory pressure.

Controlled by two new settings:

  • spill_global_backoff_max_sleep_ms — Maximum total sleep time (in milliseconds) for one spill decision under global-pressure backoff. Default: 2000.

  • min_query_memory_usage — A query is considered low-memory when its memory usage in bytes is at or below this threshold. Default: 0 (disabled).

Backoff uses exponential sleep starting at 200ms, doubling each attempt, capped by the remaining sleep budget. Once the budget is exhausted, the query spills normally.

Tests

  • Unit Test

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

This change is Reviewable

@github-actions github-actions bot added the pr-feature this PR introduces a new feature to the codebase label Apr 2, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 499dc953ab

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/query/pipeline/transforms/src/processors/memory_settings.rs Outdated
@dqhl76 dqhl76 force-pushed the dqhl76/cherry-pick-3c4c6d5 branch from 499dc95 to 87757db Compare April 2, 2026 02:48
…r global pressure

When global memory pressure triggers spill but the current query's memory
usage is low, sleep with exponential backoff before spilling to give other
queries a chance to release memory. Rename low_query_threshold to
low_query_memory_bytes for clarity and add observability logging.
@dqhl76 dqhl76 force-pushed the dqhl76/cherry-pick-3c4c6d5 branch from 87757db to a7145e0 Compare April 2, 2026 05:17
@dqhl76 dqhl76 requested a review from zhang2014 April 2, 2026 05:31
Comment thread src/query/settings/src/settings_default.rs Outdated
Comment thread src/query/pipeline/transforms/src/processors/memory_settings.rs Outdated
@dqhl76 dqhl76 requested a review from zhang2014 April 3, 2026 03:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-feature this PR introduces a new feature to the codebase

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants