From 38e4b335f5182c0efefc0d88fee733805304f95b Mon Sep 17 00:00:00 2001 From: Gaurav Bafna <85113518+gbbafna@users.noreply.github.com> Date: Thu, 13 Feb 2025 21:18:29 +0530 Subject: [PATCH] Making force merge threadpool 1/8th of total cores (#17255) Signed-off-by: Gaurav Bafna --- CHANGELOG.md | 3 ++- .../main/java/org/opensearch/threadpool/ThreadPool.java | 9 ++++++++- .../java/org/opensearch/threadpool/ThreadPoolTests.java | 8 ++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 739b3b09c1926..d5092745fb825 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Bump `reactor_netty` from 1.1.26 to 1.1.27 ([#17322](https://github.com/opensearch-project/OpenSearch/pull/17322)) ### Changed -- Convert transport-reactor-netty4 to use gradle version catalog [#17233](https://github.com/opensearch-project/OpenSearch/pull/17233)) +- Convert transport-reactor-netty4 to use gradle version catalog [#17233](https://github.com/opensearch-project/OpenSearch/pull/17233) +- Increase force merge threads to 1/8th of cores [#17255](https://github.com/opensearch-project/OpenSearch/pull/17255) ### Deprecated diff --git a/server/src/main/java/org/opensearch/threadpool/ThreadPool.java b/server/src/main/java/org/opensearch/threadpool/ThreadPool.java index 59d3b110aeca8..b67b00bb42054 100644 --- a/server/src/main/java/org/opensearch/threadpool/ThreadPool.java +++ b/server/src/main/java/org/opensearch/threadpool/ThreadPool.java @@ -278,7 +278,10 @@ public ThreadPool( Names.FETCH_SHARD_STARTED, new ScalingExecutorBuilder(Names.FETCH_SHARD_STARTED, 1, 2 * allocatedProcessors, TimeValue.timeValueMinutes(5)) ); - builders.put(Names.FORCE_MERGE, new FixedExecutorBuilder(settings, Names.FORCE_MERGE, 1, -1)); + builders.put( + Names.FORCE_MERGE, + new FixedExecutorBuilder(settings, Names.FORCE_MERGE, oneEighthAllocatedProcessors(allocatedProcessors), -1) + ); builders.put( Names.FETCH_SHARD_STORE, new ScalingExecutorBuilder(Names.FETCH_SHARD_STORE, 1, 2 * allocatedProcessors, TimeValue.timeValueMinutes(5)) @@ -678,6 +681,10 @@ static int boundedBy(int value, int min, int max) { return Math.min(max, Math.max(min, value)); } + static int oneEighthAllocatedProcessors(final int allocatedProcessors) { + return boundedBy(allocatedProcessors / 8, 1, Integer.MAX_VALUE); + } + static int halfAllocatedProcessors(int allocatedProcessors) { return (allocatedProcessors + 1) / 2; } diff --git a/server/src/test/java/org/opensearch/threadpool/ThreadPoolTests.java b/server/src/test/java/org/opensearch/threadpool/ThreadPoolTests.java index 205bf7621c576..fd79115ad5872 100644 --- a/server/src/test/java/org/opensearch/threadpool/ThreadPoolTests.java +++ b/server/src/test/java/org/opensearch/threadpool/ThreadPoolTests.java @@ -196,4 +196,12 @@ public void testThreadPoolResizeFail() { terminate(threadPool); } } + + public void testOneEighthAllocatedProcessors() { + assertThat(ThreadPool.oneEighthAllocatedProcessors(1), equalTo(1)); + assertThat(ThreadPool.oneEighthAllocatedProcessors(4), equalTo(1)); + assertThat(ThreadPool.oneEighthAllocatedProcessors(8), equalTo(1)); + assertThat(ThreadPool.oneEighthAllocatedProcessors(32), equalTo(4)); + assertThat(ThreadPool.oneEighthAllocatedProcessors(128), equalTo(16)); + } }