Skip to content

Commit 162e4cd

Browse files
committed
feature flag
1 parent 6ef45dd commit 162e4cd

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

distribution/tools/server-cli/src/main/java/org/elasticsearch/server/cli/MachineDependentHeap.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import org.elasticsearch.cluster.node.DiscoveryNodeRole;
1313
import org.elasticsearch.common.settings.Settings;
14+
import org.elasticsearch.common.util.FeatureFlag;
1415
import org.elasticsearch.node.NodeRoleSettings;
1516

1617
import java.io.IOException;
@@ -37,6 +38,8 @@ public class MachineDependentHeap {
3738
protected static final long MAX_HEAP_SIZE = GB * 31; // 31GB
3839
protected static final long MIN_HEAP_SIZE = 1024 * 1024 * 128; // 128MB
3940

41+
private static final FeatureFlag NEW_ML_MEMORY_COMPUTATION_FEATURE_FLAG = new FeatureFlag("new_ml_memory_computation");
42+
4043
public MachineDependentHeap() {}
4144

4245
/**
@@ -102,8 +105,12 @@ protected int getHeapSizeMb(Settings nodeSettings, MachineNodeRole role, long av
102105
* could result in ML processes crashing with OOM errors or repeated autoscaling up and down.
103106
*/
104107
case ML_ONLY -> {
105-
double heapFractionBelow16GB = 0.4 / (1.0 + JvmErgonomics.DIRECT_MEMORY_TO_HEAP_FACTOR);
106-
double heapFractionAbove16GB = 0.1 / (1.0 + JvmErgonomics.DIRECT_MEMORY_TO_HEAP_FACTOR);
108+
double heapFractionBelow16GB = 0.4;
109+
double heapFractionAbove16GB = 0.1;
110+
if (NEW_ML_MEMORY_COMPUTATION_FEATURE_FLAG.isEnabled()) {
111+
heapFractionBelow16GB = 0.4 / (1.0 + JvmErgonomics.DIRECT_MEMORY_TO_HEAP_FACTOR);
112+
heapFractionAbove16GB = 0.1 / (1.0 + JvmErgonomics.DIRECT_MEMORY_TO_HEAP_FACTOR);
113+
}
107114
if (availableMemory <= GB * 16) {
108115
yield mb((long) (availableMemory * heapFractionBelow16GB), 4);
109116
} else {

distribution/tools/server-cli/src/test/java/org/elasticsearch/server/cli/MachineDependentHeapTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public void testMasterOnlyOptions() throws Exception {
5656
}
5757

5858
public void testMlOnlyOptions() throws Exception {
59+
System.setProperty("es.kill_new_ml_memory_computation_feature_flag_enabled", "false");
5960
assertHeapOptions(1, containsInAnyOrder("-Xmx272m", "-Xms272m"), "ml");
6061
assertHeapOptions(4, containsInAnyOrder("-Xmx1092m", "-Xms1092m"), "ml");
6162
assertHeapOptions(32, containsInAnyOrder("-Xmx5460m", "-Xms5460m"), "ml");

server/src/main/java/org/elasticsearch/common/util/FeatureFlag.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public static FeatureFlag legacyRegisteredFlag(String name) {
6969
assert name.contains("feature_flag") == false : "Feature flag names may not contain the string 'feature_flag'";
7070

7171
final String propertyName = "es." + name + "_feature_flag_" + suffix;
72+
System.out.println("Feature flag system property name: " + propertyName);
7273
if (build.isSnapshot()) {
7374
enabled = parseSystemProperty(getSystemProperty, propertyName, true);
7475
if (enabled == false) {

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.elasticsearch.common.settings.SettingsModule;
4242
import org.elasticsearch.common.unit.ByteSizeValue;
4343
import org.elasticsearch.common.unit.Processors;
44+
import org.elasticsearch.common.util.FeatureFlag;
4445
import org.elasticsearch.common.util.concurrent.EsExecutors;
4546
import org.elasticsearch.core.TimeValue;
4647
import org.elasticsearch.env.Environment;
@@ -557,6 +558,8 @@ public class MachineLearning extends Plugin
557558
License.OperationMode.PLATINUM
558559
);
559560

561+
private static final FeatureFlag NEW_ML_MEMORY_COMPUTATION_FEATURE_FLAG = new FeatureFlag("new_ml_memory_computation");
562+
560563
@Override
561564
public Map<String, Processor.Factory> getProcessors(Processor.Parameters parameters) {
562565
if (this.enabled == false) {
@@ -846,7 +849,11 @@ public Settings additionalSettings() {
846849
Long.toString(OsProbe.getInstance().osStats().getMem().getAdjustedTotal().getBytes())
847850
);
848851

849-
addMlNodeAttribute(additionalSettings, jvmSizeAttrName, Long.toString(JvmInfo.jvmInfo().getMem().getTotalMax().getBytes()));
852+
long jvmSize = Runtime.getRuntime().maxMemory();
853+
if (NEW_ML_MEMORY_COMPUTATION_FEATURE_FLAG.isEnabled()) {
854+
jvmSize = JvmInfo.jvmInfo().getMem().getTotalMax().getBytes();
855+
}
856+
addMlNodeAttribute(additionalSettings, jvmSizeAttrName, Long.toString(jvmSize));
850857
addMlNodeAttribute(
851858
additionalSettings,
852859
deprecatedAllocatedProcessorsAttrName,

0 commit comments

Comments
 (0)