diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/BatchingMultipleIndexPopulator.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/BatchingMultipleIndexPopulator.java index 2f106054eba15..a06a01870dd81 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/BatchingMultipleIndexPopulator.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/BatchingMultipleIndexPopulator.java @@ -75,7 +75,8 @@ public class BatchingMultipleIndexPopulator extends MultipleIndexPopulator private static final String FLUSH_THREAD_NAME_PREFIX = "Index Population Flush Thread"; private final int QUEUE_THRESHOLD = FeatureToggles.getInteger( getClass(), QUEUE_THRESHOLD_NAME, 20_000 ); - private final int TASK_QUEUE_SIZE = FeatureToggles.getInteger( getClass(), TASK_QUEUE_SIZE_NAME, 10_000 ); + private final int TASK_QUEUE_SIZE = FeatureToggles.getInteger( getClass(), TASK_QUEUE_SIZE_NAME, + getNumberOfPopulationWorkers() * 2 ); private final int AWAIT_TIMEOUT_MINUTES = FeatureToggles.getInteger( getClass(), AWAIT_TIMEOUT_MINUTES_NAME, 30 ); private final int BATCH_SIZE = FeatureToggles.getInteger( getClass(), BATCH_SIZE_NAME, 10_000 ); @@ -304,7 +305,7 @@ private List newBatch() private ExecutorService createThreadPool() { - int threads = Math.max( 2, Runtime.getRuntime().availableProcessors() - 1 ); + int threads = getNumberOfPopulationWorkers(); BlockingQueue workQueue = new LinkedBlockingQueue<>( TASK_QUEUE_SIZE ); ThreadFactory threadFactory = daemon( FLUSH_THREAD_NAME_PREFIX ); RejectedExecutionHandler rejectedExecutionHandler = new ThreadPoolExecutor.CallerRunsPolicy(); @@ -327,6 +328,16 @@ private static String allStackTraces() .collect( joining() ); } + /** + * Calculate number of workers that will perform index population + * + * @return number of threads that will be used for index population + */ + private static int getNumberOfPopulationWorkers() + { + return Math.max( 2, Runtime.getRuntime().availableProcessors() - 1 ); + } + /** * An {@link IndexPopulation} that does not insert updates one by one into the index but instead adds them to the * map containing batches of updates for each index.