Skip to content

feat(config): add query_cache_memory_limit and query_cache_ttl#1266

Open
IgorOhrimenko wants to merge 1 commit into
pgdogdev:mainfrom
IgorOhrimenko:query-cache-memory-limit-ttl
Open

feat(config): add query_cache_memory_limit and query_cache_ttl#1266
IgorOhrimenko wants to merge 1 commit into
pgdogdev:mainfrom
IgorOhrimenko:query-cache-memory-limit-ttl

Conversation

@IgorOhrimenko

Copy link
Copy Markdown

Implements the memory-based cache limit and idle expiry proposed in #1261.

Adds two [general] options (also PGDOG_QUERY_CACHE_MEMORY_LIMIT / PGDOG_QUERY_CACHE_TTL env), both default 0 (off):

  • query_cache_memory_limit (bytes): evict LRU until the summed entry size is under the budget. query_cache_limit bounds the number of entries but not their memory — a parsed tree for a wide/complex query is orders of magnitude larger than for SELECT 1, so a count-based cap alone can't bound RAM. Entry size is measured via jemalloc's per-thread allocation counters (clamped to 0, since cross-thread frees under a work-stealing runtime can make the delta negative); falls back to the query text length on non-jemalloc builds.
  • query_cache_ttl (seconds, time-to-idle): entries not accessed within the window are dropped by the existing 1s maintenance sweep, releasing an idle working set without waiting for LRU eviction.

Both are opt-in (0 = off); default behaviour is unchanged. Unit tests cover count/byte eviction, byte accounting and the TTL sweep; config parsing is covered in pgdog-config. JSON schema regenerated.

Closes #1261.

The AST query cache was bounded only by entry count (query_cache_limit),
not by memory, and had no idle expiry. Heavy/complex queries produce large
parse trees, so a full cache can hold GBs of live RSS that only drop once
1000 newer distinct queries evict them (or on RESET/restart).

Adds two [general] options (also PGDOG_QUERY_CACHE_MEMORY_LIMIT /
PGDOG_QUERY_CACHE_TTL env), both default 0 (off):

- query_cache_memory_limit: evict LRU until the summed entry size is under
  the byte budget. Entry size is measured via jemalloc per-thread allocation
  counters (clamped to 0, since cross-thread frees under a work-stealing
  runtime can make the delta negative); falls back to query length on
  non-jemalloc builds.
- query_cache_ttl: drop entries not accessed within the window, via the
  existing 1s maintenance sweep.

Refs pgdogdev#1261.
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.

Query cache (query_cache_limit) is bounded by entry count, not memory, and has no TTL — heavy queries balloon RSS until restart

1 participant