Skip to content

Disable the query cache by default. #14187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ Bug Fixes

* GITHUB#14075: Remove duplicate and add missing entry on brazilian portuguese stopwords list. (Arthur Caccavo)

Changes in Runtime Behavior
---------------------
* GITHUB#14187: The query cache is now disabled by default. (Adrien Grand)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a sentence about how to opt-in? Something like "call IndexSearcher.setQueryCache(new LRUQueryCache(1000, maxRamBytesUsed)) to get back to 10.x behavior" or so? Or maybe add these details to MIGRATE.md` instead?


Other
---------------------

Expand Down
11 changes: 11 additions & 0 deletions lucene/MIGRATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@
This parameter has no replacement, TieredMergePolicy no longer bounds the
number of segments that may be merged together.

### Query caching is now disabled by default

Query caching is now disabled by default. To enable caching back, do something
like below in a static initialization block:

```
int maxCachedQueries = 1_000;
long maxRamBytesUsed = 50 * 1024 * 1024; // 50MB
IndexSearcher.setDefaultQueryCache(new LRUQueryCache(maxCachedQueries, maxRamBytesUsed));
```

## Migration from Lucene 9.x to Lucene 10.0

### DataInput#readVLong() may now read negative vlongs
Expand Down
10 changes: 2 additions & 8 deletions lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ public class IndexSearcher {
@SuppressWarnings("NonFinalStaticField")
static int maxClauseCount = 1024;

// Caching is disabled by default.
@SuppressWarnings("NonFinalStaticField")
private static QueryCache DEFAULT_QUERY_CACHE;
private static QueryCache DEFAULT_QUERY_CACHE = null;

@SuppressWarnings("NonFinalStaticField")
private static QueryCachingPolicy DEFAULT_CACHING_POLICY = new UsageTrackingQueryCachingPolicy();
Expand All @@ -92,13 +93,6 @@ public class IndexSearcher {
// shouldn't hurt either.
private volatile boolean partialResult = false;

static {
final int maxCachedQueries = 1000;
// min of 32MB or 5% of the heap size
final long maxRamBytesUsed = Math.min(1L << 25, Runtime.getRuntime().maxMemory() / 20);
DEFAULT_QUERY_CACHE = new LRUQueryCache(maxCachedQueries, maxRamBytesUsed);
}

/**
* By default, we count hits accurately up to 1000. This makes sure that we don't spend most time
* on computing hit counts
Expand Down