Skip to content

Commit 5b2d1a5

Browse files
authored
Limit processors by available processors (#44894)
This commit limits the processors setting to be more than the number of available processors.
1 parent 337ad06 commit 5b2d1a5

File tree

4 files changed

+28
-34
lines changed

4 files changed

+28
-34
lines changed

docs/reference/migration/migrate_8_0/settings.asciidoc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,13 @@ provided automatic upgrading of these settings to their `cluster.remote`
1111
counterparts. In 8.0.0, these settings have been removed. Elasticsearch will
1212
refuse to start if you have these settings in your configuration or cluster
1313
state.
14+
15+
[float]
16+
==== `processors` can no longer exceed the available number of processors
17+
18+
Previously it was possible to set the number of processors used to set the
19+
default sizes for the thread pools to be more than the number of available
20+
processors. As this leads to more context switches and more threads but without
21+
an increase in the number of physical CPUs on which to schedule these additional
22+
threads, the `processors` setting is now bounded by the number of available
23+
processors.

server/src/main/java/org/elasticsearch/common/util/concurrent/EsExecutors.java

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919

2020
package org.elasticsearch.common.util.concurrent;
2121

22-
import org.apache.logging.log4j.LogManager;
2322
import org.elasticsearch.ExceptionsHelper;
2423
import org.elasticsearch.common.SuppressForbidden;
25-
import org.elasticsearch.common.logging.DeprecationLogger;
2624
import org.elasticsearch.common.settings.Setting;
2725
import org.elasticsearch.common.settings.Setting.Property;
2826
import org.elasticsearch.common.settings.Settings;
@@ -48,26 +46,14 @@
4846

4947
public class EsExecutors {
5048

51-
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(EsExecutors.class));
52-
5349
/**
5450
* Setting to manually set the number of available processors. This setting is used to adjust thread pool sizes per node.
5551
*/
56-
public static final Setting<Integer> PROCESSORS_SETTING = new Setting<>(
52+
public static final Setting<Integer> PROCESSORS_SETTING = Setting.intSetting(
5753
"processors",
58-
s -> Integer.toString(Runtime.getRuntime().availableProcessors()),
59-
s -> {
60-
final int value = Setting.parseInt(s, 1, "processors");
61-
final int availableProcessors = Runtime.getRuntime().availableProcessors();
62-
if (value > availableProcessors) {
63-
deprecationLogger.deprecatedAndMaybeLog(
64-
"processors",
65-
"setting processors to value [{}] which is more than available processors [{}] is deprecated",
66-
value,
67-
availableProcessors);
68-
}
69-
return value;
70-
},
54+
Runtime.getRuntime().availableProcessors(),
55+
1,
56+
Runtime.getRuntime().availableProcessors(),
7157
Property.NodeScope);
7258

7359
/**

server/src/test/java/org/elasticsearch/common/util/concurrent/EsExecutorsTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import static org.hamcrest.Matchers.anyOf;
3333
import static org.hamcrest.Matchers.containsString;
3434
import static org.hamcrest.Matchers.equalTo;
35+
import static org.hamcrest.Matchers.hasToString;
3536
import static org.hamcrest.Matchers.lessThan;
3637

3738
/**
@@ -388,4 +389,15 @@ public void testGetTasks() throws InterruptedException {
388389
}
389390
}
390391

392+
public void testProcessorsBound() {
393+
final int available = Runtime.getRuntime().availableProcessors();
394+
final int processors = randomIntBetween(available + 1, Integer.MAX_VALUE);
395+
final Settings settings = Settings.builder().put("processors", processors).build();
396+
final IllegalArgumentException e =
397+
expectThrows(IllegalArgumentException.class, () -> EsExecutors.PROCESSORS_SETTING.get(settings));
398+
assertThat(
399+
e,
400+
hasToString(containsString("Failed to parse value [" + processors + "] for setting [processors] must be <= " + available)));
401+
}
402+
391403
}

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,8 @@ public void testScalingThreadPoolConfiguration() throws InterruptedException {
4848
core = "generic".equals(threadPoolName) ? 4 : 1; // the defaults
4949
}
5050

51-
final int availableProcessors = Runtime.getRuntime().availableProcessors();
52-
final int maxBasedOnNumberOfProcessors;
53-
final int processorsUsed;
54-
if (randomBoolean()) {
55-
final int processors = randomIntBetween(1, 64);
56-
maxBasedOnNumberOfProcessors = expectedSize(threadPoolName, processors);
57-
builder.put("processors", processors);
58-
processorsUsed = processors;
59-
} else {
60-
maxBasedOnNumberOfProcessors = expectedSize(threadPoolName, availableProcessors);
61-
processorsUsed = availableProcessors;
62-
}
51+
final int processors = randomIntBetween(1, Runtime.getRuntime().availableProcessors());
52+
final int maxBasedOnNumberOfProcessors = expectedSize(threadPoolName, processors);
6353

6454
final int expectedMax;
6555
if (maxBasedOnNumberOfProcessors < core || randomBoolean()) {
@@ -98,10 +88,6 @@ public void testScalingThreadPoolConfiguration() throws InterruptedException {
9888
assertThat(esThreadPoolExecutor.getMaximumPoolSize(), equalTo(expectedMax));
9989
});
10090

101-
if (processorsUsed > availableProcessors) {
102-
assertWarnings("setting processors to value [" + processorsUsed +
103-
"] which is more than available processors [" + availableProcessors + "] is deprecated");
104-
}
10591
}
10692

10793
private int expectedSize(final String threadPoolName, final int numberOfProcessors) {

0 commit comments

Comments
 (0)