LRUQueryCache should not count never-cacheable queries as a miss [LUCENE-10235]
- Dominant language
- Java
- Stars
- 3.6k
- Forks
- 1.4k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 88
Description
Hit and miss counts of a cache are typically used to check how effective a caching layer is. While looking at a system that exhibited a very high miss to hit ratio, I took a closer look at Lucene's LRUQueryCache and noticed that it's treating the handling of queries as a miss that it would never ever even think about caching in the first place. (e.g. TermQuery and others mentioned in UsageTrackingQueryCachingPolicy.shouldNeverCache).
The reason these are counted as a miss is that LRUQueryCache (scorerSupplier and bulkScorer methods) first does a lookup on the cache, incrementing hit or miss counters, and upon miss, only then checks QueryCachingPolicy.shouldCache to decide whether that query should be put into the cache.
This issue is made more complex by the fact that QueryCachingPolicy.shouldCache is a stateful method, and cacheability of a query can change over time (e.g. after appearing N times).
I'm opening this issue to discuss whether others also feel that the current way of accounting misses is unintuitive / confusing. I would also like to put forward a proposal to:
- generalize the boolean QueryCachingPolicy.shouldCache method to return an enum instead (one of YES, NOT_RIGHT_NOW, NEVER), and only account queries that are (eventually) cacheable and not in the cache as a miss,
- optionally introduce another metric for queries that are never cacheable, e.g. "ignored", and
- optionally refine miss count into a count for items that are cacheable right away, and those that will eventually be cacheable.
---
Migrated from [LUCENE-10235](https://issues.apache.org/jira/browse/LUCENE-10235) by Yannick Welsch (@ywelsch), updated Nov 24 2021
Contributor guide
Research direction
Review LRUQueryCache.scorerSupplier and bulkScorer alongside QueryCachingPolicy.shouldCache and UsageTrackingQueryCachingPolicy.shouldNeverCache. First resolve the proposed semantics for cache misses, never-cacheable queries, and changing cacheability; done requires an agreed behavior and corresponding accounting design.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- search
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100