You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
perf(ingester): lazy regex evaluation on head postings cache miss (#7553)
* perf(ingester): lazy regex evaluation on head postings cache miss
When the expanded postings cache misses on the head block, regex matchers
on high-cardinality labels (e.g. pod with 400K+ values) dominate query
cost. This PR defers expensive regex matchers to a lazy per-series
evaluation when a selective equality matcher already narrows the result
set significantly.
On cache miss, splitMatchersForHeadWithConfig splits matchers into:
- Selective matchers (equality, low-card regex) for postings lookup
- Lazy matchers (high-card regex) applied per-series via LabelValueFor
A cost-ratio gate decides when deferral is worthwhile:
- Simple regex (single contains, prefix): cardinality > selectivePostings * 6
- Complex regex (multi-substring, capture groups): cardinality > selectivePostings * 2
Label cardinality lookups are cached in an expirable LRU (60s TTL) to
avoid repeated LabelValues calls under load.
Benchmark (realistic pod names, 413K cardinality, 9K selective postings):
- Eager: 62ms, 29.8MB per query
- Lazy: 14ms, 12.6MB per query (4.5x faster, 58% less memory)
New flags (disabled by default with max-cardinality=0):
- blocks-storage.expanded_postings_cache.head.lazy-matcher-max-cardinality
- blocks-storage.expanded_postings_cache.head.lazy-matcher-simple-cost-ratio
- blocks-storage.expanded_postings_cache.head.lazy-matcher-complex-cost-ratio
* Update pkg/storage/tsdb/expanded_postings_cache.go
Co-authored-by: SungJin1212 <tjdwls1201@gmail.com>
Signed-off-by: Alan Protasio <alanprot@gmail.com>
* address review: mark flags experimental, use errors.Is, add error propagation test
- Mark all lazy-matcher flags as [EXPERIMENTAL] per v1 guarantee
- Use errors.Is(err, storage.ErrNotFound) instead of direct comparison
- Propagate non-ErrNotFound errors from LabelValueFor
- Add TestFetchWithLazyMatchers_PropagatesLabelValueForError
- Skip SetMatches matchers from lazy candidates (already fast-pathed)
- Remove dead SetMatches check from regexCostClass
- Regenerate docs and schema
---------
Signed-off-by: Alan Protasio <alanprot@gmail.com>
Signed-off-by: Alan Protasio <approtas@amazon.com>
Co-authored-by: SungJin1212 <tjdwls1201@gmail.com>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,9 @@
28
28
*[ENHANCEMENT] Instrument Ingester CPU profile with source for read APIs. #7494
29
29
*[ENHANCEMENT] Ingester: Convert expanded postings cache from FIFO to LRU eviction to retain frequently-queried entries under memory pressure. #7510
30
30
*[ENHANCEMENT] Querier: Detach series label and chunk data from gRPC unmarshal buffers in store-gateway streaming path, allowing the Go GC to reclaim receive buffers. #7519
31
+
31
32
*[ENHANCEMENT] Distributor: Add `WrappedHistogram` with configurable size limit (`-validation.max-native-histogram-size-bytes`) to cap native histogram protobuf size before unmarshalling. #7570
33
+
*[ENHANCEMENT] Ingester: Add lazy regex evaluation on head postings cache miss. Defers expensive regex matchers on high-cardinality labels to per-series filtering when a selective equality matcher already narrows the result set. Configured via `-blocks-storage.expanded_postings_cache.head.lazy-matcher-max-cardinality` (disabled by default). #7553
32
34
*[BUGFIX] Querier: Fix queryWithRetry and labelsWithRetry returning (nil, nil) on cancelled context by propagating ctx.Err(). #7370
33
35
*[BUGFIX] Metrics Helper: Fix non-deterministic bucket order in merged histograms by sorting buckets after map iteration, matching Prometheus client library behavior. #7380
34
36
*[BUGFIX] Distributor: Return HTTP 401 Unauthorized when tenant ID resolution fails in the Prometheus Remote Write 2.0 path. #7389
0 commit comments