Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-17144: Do not keep an active thread per core (#2236)

Pierre Salagnac3ab16670d13c
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index c9dc2c8e651..bab3ed4fa55 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -92,7 +92,7 @@ Improvements
Optimizations
---------------------
-(No changes)
+* SOLR-17144: Close searcherExecutor thread per core after 1 minute (Pierre Salagnac, Christine Poerschke)
Bug Fixes
---------------------
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 be6f7526b3d..c72d9debc55 100644
--- a/solr/core/src/java/org/apache/solr/core/SolrCore.java
+++ b/solr/core/src/java/org/apache/solr/core/SolrCore.java
@@ -2056,8 +2056,10 @@ public class SolrCore implements SolrInfoBean, Closeable {
private final ArrayDeque<RefCounted<SolrIndexSearcher>> _searchers = new ArrayDeque<>();
private final ArrayDeque<RefCounted<SolrIndexSearcher>> _realtimeSearchers = new ArrayDeque<>();
+ // Single threaded pool, with a time-to-keep of 60 seconds
final ExecutorService searcherExecutor =
- ExecutorUtil.newMDCAwareSingleThreadExecutor(new SolrNamedThreadFactory("searcherExecutor"));
+ ExecutorUtil.newMDCAwareSingleLazyThreadExecutor(
+ new SolrNamedThreadFactory("searcherExecutor"), 60L, TimeUnit.SECONDS);
private int onDeckSearchers; // number of searchers preparing
// Lock ordering: one can acquire the openSearcherLock and then the searcherLock, but not
// vice-versa.
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java b/solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java
index cfa7b176d50..f0d1f8bc698 100644
--- a/solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java
+++ b/solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java
@@ -150,12 +150,25 @@ public class ExecutorUtil {
nThreads, nThreads, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(), threadFactory);
}
- /** See {@link java.util.concurrent.Executors#newSingleThreadExecutor(ThreadFactory)} */
+ /**
+ * See {@link java.util.concurrent.Executors#newSingleThreadExecutor(ThreadFactory)}. Note the
+ * thread is always active, even if no tasks are submitted to the executor.
+ */
public static ExecutorService newMDCAwareSingleThreadExecutor(ThreadFactory threadFactory) {
return new MDCAwareThreadPoolExecutor(
1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(), threadFactory);
}
+ /**
+ * Similar to {@link #newMDCAwareSingleThreadExecutor(ThreadFactory)}, but the thread will not be
+ * kept active after the specified time if no task is submitted to the executor.
+ */
+ public static ExecutorService newMDCAwareSingleLazyThreadExecutor(
+ ThreadFactory threadFactory, long keepAliveTime, TimeUnit unit) {
+ return new MDCAwareThreadPoolExecutor(
+ 0, 1, keepAliveTime, unit, new LinkedBlockingQueue<>(), threadFactory);
+ }
+
/** Create a cached thread pool using a named thread factory */
public static ExecutorService newMDCAwareCachedThreadPool(String name) {
return newMDCAwareCachedThreadPool(new SolrNamedThreadFactory(name));