99
1010package org .elasticsearch .server .cli ;
1111
12+ import org .apache .logging .log4j .LogManager ;
13+ import org .apache .logging .log4j .Logger ;
14+ import org .elasticsearch .cli .Terminal ;
1215import org .elasticsearch .cluster .node .DiscoveryNodeRole ;
1316import org .elasticsearch .common .settings .Settings ;
1417import org .elasticsearch .common .util .FeatureFlag ;
@@ -40,7 +43,19 @@ public class MachineDependentHeap {
4043
4144 private static final FeatureFlag NEW_ML_MEMORY_COMPUTATION_FEATURE_FLAG = new FeatureFlag ("new_ml_memory_computation" );
4245
43- public MachineDependentHeap () {}
46+ private static final Logger logger = LogManager .getLogger (MachineDependentHeap .class );
47+
48+ private final Terminal terminal ;
49+
50+ private boolean useNewMlMemoryComputation = false ;
51+
52+ public MachineDependentHeap () {
53+ this .terminal = null ;
54+ }
55+
56+ public MachineDependentHeap (Terminal terminal ) {
57+ this .terminal = terminal ;
58+ }
4459
4560 /**
4661 * Calculate heap options.
@@ -55,8 +70,30 @@ public final List<String> determineHeapSettings(
5570 SystemMemoryInfo systemMemoryInfo ,
5671 List <String > userDefinedJvmOptions
5772 ) throws IOException , InterruptedException {
73+ if (userDefinedJvmOptions .contains ("-Des.new_ml_memory_computation_feature_flag_enabled=true" )
74+ || NEW_ML_MEMORY_COMPUTATION_FEATURE_FLAG .isEnabled ()) {
75+ useNewMlMemoryComputation = true ;
76+ }
5877 // TODO: this could be more efficient, to only parse final options once
5978 final Map <String , JvmOption > finalJvmOptions = JvmOption .findFinalOptions (userDefinedJvmOptions );
79+ if (terminal != null ) {
80+ terminal .println ("@@@ contains -Des.new_ml_memory_computation_feature_flag_enabled=true --> "
81+ + userDefinedJvmOptions .contains ("-Des.new_ml_memory_computation_feature_flag_enabled=true" ));
82+ terminal .println ("@@@ contains -Des.inference_default_elser_feature_flag_enabled=true --> "
83+ + userDefinedJvmOptions .contains ("-Des.inference_default_elser_feature_flag_enabled=true" ));
84+ terminal .println ("@@@ MachineDependentHeap userDefinedJvmOptions: " + userDefinedJvmOptions );
85+
86+ terminal .println (
87+ "@@@ MachineDependentHeap determineHeapSettings: MaxHeap="
88+ + finalJvmOptions .get ("MaxHeapSize" )
89+ + " FeatureFlag="
90+ + NEW_ML_MEMORY_COMPUTATION_FEATURE_FLAG .isEnabled ()
91+ );
92+ terminal .println ("@@@ MachineDependentHeap determineHeapSettings: inference_default_elser_feature_flag="
93+ + new FeatureFlag ("inference_default_elser" ).isEnabled ());
94+ terminal .println ("@@@ USER DEFINED OPTIONS = " + userDefinedJvmOptions );
95+ terminal .println ("@@@ FINAL OPTIONS = " + finalJvmOptions );
96+ }
6097 if (isMaxHeapSpecified (finalJvmOptions ) || isMinHeapSpecified (finalJvmOptions ) || isInitialHeapSpecified (finalJvmOptions )) {
6198 // User has explicitly set memory settings so we use those
6299 return Collections .emptyList ();
@@ -65,6 +102,12 @@ public final List<String> determineHeapSettings(
65102 List <DiscoveryNodeRole > roles = NodeRoleSettings .NODE_ROLES_SETTING .get (nodeSettings );
66103 long availableSystemMemory = systemMemoryInfo .availableSystemMemory ();
67104 MachineNodeRole nodeRole = mapNodeRole (roles );
105+ if (terminal != null ) {
106+ terminal .println (
107+ "@@@ MachineDependentHeap determineHeapSettings: setMaxHeap: "
108+ + getHeapSizeMb (nodeSettings , nodeRole , availableSystemMemory )
109+ );
110+ }
68111 return options (getHeapSizeMb (nodeSettings , nodeRole , availableSystemMemory ));
69112 }
70113
@@ -107,7 +150,7 @@ protected int getHeapSizeMb(Settings nodeSettings, MachineNodeRole role, long av
107150 case ML_ONLY -> {
108151 double heapFractionBelow16GB = 0.4 ;
109152 double heapFractionAbove16GB = 0.1 ;
110- if (NEW_ML_MEMORY_COMPUTATION_FEATURE_FLAG . isEnabled () ) {
153+ if (useNewMlMemoryComputation ) {
111154 heapFractionBelow16GB = 0.4 / (1.0 + JvmErgonomics .DIRECT_MEMORY_TO_HEAP_FACTOR );
112155 heapFractionAbove16GB = 0.1 / (1.0 + JvmErgonomics .DIRECT_MEMORY_TO_HEAP_FACTOR );
113156 }
0 commit comments