feat(config): add query_cache_memory_limit and query_cache_ttl#1266
Open
IgorOhrimenko wants to merge 1 commit into
Open
feat(config): add query_cache_memory_limit and query_cache_ttl#1266IgorOhrimenko wants to merge 1 commit into
IgorOhrimenko wants to merge 1 commit into
Conversation
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.
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.
Implements the memory-based cache limit and idle expiry proposed in #1261.
Adds two
[general]options (alsoPGDOG_QUERY_CACHE_MEMORY_LIMIT/PGDOG_QUERY_CACHE_TTLenv), both default0(off):query_cache_memory_limit(bytes): evict LRU until the summed entry size is under the budget.query_cache_limitbounds the number of entries but not their memory — a parsed tree for a wide/complex query is orders of magnitude larger than forSELECT 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 inpgdog-config. JSON schema regenerated.Closes #1261.