cpoerschke commented on code in PR #1905:
URL: https://github.com/apache/solr/pull/1905#discussion_r1320175584


##########
solr/core/src/java/org/apache/solr/util/circuitbreaker/MemoryCircuitBreaker.java:
##########
@@ -43,8 +46,34 @@ public class MemoryCircuitBreaker extends CircuitBreaker {
   private static final ThreadLocal<Long> seenMemory = 
ThreadLocal.withInitial(() -> 0L);
   private static final ThreadLocal<Long> allowedMemory = 
ThreadLocal.withInitial(() -> 0L);
 
+  /** Creates an instance which averages over 6 samples during last 30 
seconds. */
   public MemoryCircuitBreaker() {
+    this(6, 5);
+  }
+
+  /**
+   * Constructor that allows override of sample interval for which the memory 
usage is fetched. This
+   * is provided for testing, not intended for general use.
+   *
+   * @param numSamples number of samples to calculate average for
+   * @param sampleInterval interval between each sample
+   */
+  protected MemoryCircuitBreaker(int numSamples, int sampleInterval) {
     super();
+    if (averagingMetricProvider == null || 
averagingMetricProvider.getRefcount() == 0) {
+      averagingMetricProvider =

Review Comment:
   No worries, I haven't yet used the `RefCounted` API either, perhaps 
something for me to learn about next week.
   
   As an aside, just noticed the TODO in the `isTripped()` comments below and 
it sounds like the changes in this PR will have an effect similar to what is 
described there, maybe.



-- 
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: issues-unsubscr...@solr.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to