Fix API server memory leak: bound DBDagBag version cache with LRU eviction#64326
Open
dheerajturaga wants to merge 2 commits intoapache:mainfrom
Open
Fix API server memory leak: bound DBDagBag version cache with LRU eviction#64326dheerajturaga wants to merge 2 commits intoapache:mainfrom
dheerajturaga wants to merge 2 commits intoapache:mainfrom
Conversation
…ction Replace the plain dict in DBDagBag._dags with a bounded OrderedDict-based LRU cache. In long-running API server processes, every unique dag_version_id accessed is inserted and never evicted, causing unbounded RSS growth (observed: 9.4 GiB after 7 days with ~70k DAG versions in DB). The cache is now capped at 512 entries by default (configurable via core.max_dag_version_cache_size). Cache hits promote the entry to MRU so frequently-accessed versions are retained over stale historical ones.
eladkal
reviewed
Mar 27, 2026
Co-authored-by: Elad Kalif <45845474+eladkal@users.noreply.github.com>
Contributor
|
Nice. Seems like a real production bug. A few thoughts:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DBDagBag._dags is an unbounded in-memory cache causing steady memory
growth in the API server.
DBDagBag was designed for the scheduler, which works with a bounded set
of currently-active DAG versions. As an API server singleton, it is exposed to
the full history of DAG versions in the database with no bound on how
many it will cache
Replace the plain dict in DBDagBag._dags with a bounded OrderedDict-based
LRU cache. In long-running API server processes, every unique dag_version_id
accessed is inserted and never evicted, causing unbounded RSS growth (observed:
9.4 GiB after 7 days with ~70k DAG versions in DB).
The cache is now capped at 512 entries by default (configurable via
core.max_dag_version_cache_size). Cache hits promote the entry to MRU so
frequently-accessed versions are retained over stale historical ones.
Was generative AI tooling used to co-author this PR?
ClaudeCode