Skip to content

prevent server from being OOM-killed when multiple memory-intensive queries run concurrently - #1896

Open
nikhilsinhaparseable wants to merge 4 commits into
parseablehq:mainfrom
nikhilsinhaparseable:fix/query-memory-admission
Open

nikhilsinhaparseable wants to merge 4 commits into
parseablehq:mainfrom
nikhilsinhaparseable:fix/query-memory-admission

Conversation

@nikhilsinhaparseable

@nikhilsinhaparseable nikhilsinhaparseable commented Dec 6, 2026 •

Copy link
Copy Markdown
Member
  • add query admission control with a default limit of 5 concurrent queries with env P_MAX_CONCURRENT_QUERIES
  • queue additional queries until a slot becomes available
  • use DataFusion’s FairSpillPool for fairer memory allocation between concurrent queries
  • retry a non-streaming query once with exclusive access when it fails due to memory exhaustion or server memory pressure
  • cancel query execution promptly when the client disconnect
  • resume queued queries after memory falls below 90% of that threshold
  • purge jemalloc arenas after memory-pressure cancellation to return memory faster
  • improve memory-exhaustion diagnostics by reporting DataFusion’s largest consumers

Confidence Score: 5/5RetriggerView in Greptile

The PR appears safe to merge; the previous Flight cancellation issue is addressed.

Summary

Adds query limits, bounded streaming buffers, fair memory sharing, and one exclusive retry after a non-streaming query runs out of memory.

  • Query requests share a memory-aware limit on concurrent execution.
  • Query parallelism and batch size now follow available memory.
  • Nested COUNT aliases now use the fast count path.
  • Build and TLS settings change without changing server behavior.

Diagram

%%{init: {'theme': 'neutral', 'htmlLabels': false}}%%
flowchart TD
  A[Query request] --> B[Wait for query slot and memory]
  B --> C[Execute query]
  C --> D{Batch query runs out of memory?}
  D -->|Yes, first attempt| E[Wait for every query slot]
  E --> C
  D -->|No| F[Return results with query guard]
  F --> G{Flight response?}
  G -->|Yes| H[Stop memory-pressure monitor]
  G -->|No| I[Serialize or stream results]
  H --> I
  I --> J[Drop guard and release query slots]
Loading

Reviews (3) · Last reviewed commit: "fix review comments" · Reviewed by Greptile

Bound the default DataFusion memory pool and concurrent query admission using detected cgroup memory. Queue requests for up to ten seconds when all admission slots are busy, and retain permits until streaming queries finish or are cancelled.\n\nUse memory-aware partition defaults and smaller execution batches so constrained deployments reject oversized queries cleanly instead of exhausting the server.
Comment thread src/query/mod.rs Resolved
Comment thread src/query/mod.rs Resolved
Comment thread src/handlers/airplane.rs Resolved
Comment thread src/handlers/airplane.rs Resolved

This branch has not been deployed

No deployments
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.

1 participant