Skip to content

lib/logstorage: limit the total memory used by concurrently executed queries#1550

Open
cuongleqq wants to merge 5 commits into
masterfrom
add-global-query-memory-limiter
Open

lib/logstorage: limit the total memory used by concurrently executed queries#1550
cuongleqq wants to merge 5 commits into
masterfrom
add-global-query-memory-limiter

Conversation

@cuongleqq

@cuongleqq cuongleqq commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Closes #1551

Issue

  • Some pipes can only use up to a fixed fraction of the memory available to VictoriaLogs (memory.Allowed()) for their state, even when there is still free memory available:
    • 40%: stats, running_stats, top, uniq
    • 20%: sort, facets, stream_context
  • Each pipe has its own limit, separate from the others. When many queries run at the same time, each one can reach its limit, so the total memory gets too big and the process can be OOM killed.

Fix

  • Add one memory pool shared by all running queries (50% of memory.Allowed()).
  • The pipes now take memory from this shared pool instead of using their own separate limit. If the pool is full, the query fails with an error instead of being OOM killed.

Design

To keep it simple:

  • All the pipes that have their own limits now draw the memory directly from the shared pool.
  • Sub-queries initialization previously also had its own limit; it now reports the memory reserved back to where queries are initialized, so the memory is released after the query is released.

Future todo:

  • Make subqueries for the in filter draw memory from the pool.
  • Could support a per-query memory cap.

@cuongleqq cuongleqq force-pushed the add-global-query-memory-limiter branch from c11a2d2 to 5956604 Compare July 1, 2026 04:29
@cuongleqq cuongleqq force-pushed the add-global-query-memory-limiter branch from 299040a to 85018c2 Compare July 1, 2026 15:18
@cuongleqq cuongleqq marked this pull request as ready for review July 2, 2026 03:23

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 20 files

Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lib/logstorage: limit the total memory used by concurrently executed queries

1 participant