You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ma...@apache.org on 2020/07/22 01:03:11 UTC
[lucene-solr] branch reference_impl updated: @277 Improve the
thread management life cycle.
This is an automated email from the ASF dual-hosted git repository.
markrmiller pushed a commit to branch reference_impl
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
The following commit(s) were added to refs/heads/reference_impl by this push:
new c7c646e @277 Improve the thread management life cycle.
c7c646e is described below
commit c7c646e2f6f0348f0c9f899baaecc6563680b782
Author: markrmiller@gmail.com <ma...@gmail.com>
AuthorDate: Tue Jul 21 20:02:58 2020 -0500
@277 Improve the thread management life cycle.
---
.../facet/LegacyAbstractAnalyticsFacetTest.java | 7 +-
solr/server/etc/jetty.xml | 33 +++---
.../org/apache/solr/common/ParWorkExecutor.java | 125 +--------------------
.../solr/common/util/SolrQueuedThreadPool.java | 1 +
4 files changed, 23 insertions(+), 143 deletions(-)
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyAbstractAnalyticsFacetTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyAbstractAnalyticsFacetTest.java
index 055ba46..de2eba3 100644
--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyAbstractAnalyticsFacetTest.java
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/facet/LegacyAbstractAnalyticsFacetTest.java
@@ -36,6 +36,7 @@ import org.apache.solr.analytics.util.MedianCalculator;
import org.apache.solr.analytics.util.OrdinalCalculator;
import org.apache.solr.core.XmlConfigFile;
import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.schema.IndexSchema;
import org.apache.solr.util.BaseTestHarness;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -88,7 +89,7 @@ public class LegacyAbstractAnalyticsFacetTest extends SolrTestCaseJ4 {
}
protected Node getNode(String xPath) throws XPathExpressionException {
- return (Node)XmlConfigFile.xpath.compile(xPath).evaluate(doc, XPathConstants.NODE);
+ return (Node) IndexSchema.getXpath().compile(xPath).evaluate(doc, XPathConstants.NODE);
}
private NodeList getNodes(String n1, String n2, String n3, String element, String n4) throws XPathExpressionException {
// Construct the XPath expression. The form better not change or all these will fail.
@@ -97,7 +98,7 @@ public class LegacyAbstractAnalyticsFacetTest extends SolrTestCaseJ4 {
sb.append("/lst[@name='").append(n3).append("']");
sb.append("/lst[@name!='(MISSING)']");
sb.append("//").append(element).append("[@name='").append(n4).append("']");
- return (NodeList)XmlConfigFile.xpath.compile(sb.toString()).evaluate(doc, XPathConstants.NODESET);
+ return (NodeList) IndexSchema.getXpath().compile(sb.toString()).evaluate(doc, XPathConstants.NODESET);
}
protected ArrayList<String> getStringList(String n1, String n2, String n3, String element, String n4)
@@ -336,7 +337,7 @@ public class LegacyAbstractAnalyticsFacetTest extends SolrTestCaseJ4 {
protected NodeList getNodes(String xPath) throws XPathExpressionException {
StringBuilder sb = new StringBuilder(xPath);
- return (NodeList) XmlConfigFile.xpath.compile(sb.toString()).evaluate(doc, XPathConstants.NODESET);
+ return (NodeList) IndexSchema.getXpath().compile(sb.toString()).evaluate(doc, XPathConstants.NODESET);
}
}
diff --git a/solr/server/etc/jetty.xml b/solr/server/etc/jetty.xml
index ecd4f22..72e1368 100644
--- a/solr/server/etc/jetty.xml
+++ b/solr/server/etc/jetty.xml
@@ -30,25 +30,26 @@
<!-- for all configuration that may be set here. -->
<!-- =========================================================== -->
<Arg name="threadpool">
- <New id="threadpool" class="com.codahale.metrics.jetty9.InstrumentedQueuedThreadPool">
- <Arg name="registry">
- <Call id="solrJettyMetricRegistry" name="getOrCreate" class="com.codahale.metrics.SharedMetricRegistries">
- <Arg>solr.jetty</Arg>
- </Call>
- </Arg>
- </New>
- </Arg>
+ <New id="threadpool" class="org.apache.solr.common.util.SolrQueuedThreadPool">
+ <!-- <New id="threadpool" class="com.codahale.metrics.jetty9.InstrumentedQueuedThreadPool">
+ <Arg name="registry">
+ <Call id="solrJettyMetricRegistry" name="getOrCreate" class="com.codahale.metrics.SharedMetricRegistries">
+ <Arg>solr.jetty</Arg>
+ </Call>
+ </Arg>-->
+ </New>
+</Arg>
- <Get name="ThreadPool">
- <Set name="minThreads" type="int"><Property name="solr.jetty.threads.min" default="10"/></Set>
- <Set name="maxThreads" type="int"><Property name="solr.jetty.threads.max" default="10000"/></Set>
- <Set name="idleTimeout" type="int"><Property name="solr.jetty.threads.idle.timeout" default="120000"/></Set>
- <Set name="stopTimeout" type="int"><Property name="solr.jetty.threads.stop.timeout" default="60000"/></Set>
- <Set name="detailedDump">false</Set>
- </Get>
+<Get name="ThreadPool">
+ <Set name="minThreads" type="int"><Property name="solr.jetty.threads.min" default="10"/></Set>
+ <Set name="maxThreads" type="int"><Property name="solr.jetty.threads.max" default="10000"/></Set>
+ <Set name="idleTimeout" type="int"><Property name="solr.jetty.threads.idle.timeout" default="120000"/></Set>
+ <Set name="stopTimeout" type="int"><Property name="solr.jetty.threads.stop.timeout" default="60000"/></Set>
+ <Set name="detailedDump">false</Set>
+</Get>
- <!-- =========================================================== -->
+<!-- =========================================================== -->
<!-- Http Configuration. -->
<!-- This is a common configuration instance used by all -->
<!-- connectors that can carry HTTP semantics (HTTP, HTTPS, SPDY)-->
diff --git a/solr/solrj/src/java/org/apache/solr/common/ParWorkExecutor.java b/solr/solrj/src/java/org/apache/solr/common/ParWorkExecutor.java
index 1aa442d..d618cf8 100644
--- a/solr/solrj/src/java/org/apache/solr/common/ParWorkExecutor.java
+++ b/solr/solrj/src/java/org/apache/solr/common/ParWorkExecutor.java
@@ -21,7 +21,6 @@ import java.util.concurrent.atomic.AtomicInteger;
public class ParWorkExecutor extends ThreadPoolExecutor {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
public static final long KEEP_ALIVE_TIME = 1;
- private static final int GROW_BY = 30;
private final Object lock = new Object();
@@ -46,130 +45,8 @@ public class ParWorkExecutor extends ThreadPoolExecutor {
}
});
- setRejectedExecutionHandler(new RejectedExecutionHandler() {
- private volatile Runnable last;
- @Override
- public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
- throw new RejectedExecutionException();
-// if (last == r) {
-// return;
-// }
-
-// log.warn("Task was rejected, running in caller thread name" + name + " shutdown:" + isShutdown() + " terminated:" + isTerminated() + " terminating:" + isTerminating());
-// if (executor.isShutdown() || executor.isTerminated() || executor.isTerminating() || Thread.currentThread().isInterrupted()) {
-// return;
-// }
-//
-//// synchronized (lock) {
-//// try {
-//// Thread.sleep(1000);
-//// } catch (InterruptedException e) {
-//// ParWork.propegateInterrupt(e, true);
-//// return;
-//// }
-// try {
-// executor.submit(r);
-// last = r;
-// } catch (Exception e) {
-// if (e instanceof InterruptedException) {
-// Thread.currentThread().interrupt();
-// }
-// }
- }
- });
+ setRejectedExecutionHandler(new CallerRunsPolicy());
allowCoreThreadTimeOut(true);
}
-
- public Future<?> submit(Runnable task) {
- if (task == null) {
- throw new NullPointerException();
- } else {
- if (getActiveCount() == getMaximumPoolSize() && getQueue().remainingCapacity() == 0) {
- try {
- task.run();
- } catch (Exception e) {
- if (e instanceof InterruptedException) {
- Thread.currentThread().interrupt();
- throw new RuntimeException("Exception running task in caller thread");
- }
- }
- return CompletableFuture.completedFuture(new Object());
- }
- RunnableFuture<Object> ftask = super.newTaskFor(task, (Object)null);
- try {
- this.execute(ftask);
- } catch (RejectedExecutionException e) {
- task.run();
- return CompletableFuture.completedFuture(new Object());
- }
- return ftask;
- }
- }
-
- public <T> Future<T> submit(Runnable task, T result) {
- if (task == null) {
- throw new NullPointerException();
- } else {
- if (getActiveCount() == getMaximumPoolSize() && getQueue().remainingCapacity() == 0) {
- try {
- task.run();
- } catch (Exception e) {
- if (e instanceof InterruptedException) {
- Thread.currentThread().interrupt();
- throw new RuntimeException("Exception running task in caller thread");
- }
- }
- return CompletableFuture.completedFuture(result);
- }
- RunnableFuture<T> ftask = this.newTaskFor(task, result);
- try {
- this.execute(ftask);
- } catch (RejectedExecutionException e) {
- ftask.run();
- return CompletableFuture.completedFuture(result);
- }
- return ftask;
- }
- }
-
- public <T> Future<T> submit(Callable<T> task) {
- if (task == null) {
- throw new NullPointerException();
- } else {
- if (getActiveCount() == getMaximumPoolSize() && getQueue().remainingCapacity() == 0) {
- T res = null;
- try {
- res = task.call();
- } catch (Exception e) {
- if (e instanceof InterruptedException) {
- Thread.currentThread().interrupt();
- throw new RuntimeException("Exception running task in caller thread");
- }
- }
- CompletableFuture<Object> future = new CompletableFuture<>();
- future.complete(res);
- return (Future<T>) future;
- }
- RunnableFuture<T> ftask = this.newTaskFor(task);
- try {
- this.execute(ftask);
- } catch (RejectedExecutionException e) {
- ftask.run();
- CompletableFuture<Object> future = new CompletableFuture<>();
- future.complete(new Object());
- return (Future<T>) future;
- }
- return ftask;
- }
- }
-
- @Override
- protected void afterExecute(Runnable r, Throwable t) {
- super.afterExecute(r, t);
-// synchronized (lock) {
-// lock.notifyAll();
-// }
- }
-
}
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/SolrQueuedThreadPool.java b/solr/solrj/src/java/org/apache/solr/common/util/SolrQueuedThreadPool.java
index 7e7d6c6..1befa07 100644
--- a/solr/solrj/src/java/org/apache/solr/common/util/SolrQueuedThreadPool.java
+++ b/solr/solrj/src/java/org/apache/solr/common/util/SolrQueuedThreadPool.java
@@ -703,6 +703,7 @@ public class SolrQueuedThreadPool extends ContainerLifeCycle implements ThreadFa
protected void removeThread(Thread thread)
{
+ ParWork.close(ParWork.getExecutor());
_threads.remove(thread);
}