Skip to content

Commit beadcaf

Browse files
authored
Increase force_merge threadpool size (#87082)
Changes the default size used for the force_merge threadpool to 1/8 of the allocated processors, with a minimum value of 1. Closes #84943
1 parent fbf335d commit beadcaf

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

docs/changelog/87082.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 87082
2+
summary: Increase `force_merge` threadpool size based on the allocated processors
3+
area: Engine
4+
type: enhancement
5+
issues:
6+
- 84943

docs/reference/modules/threadpool.asciidoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ There are several thread pools, but the important ones include:
7979

8080
`force_merge`::
8181
For <<indices-forcemerge,force merge>> operations.
82-
Thread pool type is `fixed` with a size of 1 and an unbounded queue size.
82+
Thread pool type is `fixed` with a size of `max(1, (`<<node.processors,
83+
`# of allocated processors`>>`) / 8)` and an unbounded queue size.
8384

8485
`management`::
8586
For cluster management.

server/src/main/java/org/elasticsearch/threadpool/ThreadPool.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,10 @@ public ThreadPool(final Settings settings, final ExecutorBuilder<?>... customBui
219219
Names.FETCH_SHARD_STARTED,
220220
new ScalingExecutorBuilder(Names.FETCH_SHARD_STARTED, 1, 2 * allocatedProcessors, TimeValue.timeValueMinutes(5), false)
221221
);
222-
builders.put(Names.FORCE_MERGE, new FixedExecutorBuilder(settings, Names.FORCE_MERGE, 1, -1, false));
222+
builders.put(
223+
Names.FORCE_MERGE,
224+
new FixedExecutorBuilder(settings, Names.FORCE_MERGE, oneEighthAllocatedProcessors(allocatedProcessors), -1, false)
225+
);
223226
builders.put(Names.CLUSTER_COORDINATION, new FixedExecutorBuilder(settings, Names.CLUSTER_COORDINATION, 1, -1, false));
224227
builders.put(
225228
Names.FETCH_SHARD_STORE,
@@ -551,6 +554,10 @@ static int twiceAllocatedProcessors(final int allocatedProcessors) {
551554
return boundedBy(2 * allocatedProcessors, 2, Integer.MAX_VALUE);
552555
}
553556

557+
static int oneEighthAllocatedProcessors(final int allocatedProcessors) {
558+
return boundedBy(allocatedProcessors / 8, 1, Integer.MAX_VALUE);
559+
}
560+
554561
public static int searchThreadPoolSize(final int allocatedProcessors) {
555562
return ((allocatedProcessors * 3) / 2) + 1;
556563
}

server/src/test/java/org/elasticsearch/threadpool/ThreadPoolTests.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ public void testBoundedByBetweenMinAndMax() {
5151
assertThat(ThreadPool.boundedBy(value, min, max), equalTo(value));
5252
}
5353

54+
public void testOneEighthAllocatedProcessors() {
55+
assertThat(ThreadPool.oneEighthAllocatedProcessors(1), equalTo(1));
56+
assertThat(ThreadPool.oneEighthAllocatedProcessors(4), equalTo(1));
57+
assertThat(ThreadPool.oneEighthAllocatedProcessors(8), equalTo(1));
58+
assertThat(ThreadPool.oneEighthAllocatedProcessors(32), equalTo(4));
59+
}
60+
5461
public void testAbsoluteTime() throws Exception {
5562
TestThreadPool threadPool = new TestThreadPool("test");
5663
try {
@@ -304,4 +311,21 @@ public String toString() {
304311
assertTrue(terminate(threadPool));
305312
}
306313
}
314+
315+
public void testForceMergeThreadPoolSize() {
316+
final int allocatedProcessors = randomIntBetween(1, EsExecutors.allocatedProcessors(Settings.EMPTY));
317+
final ThreadPool threadPool = new TestThreadPool(
318+
"test",
319+
Settings.builder().put(EsExecutors.NODE_PROCESSORS_SETTING.getKey(), allocatedProcessors).build()
320+
);
321+
try {
322+
final int expectedSize = Math.max(1, allocatedProcessors / 8);
323+
ThreadPool.Info info = threadPool.info(ThreadPool.Names.FORCE_MERGE);
324+
assertThat(info.getThreadPoolType(), equalTo(ThreadPool.ThreadPoolType.FIXED));
325+
assertThat(info.getMin(), equalTo(expectedSize));
326+
assertThat(info.getMax(), equalTo(expectedSize));
327+
} finally {
328+
assertTrue(terminate(threadPool));
329+
}
330+
}
307331
}

0 commit comments

Comments
 (0)