Skip to content

Commit

Permalink
SOLR-13350: Multithreaded search (closes #2248)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ishan Chattopadhyaya committed May 6, 2024
1 parent b63e9cf commit ff6607d
Show file tree
Hide file tree
Showing 19 changed files with 772 additions and 46 deletions.
2 changes: 1 addition & 1 deletion solr/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Other Changes
================== 9.7.0 ==================
New Features
---------------------
(No changes)
* SOLR-13350: Multithreaded search execution (Ishan Chattopadhyaya, Mark Miller, Christine Poerschke, David Smiley, noble)

Improvements
---------------------
Expand Down
3 changes: 3 additions & 0 deletions solr/bin/solr
Original file line number Diff line number Diff line change
Expand Up @@ -1441,6 +1441,9 @@ if [ $# -gt 0 ]; then
done
fi

# Setting number of threads for search
if ! command -v nproc &> /dev/null; then echo "Couldn't determine number of CPUs, using default number of search threads"; else cpus=`nproc`; SCRIPT_SOLR_OPTS+="-Dsolr.searchThreads=$cpus"; fi

# Default placement plugin
if [[ -n "${SOLR_PLACEMENTPLUGIN_DEFAULT:-}" ]] ; then
SCRIPT_SOLR_OPTS+=("-Dsolr.placementplugin.default=$SOLR_PLACEMENTPLUGIN_DEFAULT")
Expand Down
15 changes: 15 additions & 0 deletions solr/core/src/java/org/apache/solr/core/CoreContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeoutException;
import java.util.function.Function;
Expand Down Expand Up @@ -175,6 +176,10 @@ public class CoreContainer {

final SolrCores solrCores;

public Executor getCollectorExecutor() {
return collectorExecutor;
}

public static class CoreLoadFailure {

public final CoreDescriptor cd;
Expand Down Expand Up @@ -278,6 +283,8 @@ public JerseyAppHandlerCache getJerseyAppHandlerCache() {

public final NodeRoles nodeRoles = new NodeRoles(System.getProperty(NodeRoles.NODE_ROLES_PROP));

private final ExecutorService collectorExecutor;

private final ClusterSingletons clusterSingletons =
new ClusterSingletons(
() ->
Expand Down Expand Up @@ -432,6 +439,12 @@ public CoreContainer(NodeConfig config, CoresLocator locator, boolean asyncSolrC
this.allowPaths = allowPathBuilder.build();

this.allowListUrlChecker = AllowListUrlChecker.create(config);

this.collectorExecutor =
ExecutorUtil.newMDCAwareCachedThreadPool(
cfg.getIndexSearcherExecutorThreads(), // thread count
cfg.getIndexSearcherExecutorThreads() * 1000, // queue size
new SolrNamedThreadFactory("searcherCollector"));
}

@SuppressWarnings({"unchecked"})
Expand Down Expand Up @@ -657,6 +670,7 @@ protected CoreContainer(Object testConstructor) {
distributedCollectionCommandRunner = Optional.empty();
allowPaths = null;
allowListUrlChecker = null;
collectorExecutor = null;
}

public static CoreContainer createAndLoad(Path solrHome) {
Expand Down Expand Up @@ -1248,6 +1262,7 @@ public void shutdown() {
}

ExecutorUtil.shutdownAndAwaitTermination(coreContainerAsyncTaskExecutor);
ExecutorUtil.shutdownAndAwaitTermination(collectorExecutor);
ExecutorService customThreadPool =
ExecutorUtil.newMDCAwareCachedThreadPool(new SolrNamedThreadFactory("closeThreadPool"));

Expand Down
18 changes: 18 additions & 0 deletions solr/core/src/java/org/apache/solr/core/NodeConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public class NodeConfig {

private final int replayUpdatesThreads;

private final int indexSearcherExecutorThreads;

@Deprecated private final int transientCacheSize;

private final boolean useSchemaCache;
Expand Down Expand Up @@ -144,6 +146,7 @@ private NodeConfig(
CloudConfig cloudConfig,
Integer coreLoadThreads,
int replayUpdatesThreads,
int indexSearcherExecutorThreads,
int transientCacheSize,
boolean useSchemaCache,
String managementPath,
Expand Down Expand Up @@ -183,6 +186,7 @@ private NodeConfig(
this.cloudConfig = cloudConfig;
this.coreLoadThreads = coreLoadThreads;
this.replayUpdatesThreads = replayUpdatesThreads;
this.indexSearcherExecutorThreads = indexSearcherExecutorThreads;
this.transientCacheSize = transientCacheSize;
this.useSchemaCache = useSchemaCache;
this.managementPath = managementPath;
Expand Down Expand Up @@ -335,6 +339,10 @@ public int getReplayUpdatesThreads() {
return replayUpdatesThreads;
}

public int getIndexSearcherExecutorThreads() {
return indexSearcherExecutorThreads;
}

/**
* Returns a directory, optionally a comma separated list of directories that will be added to
* Solr's class path for searching for classes and plugins. The path is either absolute or
Expand Down Expand Up @@ -597,6 +605,7 @@ public static class NodeConfigBuilder {
private CloudConfig cloudConfig;
private int coreLoadThreads = DEFAULT_CORE_LOAD_THREADS;
private int replayUpdatesThreads = Runtime.getRuntime().availableProcessors();
private int indexSearcherExecutorThreads = DEFAULT_INDEX_SEARCHER_EXECUTOR_THREADS;
@Deprecated private int transientCacheSize = -1;
private boolean useSchemaCache = false;
private String managementPath;
Expand All @@ -618,6 +627,9 @@ public static class NodeConfigBuilder {
// No:of core load threads in cloud mode is set to a default of 8
public static final int DEFAULT_CORE_LOAD_THREADS_IN_CLOUD = 8;

public static final int DEFAULT_INDEX_SEARCHER_EXECUTOR_THREADS =
4;

private static final String DEFAULT_CORESLOCATORCLASS =
"org.apache.solr.core.CorePropertiesLocator";
private static final String DEFAULT_CORESORTERCLASS = "org.apache.solr.core.CoreSorter";
Expand Down Expand Up @@ -755,6 +767,11 @@ public NodeConfigBuilder setReplayUpdatesThreads(int replayUpdatesThreads) {
return this;
}

public NodeConfigBuilder setIndexSearcherExecutorThreads(int indexSearcherExecutorThreads) {
this.indexSearcherExecutorThreads = indexSearcherExecutorThreads;
return this;
}

// Remove in Solr 10.0

@Deprecated
Expand Down Expand Up @@ -904,6 +921,7 @@ public NodeConfig build() {
cloudConfig,
coreLoadThreads,
replayUpdatesThreads,
indexSearcherExecutorThreads,
transientCacheSize,
useSchemaCache,
managementPath,
Expand Down
3 changes: 3 additions & 0 deletions solr/core/src/java/org/apache/solr/core/SolrXmlConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,9 @@ private static NodeConfig fillSolrSection(NodeConfig.NodeConfigBuilder builder,
case "replayUpdatesThreads":
builder.setReplayUpdatesThreads(it.intVal(-1));
break;
case "indexSearcherExecutorThreads":
builder.setIndexSearcherExecutorThreads(it.intVal(-1));
break;
case "transientCacheSize":
log.warn("solr.xml transientCacheSize -- transient cores is deprecated");
builder.setTransientCacheSize(it.intVal(-1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,13 @@ public void process(ResponseBuilder rb) throws IOException {
return;
}

final boolean multiThreaded = params.getBool("multiThreaded", true);

// -1 as flag if not set.
long timeAllowed = params.getLong(CommonParams.TIME_ALLOWED, -1L);

QueryCommand cmd = rb.createQueryCommand();
cmd.setMultiThreaded(multiThreaded);
cmd.setTimeAllowed(timeAllowed);
cmd.setMinExactCount(getMinExactCount(params));
cmd.setDistribStatsDisabled(rb.isDistribStatsDisabled());
Expand Down
Loading

0 comments on commit ff6607d

Please sign in to comment.