Skip to content

Commit 931503c

Browse files
committed
Limit processors by available processors
This commit limits the processors setting to be more than the number of available processors.
1 parent 16a4aa5 commit 931503c

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

docs/reference/migration/migrate_8_0/settings.asciidoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,12 @@ 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 processors.

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

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,14 @@
4848

4949
public class EsExecutors {
5050

51-
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(EsExecutors.class));
52-
5351
/**
5452
* Setting to manually set the number of available processors. This setting is used to adjust thread pool sizes per node.
5553
*/
56-
public static final Setting<Integer> PROCESSORS_SETTING = new Setting<>(
54+
public static final Setting<Integer> PROCESSORS_SETTING = Setting.intSetting(
5755
"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-
},
56+
Runtime.getRuntime().availableProcessors(),
57+
1,
58+
Runtime.getRuntime().availableProcessors(),
7159
Property.NodeScope);
7260

7361
/**

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@
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;
37+
import static org.hamcrest.Matchers.matchesPattern;
38+
import static org.hamcrest.Matchers.matchesRegex;
3639

3740
/**
3841
* Tests for EsExecutors and its components like EsAbortPolicy.
@@ -388,4 +391,15 @@ public void testGetTasks() throws InterruptedException {
388391
}
389392
}
390393

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

0 commit comments

Comments
 (0)