Skip to content

perf(ingester): Convert postings cache from FIFO to LRU eviction#7510

Merged
danielblando merged 2 commits into
cortexproject:masterfrom
alanprot:lru-postings-cache
May 12, 2026
Merged

perf(ingester): Convert postings cache from FIFO to LRU eviction#7510
danielblando merged 2 commits into
cortexproject:masterfrom
alanprot:lru-postings-cache

Conversation

@alanprot
Copy link
Copy Markdown
Member

@alanprot alanprot commented May 12, 2026

What this PR does:

The expanded postings cache previously used FIFO eviction, which evicts the oldest entry regardless of access frequency. Under memory pressure with high series churn, actively-queried entries get evicted simply because they were inserted earliest, causing repeated expensive recomputations.

LRU eviction moves entries to the back of the list on every access, ensuring frequently-queried entries (e.g., ruler queries running every 30s) stay cached even when the cache is full. Only entries that haven't been accessed recently get evicted.

Implementation: add a map[string]*list.Element for O(1) MoveToBack on cache hit. The eviction logic (shouldEvictHead/evictHead) remains unchanged — it still evicts from the front, but now the front contains the least-recently-used entry instead of the oldest-inserted entry.

Which issue(s) this PR fixes:
Fixes #

Checklist

  • Tests updated
  • [NA] Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]
  • docs/configuration/v1-guarantees.md updated if this PR introduces experimental flags

The expanded postings cache previously used FIFO eviction, which evicts
the oldest entry regardless of access frequency. Under memory pressure
with high series churn, actively-queried entries get evicted simply
because they were inserted earliest, causing repeated expensive
recomputations.

LRU eviction moves entries to the back of the list on every access,
ensuring frequently-queried entries (e.g., ruler queries running every
30s) stay cached even when the cache is full. Only entries that haven't
been accessed recently get evicted.

Implementation: add a map[string]*list.Element for O(1) MoveToBack on
cache hit. The eviction logic (shouldEvictHead/evictHead) remains
unchanged — it still evicts from the front, but now the front contains
the least-recently-used entry instead of the oldest-inserted entry.

Signed-off-by: Alan Protasio <approtas@amazon.com>
@alanprot alanprot force-pushed the lru-postings-cache branch from 96a7948 to 4d47b41 Compare May 12, 2026 15:43
@alanprot alanprot marked this pull request as ready for review May 12, 2026 15:43
Signed-off-by: Alan Protasio <approtas@amazon.com>
Copy link
Copy Markdown
Contributor

@danielblando danielblando left a comment

Choose a reason for hiding this comment

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

Nice

@danielblando danielblando merged commit a13e3d9 into cortexproject:master May 12, 2026
68 of 69 checks passed
@alanprot alanprot deleted the lru-postings-cache branch May 12, 2026 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants