From b3e0a10336401f7c79fc4996724b4bdb751b5ddb Mon Sep 17 00:00:00 2001 From: Tomas Eduardo Fernandez Lobbe Date: Thu, 6 Aug 2015 21:27:07 +0000 Subject: [PATCH] SOLR-7875: Speedup SolrQueryTimeoutImpl git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1694574 13f79535-47bb-0310-9956-ffa450edef68 --- solr/CHANGES.txt | 3 ++ .../solr/search/SolrQueryTimeoutImpl.java | 35 +++++-------------- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index f6aab5132ec..0a4599b7155 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -328,6 +328,9 @@ Optimizations * SOLR-7840: ZkStateReader.updateClusterState fetches watched collections twice from ZK. (shalin) +* SOLR-7875: Speedup SolrQueryTimeoutImpl. Avoid setting a timeout time when timeAllowed + parameter is not set. (Tomás Fernández Löbbe) + Other Changes ---------------------- diff --git a/solr/core/src/java/org/apache/solr/search/SolrQueryTimeoutImpl.java b/solr/core/src/java/org/apache/solr/search/SolrQueryTimeoutImpl.java index 2ff09900cf7..998631cb4ca 100644 --- a/solr/core/src/java/org/apache/solr/search/SolrQueryTimeoutImpl.java +++ b/solr/core/src/java/org/apache/solr/search/SolrQueryTimeoutImpl.java @@ -17,11 +17,11 @@ package org.apache.solr.search; * limitations under the License. */ -import org.apache.lucene.index.QueryTimeout; +import static java.lang.System.nanoTime; import java.util.concurrent.TimeUnit; -import static java.lang.System.nanoTime; +import org.apache.lucene.index.QueryTimeout; /** * Implementation of {@link QueryTimeout} that is used by Solr. @@ -32,29 +32,7 @@ public class SolrQueryTimeoutImpl implements QueryTimeout { /** * The ThreadLocal variable to store the time beyond which, the processing should exit. */ - public static ThreadLocal timeoutAt = new ThreadLocal() { - /** - * {@inheritDoc} - *

- * By default, timeoutAt is set as far in the future as possible, - * so that it effectively never happens. - *

- * Since nanoTime() values can be anything from Long.MIN_VALUE to - * Long.MAX_VALUE, adding Long.MAX_VALUE can cause overflow. That's - * expected and works fine, since in that case the subtraction of a - * future nanoTime() value from timeoutAt (in - * {@link SolrQueryTimeoutImpl#shouldExit}) will result in underflow, - * and checking the sign of the result of that subtraction (via - * comparison to zero) will correctly indicate whether the future - * nanoTime() value has exceeded the timeoutAt value. - *

- * See {@link System#nanoTime} - */ - @Override - protected Long initialValue() { - return nanoTime() + Long.MAX_VALUE; - } - }; + public static ThreadLocal timeoutAt = new ThreadLocal(); private SolrQueryTimeoutImpl() { } private static SolrQueryTimeoutImpl instance = new SolrQueryTimeoutImpl(); @@ -76,7 +54,12 @@ public class SolrQueryTimeoutImpl implements QueryTimeout { */ @Override public boolean shouldExit() { - return get() - nanoTime() < 0L; + Long timeoutAt = get(); + if (timeoutAt == null) { + // timeout unset + return false; + } + return timeoutAt - nanoTime() < 0L; } /**