You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by at...@apache.org on 2020/06/25 15:36:33 UTC

[lucene-solr] branch master updated: SOLR-14588: Implement Circuit Breakers (#1606)

This is an automated email from the ASF dual-hosted git repository.

atri pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/master by this push:
     new 7b54902  SOLR-14588: Implement Circuit Breakers (#1606)
7b54902 is described below

commit 7b54902f681542ae49293df9bc9e5ac1694d465c
Author: Atri Sharma <at...@gmail.com>
AuthorDate: Thu Jun 25 21:06:22 2020 +0530

    SOLR-14588: Implement Circuit Breakers (#1606)
    
    * SOLR-14588: Implement Circuit Breakers
    
    This commit consists of two parts: initial circuit breakers infrastructure and real JVM memory based
    circuit breaker which monitors incoming search requests and rejects them with SERVICE_TOO_BUSY error
    if the defined threshold is breached, thus giving headroom to existing indexing and search requests
    to complete.
---
 .../solr/collection1/conf/solrconfig.xml           |  11 ++
 .../solr/collection1/conf/solrconfig.xml           |   4 +
 .../src/java/org/apache/solr/core/SolrConfig.java  |  19 +++
 .../src/java/org/apache/solr/core/SolrCore.java    |  16 +-
 .../solr/handler/component/SearchHandler.java      |  31 +++-
 .../solr/util/circuitbreaker/CircuitBreaker.java   |  51 ++++++
 .../util/circuitbreaker/CircuitBreakerManager.java | 105 ++++++++++++
 .../util/circuitbreaker/CircuitBreakerType.java    |  26 +++
 .../util/circuitbreaker/MemoryCircuitBreaker.java  |  87 ++++++++++
 .../resources/EditableSolrConfigAttributes.json    |   2 +
 .../conf/solrconfig-cache-enable-disable.xml       |   4 +
 .../solr/collection1/conf/solrconfig-elevate.xml   |   4 +
 .../conf/solrconfig-implicitproperties.xml         |   2 +
 ...le.xml => solrconfig-memory-circuitbreaker.xml} |  15 +-
 .../conf/solrconfig-sortingresponse.xml            |   4 +
 .../solr/collection1/conf/solrconfig.xml           |  10 ++
 .../solr/collection1/conf/solrconfig_perf.xml      |   2 +
 .../test/org/apache/solr/core/SolrCoreTest.java    |   2 +
 .../org/apache/solr/core/TestConfigOverlay.java    |   2 +
 .../org/apache/solr/util/TestCircuitBreaker.java   | 190 +++++++++++++++++++++
 .../example-DIH/solr/db/conf/solrconfig.xml        |  10 ++
 .../example-DIH/solr/mail/conf/solrconfig.xml      |  10 ++
 .../example-DIH/solr/solr/conf/solrconfig.xml      |  10 ++
 solr/example/files/conf/solrconfig.xml             |  10 ++
 .../solr/configsets/_default/conf/solrconfig.xml   |  10 ++
 .../conf/solrconfig.xml                            |  10 ++
 solr/solr-ref-guide/src/config-api.adoc            |   4 +
 .../src/query-settings-in-solrconfig.adoc          |  18 ++
 28 files changed, 660 insertions(+), 9 deletions(-)

diff --git a/solr/contrib/clustering/src/test-files/clustering/solr/collection1/conf/solrconfig.xml b/solr/contrib/clustering/src/test-files/clustering/solr/collection1/conf/solrconfig.xml
index e8bc13a..5256eed 100644
--- a/solr/contrib/clustering/src/test-files/clustering/solr/collection1/conf/solrconfig.xml
+++ b/solr/contrib/clustering/src/test-files/clustering/solr/collection1/conf/solrconfig.xml
@@ -123,6 +123,17 @@
          The purpose is to enable easy caching of user/application level data.
          The regenerator argument should be specified as an implementation
          of solr.search.CacheRegenerator if autowarming is desired.  -->
+
+    <!-- Enable Circuit Breakers
+  -->
+    <useCircuitBreakers>false</useCircuitBreakers>
+
+    <!-- Memory Circuit Breaker Threshold In Percentage
+
+    Post this percentage usage of the heap, incoming queries will be rejected
+      -->
+    <memoryCircuitBreakerThreshold>100</memoryCircuitBreakerThreshold>
+
     <!--
     <cache name="myUserCache"
       class="solr.CaffeineCache"
diff --git a/solr/contrib/prometheus-exporter/src/test-files/solr/collection1/conf/solrconfig.xml b/solr/contrib/prometheus-exporter/src/test-files/solr/collection1/conf/solrconfig.xml
index 31902a3..500e8f0 100644
--- a/solr/contrib/prometheus-exporter/src/test-files/solr/collection1/conf/solrconfig.xml
+++ b/solr/contrib/prometheus-exporter/src/test-files/solr/collection1/conf/solrconfig.xml
@@ -83,6 +83,10 @@
 
     <queryResultMaxDocsCached>200</queryResultMaxDocsCached>
 
+    <useCircuitBreakers>false</useCircuitBreakers>
+
+    <memoryCircuitBreakerThreshold>100</memoryCircuitBreakerThreshold>
+
     <listener event="newSearcher" class="solr.QuerySenderListener">
       <arr name="queries">
       </arr>
diff --git a/solr/core/src/java/org/apache/solr/core/SolrConfig.java b/solr/core/src/java/org/apache/solr/core/SolrConfig.java
index bd0c45d..928a25c 100644
--- a/solr/core/src/java/org/apache/solr/core/SolrConfig.java
+++ b/solr/core/src/java/org/apache/solr/core/SolrConfig.java
@@ -224,6 +224,11 @@ public class SolrConfig extends XmlConfigFile implements MapSerializable {
     queryResultWindowSize = Math.max(1, getInt("query/queryResultWindowSize", 1));
     queryResultMaxDocsCached = getInt("query/queryResultMaxDocsCached", Integer.MAX_VALUE);
     enableLazyFieldLoading = getBool("query/enableLazyFieldLoading", false);
+
+    useCircuitBreakers = getBool("query/useCircuitBreakers", false);
+    memoryCircuitBreakerThreshold = getInt("query/memoryCircuitBreakerThreshold", 100);
+
+    validateMemoryBreakerThreshold();
     
     useRangeVersionsForPeerSync = getBool("peerSync/useRangeVersions", true);
 
@@ -522,6 +527,10 @@ public class SolrConfig extends XmlConfigFile implements MapSerializable {
   public final int queryResultWindowSize;
   public final int queryResultMaxDocsCached;
   public final boolean enableLazyFieldLoading;
+
+  // Circuit Breaker Configuration
+  public final boolean useCircuitBreakers;
+  public final int memoryCircuitBreakerThreshold;
   
   public final boolean useRangeVersionsForPeerSync;
   
@@ -804,6 +813,14 @@ public class SolrConfig extends XmlConfigFile implements MapSerializable {
     loader.reloadLuceneSPI();
   }
 
+  private void validateMemoryBreakerThreshold() {
+    if (useCircuitBreakers) {
+      if (memoryCircuitBreakerThreshold > 100 || memoryCircuitBreakerThreshold < 0) {
+        throw new IllegalArgumentException("memoryCircuitBreakerThreshold is not a valid percentage");
+      }
+    }
+  }
+
   public int getMultipartUploadLimitKB() {
     return multipartUploadLimitKB;
   }
@@ -873,6 +890,8 @@ public class SolrConfig extends XmlConfigFile implements MapSerializable {
     m.put("queryResultMaxDocsCached", queryResultMaxDocsCached);
     m.put("enableLazyFieldLoading", enableLazyFieldLoading);
     m.put("maxBooleanClauses", booleanQueryMaxClauseCount);
+    m.put("useCircuitBreakers", useCircuitBreakers);
+    m.put("memoryCircuitBreakerThreshold", memoryCircuitBreakerThreshold);
     for (SolrPluginInfo plugin : plugins) {
       List<PluginInfo> infos = getPluginInfos(plugin.clazz.getName());
       if (infos == null || infos.isEmpty()) continue;
diff --git a/solr/core/src/java/org/apache/solr/core/SolrCore.java b/solr/core/src/java/org/apache/solr/core/SolrCore.java
index 9b635e4..2a0c57a 100644
--- a/solr/core/src/java/org/apache/solr/core/SolrCore.java
+++ b/solr/core/src/java/org/apache/solr/core/SolrCore.java
@@ -94,6 +94,7 @@ import org.apache.solr.common.util.IOUtils;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.common.util.ObjectReleaseTracker;
 import org.apache.solr.common.util.SimpleOrderedMap;
+import org.apache.solr.common.util.SolrNamedThreadFactory;
 import org.apache.solr.common.util.Utils;
 import org.apache.solr.core.DirectoryFactory.DirContext;
 import org.apache.solr.core.snapshots.SolrSnapshotManager;
@@ -157,13 +158,13 @@ import org.apache.solr.update.processor.RunUpdateProcessorFactory;
 import org.apache.solr.update.processor.UpdateRequestProcessorChain;
 import org.apache.solr.update.processor.UpdateRequestProcessorChain.ProcessorInfo;
 import org.apache.solr.update.processor.UpdateRequestProcessorFactory;
-import org.apache.solr.common.util.SolrNamedThreadFactory;
 import org.apache.solr.util.IOFunction;
 import org.apache.solr.util.NumberUtils;
 import org.apache.solr.util.PropertiesInputStream;
 import org.apache.solr.util.PropertiesOutputStream;
 import org.apache.solr.util.RefCounted;
 import org.apache.solr.util.TestInjection;
+import org.apache.solr.util.circuitbreaker.CircuitBreakerManager;
 import org.apache.solr.util.plugin.NamedListInitializedPlugin;
 import org.apache.solr.util.plugin.PluginInfoInitialized;
 import org.apache.solr.util.plugin.SolrCoreAware;
@@ -219,6 +220,8 @@ public final class SolrCore implements SolrInfoBean, Closeable {
   private final Codec codec;
   private final MemClassLoader memClassLoader;
 
+  private final CircuitBreakerManager circuitBreakerManager;
+
   private final List<Runnable> confListeners = new CopyOnWriteArrayList<>();
 
   private final ReentrantLock ruleExpiryLock;
@@ -938,6 +941,7 @@ public final class SolrCore implements SolrInfoBean, Closeable {
       this.configSetProperties = configSet.getProperties();
       // Initialize the metrics manager
       this.coreMetricManager = initCoreMetricManager(solrConfig);
+      this.circuitBreakerManager = initCircuitBreakerManager();
       solrMetricsContext = coreMetricManager.getSolrMetricsContext();
       this.coreMetricManager.loadReporters();
 
@@ -1164,6 +1168,12 @@ public final class SolrCore implements SolrInfoBean, Closeable {
     return coreMetricManager;
   }
 
+  private CircuitBreakerManager initCircuitBreakerManager() {
+    CircuitBreakerManager circuitBreakerManager = CircuitBreakerManager.buildDefaultCircuitBreakerManager(this);
+
+    return circuitBreakerManager;
+  }
+
   @Override
   public void initializeMetrics(SolrMetricsContext parentContext, String scope) {
     newSearcherCounter = parentContext.counter("new", Category.SEARCHER.toString());
@@ -1499,6 +1509,10 @@ public final class SolrCore implements SolrInfoBean, Closeable {
     return updateProcessors;
   }
 
+  public CircuitBreakerManager getCircuitBreakerManager() {
+    return circuitBreakerManager;
+  }
+
   // this core current usage count
   private final AtomicInteger refCount = new AtomicInteger(1);
 
diff --git a/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java b/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java
index 2051b20..9b49f3f 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java
@@ -23,6 +23,7 @@ import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import org.apache.lucene.index.ExitableDirectoryReader;
@@ -51,13 +52,18 @@ import org.apache.solr.security.AuthorizationContext;
 import org.apache.solr.security.PermissionNameProvider;
 import org.apache.solr.util.RTimerTree;
 import org.apache.solr.util.SolrPluginUtils;
+import org.apache.solr.util.circuitbreaker.CircuitBreaker;
+import org.apache.solr.util.circuitbreaker.CircuitBreakerManager;
+import org.apache.solr.util.circuitbreaker.CircuitBreakerType;
 import org.apache.solr.util.plugin.PluginInfoInitialized;
 import org.apache.solr.util.plugin.SolrCoreAware;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import static org.apache.solr.common.params.CommonParams.DISTRIB;
+import static org.apache.solr.common.params.CommonParams.FAILURE;
 import static org.apache.solr.common.params.CommonParams.PATH;
+import static org.apache.solr.common.params.CommonParams.STATUS;
 
 
 /**
@@ -297,6 +303,29 @@ public class SearchHandler extends RequestHandlerBase implements SolrCoreAware,
 
     final RTimerTree timer = rb.isDebug() ? req.getRequestTimer() : null;
 
+    Map<CircuitBreakerType, CircuitBreaker> trippedCircuitBreakers;
+
+    if (timer != null) {
+      RTimerTree subt = timer.sub("circuitbreaker");
+      rb.setTimer(subt.sub("circuitbreaker"));
+
+      CircuitBreakerManager circuitBreakerManager = req.getCore().getCircuitBreakerManager();
+      trippedCircuitBreakers = circuitBreakerManager.checkAllCircuitBreakers();
+
+      rb.getTimer().stop();
+      subt.stop();
+    } else {
+      CircuitBreakerManager circuitBreakerManager = req.getCore().getCircuitBreakerManager();
+      trippedCircuitBreakers = circuitBreakerManager.checkAllCircuitBreakers();
+    }
+
+    if (trippedCircuitBreakers != null) {
+      String errorMessage = CircuitBreakerManager.constructFinalErrorMessageString(trippedCircuitBreakers);
+      rsp.add(STATUS, FAILURE);
+      rsp.setException(new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE, "Circuit Breakers tripped " + errorMessage));
+      return;
+    }
+
     final ShardHandler shardHandler1 = getAndPrepShardHandler(req, rb); // creates a ShardHandler object only if it's needed
     
     if (timer == null) {
@@ -308,7 +337,7 @@ public class SearchHandler extends RequestHandlerBase implements SolrCoreAware,
       // debugging prepare phase
       RTimerTree subt = timer.sub( "prepare" );
       for( SearchComponent c : components ) {
-        rb.setTimer( subt.sub( c.getName() ) );
+        rb.setTimer(subt.sub( c.getName() ) );
         c.prepare(rb);
         rb.getTimer().stop();
       }
diff --git a/solr/core/src/java/org/apache/solr/util/circuitbreaker/CircuitBreaker.java b/solr/core/src/java/org/apache/solr/util/circuitbreaker/CircuitBreaker.java
new file mode 100644
index 0000000..2e7de82
--- /dev/null
+++ b/solr/core/src/java/org/apache/solr/util/circuitbreaker/CircuitBreaker.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.util.circuitbreaker;
+
+import org.apache.solr.core.SolrCore;
+
+/**
+ * Default class to define circuit breakers for Solr.
+ *
+ * TODO: This class should be grown as the scope of circuit breakers grow.
+ */
+public abstract class CircuitBreaker {
+  public static final String NAME = "circuitbreaker";
+
+  protected final SolrCore solrCore;
+
+  public CircuitBreaker(SolrCore solrCore) {
+    this.solrCore = solrCore;
+  }
+
+  // Global config for all circuit breakers. For specific circuit breaker configs, define
+  // your own config
+  protected boolean isCircuitBreakerEnabled() {
+    return solrCore.getSolrConfig().useCircuitBreakers;
+  }
+
+  /**
+   * Check if this allocation will trigger circuit breaker.
+   */
+  public abstract boolean isCircuitBreakerGauntletTripped();
+
+  /**
+   * Print debug useful info
+   */
+  public abstract String printDebugInfo();
+}
diff --git a/solr/core/src/java/org/apache/solr/util/circuitbreaker/CircuitBreakerManager.java b/solr/core/src/java/org/apache/solr/util/circuitbreaker/CircuitBreakerManager.java
new file mode 100644
index 0000000..20f45e7
--- /dev/null
+++ b/solr/core/src/java/org/apache/solr/util/circuitbreaker/CircuitBreakerManager.java
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.util.circuitbreaker;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.solr.core.SolrCore;
+
+/**
+ * Manages all registered circuit breaker instances. Responsible for a holistic view
+ * of whether a circuit breaker has tripped or not.
+ *
+ * There are two typical ways of using this class's instance:
+ * 1. Check if any circuit breaker has triggered -- and know which circuit breaker has triggered.
+ * 2. Get an instance of a specific circuit breaker and perform checks.
+ *
+ * It is a good practice to register new circuit breakers here if you want them checked for every
+ * request.
+ *
+ * NOTE: The current way of registering new default circuit breakers is minimal and not a long term
+ * solution. There will be a follow up with a SIP for a schema API design.
+ */
+public class CircuitBreakerManager {
+
+  private final Map<CircuitBreakerType, CircuitBreaker> circuitBreakerMap = new HashMap<>();
+
+  // Allows replacing of existing circuit breaker
+  public void registerCircuitBreaker(CircuitBreakerType circuitBreakerType, CircuitBreaker circuitBreaker) {
+    circuitBreakerMap.put(circuitBreakerType, circuitBreaker);
+  }
+
+  public CircuitBreaker getCircuitBreaker(CircuitBreakerType circuitBreakerType) {
+    assert circuitBreakerType != null;
+
+    return circuitBreakerMap.get(circuitBreakerType);
+  }
+
+  /**
+   * Check if any circuit breaker has triggered.
+   * @return CircuitBreakers which have triggered, null otherwise
+   */
+  public Map<CircuitBreakerType, CircuitBreaker> checkAllCircuitBreakers() {
+    Map<CircuitBreakerType, CircuitBreaker> triggeredCircuitBreakers = new HashMap<>();
+
+    for (Map.Entry<CircuitBreakerType, CircuitBreaker> entry : circuitBreakerMap.entrySet()) {
+      CircuitBreaker circuitBreaker = entry.getValue();
+
+      if (circuitBreaker.isCircuitBreakerEnabled() &&
+          circuitBreaker.isCircuitBreakerGauntletTripped()) {
+        triggeredCircuitBreakers.put(entry.getKey(), circuitBreaker);
+      }
+    }
+
+    return triggeredCircuitBreakers.size() > 0 ? triggeredCircuitBreakers : null;
+  }
+
+  /**
+   * Construct the final error message to be printed when circuit breakers trip
+   * @param circuitBreakerMap Input list for circuit breakers
+   * @return Constructed error message
+   */
+  public static String constructFinalErrorMessageString(Map<CircuitBreakerType, CircuitBreaker> circuitBreakerMap) {
+    assert circuitBreakerMap != null;
+
+    StringBuilder sb = new StringBuilder();
+
+    for (CircuitBreakerType circuitBreakerType : circuitBreakerMap.keySet()) {
+      sb.append(circuitBreakerType.toString() + " " + circuitBreakerMap.get(circuitBreakerType).printDebugInfo());
+    }
+
+    return sb.toString();
+  }
+
+  /**
+   * Register default circuit breakers and return a constructed CircuitBreakerManager
+   * instance which serves the given circuit breakers.
+   *
+   * Any default circuit breakers should be registered here
+   */
+  public static CircuitBreakerManager buildDefaultCircuitBreakerManager(SolrCore solrCore) {
+    CircuitBreakerManager circuitBreakerManager = new CircuitBreakerManager();
+
+    // Install the default circuit breakers
+    CircuitBreaker memoryCircuitBreaker = new MemoryCircuitBreaker(solrCore);
+    circuitBreakerManager.registerCircuitBreaker(CircuitBreakerType.MEMORY, memoryCircuitBreaker);
+
+    return circuitBreakerManager;
+  }
+}
diff --git a/solr/core/src/java/org/apache/solr/util/circuitbreaker/CircuitBreakerType.java b/solr/core/src/java/org/apache/solr/util/circuitbreaker/CircuitBreakerType.java
new file mode 100644
index 0000000..63db048
--- /dev/null
+++ b/solr/core/src/java/org/apache/solr/util/circuitbreaker/CircuitBreakerType.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.util.circuitbreaker;
+
+/**
+ * Types of circuit breakers
+ */
+public enum CircuitBreakerType {
+  MEMORY,
+  CPU
+}
diff --git a/solr/core/src/java/org/apache/solr/util/circuitbreaker/MemoryCircuitBreaker.java b/solr/core/src/java/org/apache/solr/util/circuitbreaker/MemoryCircuitBreaker.java
new file mode 100644
index 0000000..ae067e9
--- /dev/null
+++ b/solr/core/src/java/org/apache/solr/util/circuitbreaker/MemoryCircuitBreaker.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.util.circuitbreaker;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryMXBean;
+
+import org.apache.solr.core.SolrCore;
+
+public class MemoryCircuitBreaker extends CircuitBreaker {
+  private static final MemoryMXBean MEMORY_MX_BEAN = ManagementFactory.getMemoryMXBean();
+
+  private final long currentMaxHeap = MEMORY_MX_BEAN.getHeapMemoryUsage().getMax();
+
+  // Assumption -- the value of these parameters will be set correctly before invoking printDebugInfo()
+  private ThreadLocal<Long> seenMemory = new ThreadLocal<>();
+  private ThreadLocal<Long> allowedMemory = new ThreadLocal<>();
+
+  public MemoryCircuitBreaker(SolrCore solrCore) {
+    super(solrCore);
+
+    if (currentMaxHeap <= 0) {
+      throw new IllegalArgumentException("Invalid JVM state for the max heap usage");
+    }
+  }
+
+  // TODO: An optimization can be to trip the circuit breaker for a duration of time
+  // after the circuit breaker condition is matched. This will optimize for per call
+  // overhead of calculating the condition parameters but can result in false positives.
+  @Override
+  public boolean isCircuitBreakerGauntletTripped() {
+    if (!isCircuitBreakerEnabled()) {
+      return false;
+    }
+
+    allowedMemory.set(getCurrentMemoryThreshold());
+
+    seenMemory.set(calculateLiveMemoryUsage());
+
+    return (seenMemory.get() >= allowedMemory.get());
+  }
+
+  @Override
+  public String printDebugInfo() {
+    return "seenMemory=" + seenMemory.get() + " allowedMemory=" + allowedMemory.get();
+  }
+
+  private long getCurrentMemoryThreshold() {
+    int thresholdValueInPercentage = solrCore.getSolrConfig().memoryCircuitBreakerThreshold;
+    double thresholdInFraction = thresholdValueInPercentage / (double) 100;
+    long actualLimit = (long) (currentMaxHeap * thresholdInFraction);
+
+    if (actualLimit <= 0) {
+      throw new IllegalStateException("Memory limit cannot be less than or equal to zero");
+    }
+
+    return actualLimit;
+  }
+
+  /**
+   * Calculate the live memory usage for the system. This method has package visibility
+   * to allow using for testing
+   * @return Memory usage in bytes
+   */
+  protected long calculateLiveMemoryUsage() {
+    // NOTE: MemoryUsageGaugeSet provides memory usage statistics but we do not use them
+    // here since MemoryUsageGaugeSet provides combination of heap and non heap usage and
+    // we are not looking into non heap usage here. Ideally, this call should not add noticeable
+    // latency to a query -- but if it does, please signify on SOLR-14588
+    return MEMORY_MX_BEAN.getHeapMemoryUsage().getUsed();
+  }
+}
diff --git a/solr/core/src/resources/EditableSolrConfigAttributes.json b/solr/core/src/resources/EditableSolrConfigAttributes.json
index ed61e1f..d5b5bd9 100644
--- a/solr/core/src/resources/EditableSolrConfigAttributes.json
+++ b/solr/core/src/resources/EditableSolrConfigAttributes.json
@@ -55,6 +55,8 @@
     "queryResultMaxDocsCached":1,
     "enableLazyFieldLoading":1,
     "boolTofilterOptimizer":1,
+    "useCircuitBreakers":10,
+    "memoryCircuitBreakerThreshold":20,
     "maxBooleanClauses":1},
   "jmx":{
     "agentId":0,
diff --git a/solr/core/src/test-files/solr/collection1/conf/solrconfig-cache-enable-disable.xml b/solr/core/src/test-files/solr/collection1/conf/solrconfig-cache-enable-disable.xml
index 29e1799..32dff76 100644
--- a/solr/core/src/test-files/solr/collection1/conf/solrconfig-cache-enable-disable.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/solrconfig-cache-enable-disable.xml
@@ -70,6 +70,10 @@
 
     <queryResultWindowSize>10</queryResultWindowSize>
 
+    <useCircuitBreakers>false</useCircuitBreakers>
+
+    <memoryCircuitBreakerThreshold>100</memoryCircuitBreakerThreshold>
+
     <!-- boolToFilterOptimizer converts boolean clauses with zero boost
          into cached filters if the number of docs selected by the clause exceeds
          the threshold (represented as a fraction of the total index)
diff --git a/solr/core/src/test-files/solr/collection1/conf/solrconfig-elevate.xml b/solr/core/src/test-files/solr/collection1/conf/solrconfig-elevate.xml
index 75d36c9..cbc0cff 100644
--- a/solr/core/src/test-files/solr/collection1/conf/solrconfig-elevate.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/solrconfig-elevate.xml
@@ -76,6 +76,10 @@
 
     <queryResultWindowSize>10</queryResultWindowSize>
 
+    <useCircuitBreakers>false</useCircuitBreakers>
+
+    <memoryCircuitBreakerThreshold>100</memoryCircuitBreakerThreshold>
+
     <!-- boolToFilterOptimizer converts boolean clauses with zero boost
          into cached filters if the number of docs selected by the clause exceeds
          the threshold (represented as a fraction of the total index)
diff --git a/solr/core/src/test-files/solr/collection1/conf/solrconfig-implicitproperties.xml b/solr/core/src/test-files/solr/collection1/conf/solrconfig-implicitproperties.xml
index 5ef9d72..aa6cf59 100644
--- a/solr/core/src/test-files/solr/collection1/conf/solrconfig-implicitproperties.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/solrconfig-implicitproperties.xml
@@ -42,6 +42,8 @@
     <enableLazyFieldLoading>true</enableLazyFieldLoading>
     <queryResultWindowSize>20</queryResultWindowSize>
     <queryResultMaxDocsCached>20</queryResultMaxDocsCached>
+    <useCircuitBreakers>false</useCircuitBreakers>
+    <memoryCircuitBreakerThreshold>100</memoryCircuitBreakerThreshold>
 
     <useColdSearcher>true</useColdSearcher>
 
diff --git a/solr/core/src/test-files/solr/collection1/conf/solrconfig-cache-enable-disable.xml b/solr/core/src/test-files/solr/collection1/conf/solrconfig-memory-circuitbreaker.xml
similarity index 92%
copy from solr/core/src/test-files/solr/collection1/conf/solrconfig-cache-enable-disable.xml
copy to solr/core/src/test-files/solr/collection1/conf/solrconfig-memory-circuitbreaker.xml
index 29e1799..ba114d5 100644
--- a/solr/core/src/test-files/solr/collection1/conf/solrconfig-cache-enable-disable.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/solrconfig-memory-circuitbreaker.xml
@@ -24,7 +24,7 @@
   <directoryFactory name="DirectoryFactory" class="${solr.directoryFactory:solr.RAMDirectoryFactory}"/>
   <schemaFactory class="ClassicIndexSchemaFactory"/>
   <requestHandler name="/select" class="solr.SearchHandler" />
-  
+
   <query>
     <!-- Maximum number of clauses in a boolean query... can affect
         range or wildcard queries that expand to big boolean
@@ -55,21 +55,25 @@
 
     <cache
       name="user_definied_cache_XXX"
-      enabled="${user_definied_cache_XXX.enabled:false}"  
+      enabled="${user_definied_cache_XXX.enabled:false}"
       />
     <cache
       name="user_definied_cache_ZZZ"
-      enabled="${user_definied_cache_ZZZ.enabled:false}"  
+      enabled="${user_definied_cache_ZZZ.enabled:false}"
       />
 
 
-    
+
     <!-- If true, stored fields that are not requested will be loaded lazily.
     -->
     <enableLazyFieldLoading>true</enableLazyFieldLoading>
 
     <queryResultWindowSize>10</queryResultWindowSize>
 
+    <useCircuitBreakers>true</useCircuitBreakers>
+
+    <memoryCircuitBreakerThreshold>75</memoryCircuitBreakerThreshold>
+
     <!-- boolToFilterOptimizer converts boolean clauses with zero boost
          into cached filters if the number of docs selected by the clause exceeds
          the threshold (represented as a fraction of the total index)
@@ -85,6 +89,3 @@
   </initParams>
 
 </config>
-
-
-
diff --git a/solr/core/src/test-files/solr/collection1/conf/solrconfig-sortingresponse.xml b/solr/core/src/test-files/solr/collection1/conf/solrconfig-sortingresponse.xml
index 1bb3c97..2c190d8 100644
--- a/solr/core/src/test-files/solr/collection1/conf/solrconfig-sortingresponse.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/solrconfig-sortingresponse.xml
@@ -35,6 +35,10 @@
 
     <queryResultMaxDocsCached>200</queryResultMaxDocsCached>
 
+    <useCircuitBreakers>false</useCircuitBreakers>
+
+    <memoryCircuitBreakerThreshold>100</memoryCircuitBreakerThreshold>
+
     <documentCache size="512"
                    initialSize="512"
                    autowarmCount="0"/>
diff --git a/solr/core/src/test-files/solr/collection1/conf/solrconfig.xml b/solr/core/src/test-files/solr/collection1/conf/solrconfig.xml
index f57b149..f1624af 100644
--- a/solr/core/src/test-files/solr/collection1/conf/solrconfig.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/solrconfig.xml
@@ -119,6 +119,16 @@
     -->
     <enableLazyFieldLoading>true</enableLazyFieldLoading>
 
+    <!-- Enable Circuit Breakers
+      -->
+    <useCircuitBreakers>false</useCircuitBreakers>
+
+    <!-- Memory Circuit Breaker Threshold In Percentage
+
+    Post this percentage usage of the heap, incoming queries will be rejected
+      -->
+    <memoryCircuitBreakerThreshold>80</memoryCircuitBreakerThreshold>
+
     <!--
 
     <cache name="myUserCache"
diff --git a/solr/core/src/test-files/solr/collection1/conf/solrconfig_perf.xml b/solr/core/src/test-files/solr/collection1/conf/solrconfig_perf.xml
index 29fbd3d..1a534a2 100644
--- a/solr/core/src/test-files/solr/collection1/conf/solrconfig_perf.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/solrconfig_perf.xml
@@ -53,6 +53,8 @@
     <enableLazyFieldLoading>true</enableLazyFieldLoading>
     <queryResultWindowSize>20</queryResultWindowSize>
     <queryResultMaxDocsCached>200</queryResultMaxDocsCached>
+    <useCircuitBreakers>false</useCircuitBreakers>
+    <memoryCircuitBreakerThreshold>100</memoryCircuitBreakerThreshold>
     <useColdSearcher>false</useColdSearcher>
 
   </query>
diff --git a/solr/core/src/test/org/apache/solr/core/SolrCoreTest.java b/solr/core/src/test/org/apache/solr/core/SolrCoreTest.java
index 09b481c..216a4db 100644
--- a/solr/core/src/test/org/apache/solr/core/SolrCoreTest.java
+++ b/solr/core/src/test/org/apache/solr/core/SolrCoreTest.java
@@ -266,6 +266,8 @@ public class SolrCoreTest extends SolrTestCaseJ4 {
     assertEquals("wrong config for maxBooleanClauses", 1024, solrConfig.booleanQueryMaxClauseCount);
     assertEquals("wrong config for enableLazyFieldLoading", true, solrConfig.enableLazyFieldLoading);
     assertEquals("wrong config for queryResultWindowSize", 10, solrConfig.queryResultWindowSize);
+    assertEquals("wrong config for useCircuitBreakers", false, solrConfig.useCircuitBreakers);
+    assertEquals("wrong config for memoryCircuitBreakerThreshold", 80, solrConfig.memoryCircuitBreakerThreshold);
   }
 
   /**
diff --git a/solr/core/src/test/org/apache/solr/core/TestConfigOverlay.java b/solr/core/src/test/org/apache/solr/core/TestConfigOverlay.java
index 1c39fa9..866596c 100644
--- a/solr/core/src/test/org/apache/solr/core/TestConfigOverlay.java
+++ b/solr/core/src/test/org/apache/solr/core/TestConfigOverlay.java
@@ -46,6 +46,8 @@ public class TestConfigOverlay extends SolrTestCase {
     assertTrue(isEditableProp("query.queryResultMaxDocsCached", false, null));
     assertTrue(isEditableProp("query.enableLazyFieldLoading", false, null));
     assertTrue(isEditableProp("query.boolTofilterOptimizer", false, null));
+    assertTrue(isEditableProp("query.useCircuitBreakers", false, null));
+    assertTrue(isEditableProp("query.memoryCircuitBreakerThreshold", false, null));
     assertTrue(isEditableProp("jmx.agentId", false, null));
     assertTrue(isEditableProp("jmx.serviceUrl", false, null));
     assertTrue(isEditableProp("jmx.rootName", false, null));
diff --git a/solr/core/src/test/org/apache/solr/util/TestCircuitBreaker.java b/solr/core/src/test/org/apache/solr/util/TestCircuitBreaker.java
new file mode 100644
index 0000000..ad6295d
--- /dev/null
+++ b/solr/core/src/test/org/apache/solr/util/TestCircuitBreaker.java
@@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.util;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.params.CommonParams;
+import org.apache.solr.common.util.ExecutorUtil;
+import org.apache.solr.common.util.SolrNamedThreadFactory;
+import org.apache.solr.core.SolrCore;
+import org.apache.solr.search.QueryParsing;
+import org.apache.solr.util.circuitbreaker.CircuitBreaker;
+import org.apache.solr.util.circuitbreaker.CircuitBreakerType;
+import org.apache.solr.util.circuitbreaker.MemoryCircuitBreaker;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+public class TestCircuitBreaker extends SolrTestCaseJ4 {
+  private final static int NUM_DOCS = 20;
+
+  @BeforeClass
+  public static void setUpClass() throws Exception {
+    System.setProperty("filterCache.enabled", "false");
+    System.setProperty("queryResultCache.enabled", "false");
+    System.setProperty("documentCache.enabled", "true");
+
+    initCore("solrconfig-memory-circuitbreaker.xml", "schema.xml");
+    for (int i = 0 ; i < NUM_DOCS ; i ++) {
+      assertU(adoc("name", "john smith", "id", "1"));
+      assertU(adoc("name", "johathon smith", "id", "2"));
+      assertU(adoc("name", "john percival smith", "id", "3"));
+
+      //commit inside the loop to get multiple segments to make search as realistic as possible
+      assertU(commit());
+    }
+  }
+
+  @Override
+  public void tearDown() throws Exception {
+    super.tearDown();
+  }
+
+  @AfterClass
+  public static void afterClass() {
+    System.clearProperty("filterCache.enabled");
+    System.clearProperty("queryResultCache.enabled");
+    System.clearProperty("documentCache.enabled");
+  }
+
+  public void testCBAlwaysTrips() throws IOException {
+    HashMap<String, String> args = new HashMap<String, String>();
+
+    args.put(QueryParsing.DEFTYPE, CircuitBreaker.NAME);
+    args.put(CommonParams.FL, "id");
+
+    CircuitBreaker circuitBreaker = new MockCircuitBreaker(h.getCore());
+
+    h.getCore().getCircuitBreakerManager().registerCircuitBreaker(CircuitBreakerType.MEMORY, circuitBreaker);
+
+    expectThrows(SolrException.class, () -> {
+      h.query(req("name:\"john smith\""));
+    });
+  }
+
+  public void testCBFakeMemoryPressure() throws IOException {
+    HashMap<String, String> args = new HashMap<String, String>();
+
+    args.put(QueryParsing.DEFTYPE, CircuitBreaker.NAME);
+    args.put(CommonParams.FL, "id");
+
+    CircuitBreaker circuitBreaker = new FakeMemoryPressureCircuitBreaker(h.getCore());
+
+    h.getCore().getCircuitBreakerManager().registerCircuitBreaker(CircuitBreakerType.MEMORY, circuitBreaker);
+
+    expectThrows(SolrException.class, () -> {
+      h.query(req("name:\"john smith\""));
+    });
+  }
+
+  public void testBuildingMemoryPressure() {
+    ExecutorService executor = ExecutorUtil.newMDCAwareCachedThreadPool(
+        new SolrNamedThreadFactory("TestCircuitBreaker"));
+    HashMap<String, String> args = new HashMap<String, String>();
+
+    args.put(QueryParsing.DEFTYPE, CircuitBreaker.NAME);
+    args.put(CommonParams.FL, "id");
+
+    AtomicInteger failureCount = new AtomicInteger();
+
+    try {
+      CircuitBreaker circuitBreaker = new BuildingUpMemoryPressureCircuitBreaker(h.getCore());
+
+      h.getCore().getCircuitBreakerManager().registerCircuitBreaker(CircuitBreakerType.MEMORY, circuitBreaker);
+
+      for (int i = 0; i < 5; i++) {
+        executor.submit(() -> {
+          try {
+            h.query(req("name:\"john smith\""));
+          } catch (SolrException e) {
+            failureCount.incrementAndGet();
+          } catch (Exception e) {
+            throw new RuntimeException(e.getMessage());
+          }
+        });
+      }
+
+      executor.shutdown();
+      try {
+        executor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
+      } catch (InterruptedException e) {
+        throw new RuntimeException(e.getMessage());
+      }
+
+      assertEquals("Number of failed queries is not correct", 1, failureCount.get());
+    } finally {
+      if (!executor.isShutdown()) {
+        executor.shutdown();
+      }
+    }
+  }
+
+  private class MockCircuitBreaker extends CircuitBreaker {
+
+    public MockCircuitBreaker(SolrCore solrCore) {
+      super(solrCore);
+    }
+
+    @Override
+    public boolean isCircuitBreakerGauntletTripped() {
+      // Always return true
+      return true;
+    }
+
+    @Override
+    public String printDebugInfo() {
+      return "MockCircuitBreaker";
+    }
+  }
+
+  private class FakeMemoryPressureCircuitBreaker extends MemoryCircuitBreaker {
+
+    public FakeMemoryPressureCircuitBreaker(SolrCore solrCore) {
+      super(solrCore);
+    }
+
+    @Override
+    protected long calculateLiveMemoryUsage() {
+      // Return a number large enough to trigger a pushback from the circuit breaker
+      return Long.MAX_VALUE;
+    }
+  }
+
+  private class BuildingUpMemoryPressureCircuitBreaker extends MemoryCircuitBreaker {
+    private AtomicInteger count = new AtomicInteger();
+
+    public BuildingUpMemoryPressureCircuitBreaker(SolrCore solrCore) {
+      super(solrCore);
+    }
+
+    @Override
+    protected long calculateLiveMemoryUsage() {
+      if (count.getAndIncrement() >= 4) {
+        return Long.MAX_VALUE;
+      }
+
+      return 5; // Random number guaranteed to not trip the circuit breaker
+    }
+  }
+}
diff --git a/solr/example/example-DIH/solr/db/conf/solrconfig.xml b/solr/example/example-DIH/solr/db/conf/solrconfig.xml
index 1127093..427c164 100644
--- a/solr/example/example-DIH/solr/db/conf/solrconfig.xml
+++ b/solr/example/example-DIH/solr/db/conf/solrconfig.xml
@@ -502,6 +502,16 @@
      -->
    <queryResultMaxDocsCached>200</queryResultMaxDocsCached>
 
+    <!-- Enable Circuit Breakers
+  -->
+    <useCircuitBreakers>false</useCircuitBreakers>
+
+    <!-- Memory Circuit Breaker Threshold In Percentage
+
+    Post this percentage usage of the heap, incoming queries will be rejected
+      -->
+    <memoryCircuitBreakerThreshold>100</memoryCircuitBreakerThreshold>
+
    <!-- Query Related Event Listeners
 
         Various IndexSearcher related events can trigger Listeners to
diff --git a/solr/example/example-DIH/solr/mail/conf/solrconfig.xml b/solr/example/example-DIH/solr/mail/conf/solrconfig.xml
index 91b9957..6ba9758 100644
--- a/solr/example/example-DIH/solr/mail/conf/solrconfig.xml
+++ b/solr/example/example-DIH/solr/mail/conf/solrconfig.xml
@@ -505,6 +505,16 @@
      -->
    <queryResultMaxDocsCached>200</queryResultMaxDocsCached>
 
+    <!-- Enable Circuit Breakers
+  -->
+    <useCircuitBreakers>false</useCircuitBreakers>
+
+    <!-- Memory Circuit Breaker Threshold In Percentage
+
+    Post this percentage usage of the heap, incoming queries will be rejected
+      -->
+    <memoryCircuitBreakerThreshold>100</memoryCircuitBreakerThreshold>
+
    <!-- Query Related Event Listeners
 
         Various IndexSearcher related events can trigger Listeners to
diff --git a/solr/example/example-DIH/solr/solr/conf/solrconfig.xml b/solr/example/example-DIH/solr/solr/conf/solrconfig.xml
index 56e7ed6..28a9b49 100644
--- a/solr/example/example-DIH/solr/solr/conf/solrconfig.xml
+++ b/solr/example/example-DIH/solr/solr/conf/solrconfig.xml
@@ -502,6 +502,16 @@
      -->
    <queryResultMaxDocsCached>200</queryResultMaxDocsCached>
 
+    <!-- Enable Circuit Breakers
+  -->
+    <useCircuitBreakers>false</useCircuitBreakers>
+
+    <!-- Memory Circuit Breaker Threshold In Percentage
+
+    Post this percentage usage of the heap, incoming queries will be rejected
+      -->
+    <memoryCircuitBreakerThreshold>100</memoryCircuitBreakerThreshold>
+
    <!-- Query Related Event Listeners
 
         Various IndexSearcher related events can trigger Listeners to
diff --git a/solr/example/files/conf/solrconfig.xml b/solr/example/files/conf/solrconfig.xml
index d16d4bf..c400a44 100644
--- a/solr/example/files/conf/solrconfig.xml
+++ b/solr/example/files/conf/solrconfig.xml
@@ -498,6 +498,16 @@
       -->
     <queryResultMaxDocsCached>200</queryResultMaxDocsCached>
 
+    <!-- Enable Circuit Breakers
+      -->
+    <useCircuitBreakers>false</useCircuitBreakers>
+
+    <!-- Memory Circuit Breaker Threshold In Percentage
+
+    Post this percentage usage of the heap, incoming queries will be rejected
+      -->
+    <memoryCircuitBreakerThreshold>100</memoryCircuitBreakerThreshold>
+
     <!-- Query Related Event Listeners
 
          Various IndexSearcher related events can trigger Listeners to
diff --git a/solr/server/solr/configsets/_default/conf/solrconfig.xml b/solr/server/solr/configsets/_default/conf/solrconfig.xml
index db0e906..b92ecab 100644
--- a/solr/server/solr/configsets/_default/conf/solrconfig.xml
+++ b/solr/server/solr/configsets/_default/conf/solrconfig.xml
@@ -513,6 +513,16 @@
       -->
     <queryResultMaxDocsCached>200</queryResultMaxDocsCached>
 
+    <!-- Enable Circuit Breakers
+      -->
+    <useCircuitBreakers>false</useCircuitBreakers>
+
+    <!-- Memory Circuit Breaker Threshold In Percentage
+
+    Post this percentage usage of the heap, incoming queries will be rejected
+      -->
+    <memoryCircuitBreakerThreshold>100</memoryCircuitBreakerThreshold>
+
     <!-- Query Related Event Listeners
 
          Various IndexSearcher related events can trigger Listeners to
diff --git a/solr/server/solr/configsets/sample_techproducts_configs/conf/solrconfig.xml b/solr/server/solr/configsets/sample_techproducts_configs/conf/solrconfig.xml
index 554a82e..45a5ef8 100644
--- a/solr/server/solr/configsets/sample_techproducts_configs/conf/solrconfig.xml
+++ b/solr/server/solr/configsets/sample_techproducts_configs/conf/solrconfig.xml
@@ -554,6 +554,16 @@
      -->
    <queryResultMaxDocsCached>200</queryResultMaxDocsCached>
 
+    <!-- Enable Circuit Breakers
+      -->
+    <useCircuitBreakers>false</useCircuitBreakers>
+
+    <!-- Memory Circuit Breaker Threshold In Percentage
+
+    Post this percentage usage of the heap, incoming queries will be rejected
+      -->
+    <memoryCircuitBreakerThreshold>100</memoryCircuitBreakerThreshold>
+
    <!-- Query Related Event Listeners
 
         Various IndexSearcher related events can trigger Listeners to
diff --git a/solr/solr-ref-guide/src/config-api.adoc b/solr/solr-ref-guide/src/config-api.adoc
index 21227e4..8b472eb 100644
--- a/solr/solr-ref-guide/src/config-api.adoc
+++ b/solr/solr-ref-guide/src/config-api.adoc
@@ -202,6 +202,10 @@ _Query Sizing and Warming_
 * `query.queryResultWindowSize`
 * `query.queryResultMaxDocCached`
 
+_Query JVM Metrics Control_
+* `query.useCircuitBreakers`
+* `query.memoryCircuitBreakerThreshold`
+
 *RequestDispatcher Settings*
 
 See <<requestdispatcher-in-solrconfig.adoc#requestdispatcher-in-solrconfig,RequestDispatcher in SolrConfig>> for defaults and acceptable values for these settings.
diff --git a/solr/solr-ref-guide/src/query-settings-in-solrconfig.adoc b/solr/solr-ref-guide/src/query-settings-in-solrconfig.adoc
index e12aafb..0d4b6fa 100644
--- a/solr/solr-ref-guide/src/query-settings-in-solrconfig.adoc
+++ b/solr/solr-ref-guide/src/query-settings-in-solrconfig.adoc
@@ -170,6 +170,24 @@ This parameter sets the maximum number of documents to cache for any entry in th
 <queryResultMaxDocsCached>200</queryResultMaxDocsCached>
 ----
 
+=== useCircuitBreakers
+
+This parameter allows enabling circuit breakers for query control.
+
+[source,xml]
+----
+<useCircuitBreakers>true</useCircuitBreakers>
+----
+
+=== memoryCircuitBreakerThreshold
+
+Memory threshold in percentage for JVM heap usage
+
+[source,xml]
+----
+<memoryCircuitBreakerThreshold>75</memoryCircuitBreakerThreshold>
+----
+
 === useColdSearcher
 
 This setting controls whether search requests for which there is not a currently registered searcher should wait for a new searcher to warm up (false) or proceed immediately (true). When set to "false", requests will block until the searcher has warmed its caches.