Skip to content
Open
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
3 changes: 3 additions & 0 deletions lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,9 @@ Optimizations
fewer radix passes. This speeds up DocIdSetBuilder, e.g. for range queries on fields whose values
follow doc ID order such as timestamps or index sort fields. (Asharam)

* GITHUB#16306: Reduce lock contention in UsageTrackingQueryCachingPolicy by splitting its usage
history into small per-lock ring buffers with lock-free reads. (prudhvigodithi)

Bug Fixes
---------------------
* GITHUB#17020: Reduce CachingTokenFilter memory use by not copying stale term bytes in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.apache.lucene.search;

import java.io.IOException;
import org.apache.lucene.util.FrequencyTrackingRingBuffer;
import org.apache.lucene.util.StripedFrequencyTracker;

/**
* A {@link QueryCachingPolicy} that tracks usage statistics of recently-used filters in order to
Expand Down Expand Up @@ -90,7 +90,11 @@ private static boolean shouldNeverCache(Query query) {
return false;
}

private final FrequencyTrackingRingBuffer recentlyUsedFilters;
/**
* Recently used hash codes. The history is striped so that concurrent searches on different
* queries do not contend on a single lock, see {@link StripedFrequencyTracker}.
*/
private final StripedFrequencyTracker recentlyUsedFilters;

/**
* Expert: Create a new instance with a configurable history size. Beware of passing too large
Expand All @@ -99,10 +103,14 @@ private static boolean shouldNeverCache(Query query) {
* {@link #minFrequencyToCache} returns high values that are function of the size of the history
* but then filters will be slow to make it to the cache.
*
* <p>Internally the history is split into stripes of 32 to 64 entries (a single stripe is used
* for histories smaller than 64), and a query only competes for history slots with the queries of
* its own stripe. The default history of 256 is split into 8 stripes.
*
* @param historySize the number of recently used filters to track
*/
public UsageTrackingQueryCachingPolicy(int historySize) {
this.recentlyUsedFilters = new FrequencyTrackingRingBuffer(historySize, SENTINEL);
this.recentlyUsedFilters = new StripedFrequencyTracker(historySize, SENTINEL);
}

/**
Expand Down Expand Up @@ -146,29 +154,19 @@ public void onUse(Query query) {
return;
}

// call hashCode outside of sync block
// in case it's somewhat expensive:
int hashCode = query.hashCode();

// we only track hash codes to avoid holding references to possible
// large queries; this may cause rare false positives, but at worse
// this just means we cache a query that was not in fact used enough:
synchronized (this) {
recentlyUsedFilters.add(hashCode);
}
final int hashCode = query.hashCode();
recentlyUsedFilters.add(hashCode);
}

int frequency(Query query) {
assert query instanceof BoostQuery == false;
assert query instanceof ConstantScoreQuery == false;

// call hashCode outside of sync block
// in case it's somewhat expensive:
int hashCode = query.hashCode();

synchronized (this) {
return recentlyUsedFilters.frequency(hashCode);
}
final int hashCode = query.hashCode();
return recentlyUsedFilters.frequency(hashCode);
}

@Override
Expand Down

This file was deleted.

Loading
Loading