Skip to content

Commit 4d3b886

Browse files
authored
Capture max processors in static init (elastic#97119) (elastic#97122)
The number of processors available to the jvm can change over time. However, most of Elasticsearch assumes this value is constant. Although we could rework all code relying on the number of processors to dynamically support updates and poll the jvm, doing so has little value since the processors changing is an edge case. Instead, this commit fixes validation of the node.processors setting (our internal number of processors) to validate based on the max processors available at launch. closes elastic#97088
1 parent bdd177c commit 4d3b886

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

docs/changelog/97119.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 97119
2+
summary: Capture max processors in static init
3+
area: Infra/Core
4+
type: bug
5+
issues:
6+
- 97088

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535

3636
public class EsExecutors {
3737

38+
// although the available processors may technically change, for node sizing we use the number available at launch
39+
private static final int MAX_NUM_PROCESSORS = Runtime.getRuntime().availableProcessors();
40+
3841
/**
3942
* Setting to manually control the number of allocated processors. This setting is used to adjust thread pool sizes per node. The
4043
* default value is {@link Runtime#availableProcessors()} but should be manually controlled if not all processors on the machine are
@@ -43,7 +46,7 @@ public class EsExecutors {
4346
*/
4447
public static final Setting<Processors> NODE_PROCESSORS_SETTING = new Setting<>(
4548
"node.processors",
46-
Double.toString(Runtime.getRuntime().availableProcessors()),
49+
Double.toString(MAX_NUM_PROCESSORS),
4750
textValue -> {
4851
double numberOfProcessors = Double.parseDouble(textValue);
4952
if (Double.isNaN(numberOfProcessors) || Double.isInfinite(numberOfProcessors)) {
@@ -56,9 +59,8 @@ public class EsExecutors {
5659
throw new IllegalArgumentException(err);
5760
}
5861

59-
final int maxNumberOfProcessors = Runtime.getRuntime().availableProcessors();
60-
if (numberOfProcessors > maxNumberOfProcessors) {
61-
String err = "Failed to parse value [" + textValue + "] for setting [node.processors] must be <= " + maxNumberOfProcessors;
62+
if (numberOfProcessors > MAX_NUM_PROCESSORS) {
63+
String err = "Failed to parse value [" + textValue + "] for setting [node.processors] must be <= " + MAX_NUM_PROCESSORS;
6264
throw new IllegalArgumentException(err);
6365
}
6466
return Processors.of(numberOfProcessors);

0 commit comments

Comments
 (0)