sgup432 commented on code in PR #16306:
URL: https://github.com/apache/lucene/pull/16306#discussion_r4684411892


##########
lucene/core/src/java/org/apache/lucene/search/UsageTrackingQueryCachingPolicy.java:
##########
@@ -99,10 +119,28 @@ 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 16 to 31 entries (a 
single stripe is used
+   * for histories smaller than 32), and a query only competes for history 
slots with the queries of
+   * its own stripe. The default history of 256 is split into 16 stripes.

Review Comment:
   I wonder if we could increase the default history size of 256 now as it 
looks small to me especially with the workloads with many unique queries. Do 
you see any benefits of increasing?



##########
lucene/core/src/java/org/apache/lucene/search/UsageTrackingQueryCachingPolicy.java:
##########
@@ -90,7 +90,27 @@ private static boolean shouldNeverCache(Query query) {
     return false;
   }
 
-  private final FrequencyTrackingRingBuffer recentlyUsedFilters;
+  /**
+   * Maximum number of stripes the usage history is split into. Stripes are 
sized so that they hold
+   * between {@link #MIN_HISTORY_PER_STRIPE} and twice as many entries, which 
keeps the linear scan
+   * in {@link Stripe#frequency} short for any history size up to {@code 
MAX_STRIPES * 32}.
+   */
+  private static final int MAX_STRIPES = 1024;
+
+  /**
+   * Minimum number of entries per stripe. A query can never appear more often 
in its stripe than
+   * the stripe has entries, so this must stay comfortably above {@link 
#minFrequencyToCache}.
+   */
+  private static final int MIN_HISTORY_PER_STRIPE = 16;

Review Comment:
   While using 16 stripes does reduce lock contention, is it possible that one 
hot query starve other queries(as they may never get to 5 frequency) mapping to 
same strip? This might reduce query admissions in certain cases.



##########
lucene/core/src/java/org/apache/lucene/search/UsageTrackingQueryCachingPolicy.java:
##########
@@ -99,10 +119,28 @@ 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 16 to 31 entries (a 
single stripe is used
+   * for histories smaller than 32), and a query only competes for history 
slots with the queries of
+   * its own stripe. The default history of 256 is split into 16 stripes.
+   *
    * @param historySize the number of recently used filters to track
    */
   public UsageTrackingQueryCachingPolicy(int historySize) {
-    this.recentlyUsedFilters = new FrequencyTrackingRingBuffer(historySize, 
SENTINEL);
+    if (historySize < 2) {
+      throw new IllegalArgumentException("historySize must be at least 2, got: 
" + historySize);
+    }
+    int numStripes = 1;

Review Comment:
   Is it possible to decouple the stripe logic like we had for frequency 
tracker? Also make it implement Accountable?
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to