From c16680efec3bf3605f95c447c15b85063a916757 Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Thu, 24 Oct 2024 14:42:49 -0400 Subject: [PATCH] add search threading --- .../src/main/java/io/zulia/server/index/ShardReader.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/zulia-server/src/main/java/io/zulia/server/index/ShardReader.java b/zulia-server/src/main/java/io/zulia/server/index/ShardReader.java index 4c085493..f46bad71 100644 --- a/zulia-server/src/main/java/io/zulia/server/index/ShardReader.java +++ b/zulia-server/src/main/java/io/zulia/server/index/ShardReader.java @@ -53,6 +53,8 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.function.Consumer; public class ShardReader implements AutoCloseable { @@ -67,6 +69,7 @@ public class ShardReader implements AutoCloseable { private final ZuliaPerFieldAnalyzer zuliaPerFieldAnalyzer; private final Cache queryResultCache; private final Cache pinnedQueryResultCache; + private final ExecutorService searchExecutor; public ShardReader(int shardNumber, DirectoryReader indexReader, DirectoryTaxonomyReader taxoReader, ServerIndexConfig indexConfig, ZuliaPerFieldAnalyzer zuliaPerFieldAnalyzer) { @@ -79,12 +82,14 @@ public ShardReader(int shardNumber, DirectoryReader indexReader, DirectoryTaxono this.zuliaPerFieldAnalyzer = zuliaPerFieldAnalyzer; this.queryResultCache = Caffeine.newBuilder().maximumSize(indexConfig.getIndexSettings().getShardQueryCacheSize()).recordStats().build(); this.pinnedQueryResultCache = Caffeine.newBuilder().recordStats().build(); + this.searchExecutor = Executors.newVirtualThreadPerTaskExecutor(); } @Override public void close() throws Exception { indexReader.close(); taxoReader.close(); + searchExecutor.shutdown(); } public long getCreationTime() { @@ -195,7 +200,7 @@ private ZuliaQuery.ShardQueryResponse getShardQueryResponseAndCache(QueryCacheKe private ZuliaQuery.ShardQueryResponse.Builder getShardQueryResponseAndCache(ShardQuery shardQuery) throws Exception { PerFieldSimilarityWrapper similarity = getSimilarity(shardQuery.getSimilarityOverrideMap()); - IndexSearcher indexSearcher = new IndexSearcher(indexReader); + IndexSearcher indexSearcher = new IndexSearcher(indexReader, searchExecutor); //similarity is only set query time, indexing time all these similarities are the same indexSearcher.setSimilarity(similarity);