Skip to content

Commit c3e94ae

Browse files
ashangit1996fanrui
authored andcommitted
[FLINK-35489] Ensure METASPACE size is computed before the heap
If the heap usage with overhead leads to remaining memory to be assigned to the HEAP no memory will be assigned to the METASPACE leading to JVM failure at startup By setting this before the HEAP we ensure the JVM can start with appropriate amount of METASPACE memory
1 parent 1992841 commit c3e94ae

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

flink-autoscaler/src/main/java/org/apache/flink/autoscaler/tuning/MemoryTuning.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,12 @@ public static ConfigChanges tuneTaskManagerMemory(
125125
scalingSummaries, evaluatedMetrics.getVertexMetrics()),
126126
config,
127127
memBudget);
128-
MemorySize newHeapSize =
129-
determineNewSize(getUsage(HEAP_MEMORY_USED, globalMetrics), config, memBudget);
128+
// Assign memory to the METASPACE before the HEAP to ensure all needed memory is provided
129+
// to the METASPACE
130130
MemorySize newMetaspaceSize =
131131
determineNewSize(getUsage(METASPACE_MEMORY_USED, globalMetrics), config, memBudget);
132+
MemorySize newHeapSize =
133+
determineNewSize(getUsage(HEAP_MEMORY_USED, globalMetrics), config, memBudget);
132134
MemorySize newManagedSize =
133135
adjustManagedMemory(
134136
getUsage(MANAGED_MEMORY_USED, globalMetrics),

flink-autoscaler/src/test/java/org/apache/flink/autoscaler/tuning/MemoryTuningTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,34 @@ jobVertex1, new ScalingSummary(50, 25, Map.of()),
208208
TaskManagerOptions.TOTAL_PROCESS_MEMORY.key(),
209209
"14172382822 bytes"));
210210

211+
// Test METASPACE when memory usage is so high that it could take all the memory
212+
metrics = new EvaluatedMetrics(vertexMetrics, new HashMap<>(globalMetrics));
213+
metrics.getGlobalMetrics()
214+
.put(ScalingMetric.HEAP_MEMORY_USED, EvaluatedScalingMetric.avg(30812254720d));
215+
// Set usage to max metaspace usage to ensure the calculation take in account max size
216+
metrics.getGlobalMetrics()
217+
.put(ScalingMetric.METASPACE_MEMORY_USED, EvaluatedScalingMetric.avg(268435456d));
218+
configChanges =
219+
MemoryTuning.tuneTaskManagerMemory(
220+
context, metrics, jobTopology, scalingSummaries, eventHandler);
221+
assertThat(configChanges.getOverrides())
222+
.containsExactlyInAnyOrderEntriesOf(
223+
Map.of(
224+
TaskManagerOptions.MANAGED_MEMORY_FRACTION.key(),
225+
"0.0",
226+
TaskManagerOptions.NETWORK_MEMORY_MIN.key(),
227+
"13760 kb",
228+
TaskManagerOptions.NETWORK_MEMORY_MAX.key(),
229+
"13760 kb",
230+
TaskManagerOptions.JVM_METASPACE.key(),
231+
"322122547 bytes",
232+
TaskManagerOptions.JVM_OVERHEAD_FRACTION.key(),
233+
"0.034",
234+
TaskManagerOptions.FRAMEWORK_HEAP_MEMORY.key(),
235+
"0 bytes",
236+
TaskManagerOptions.TOTAL_PROCESS_MEMORY.key(),
237+
"30 gb"));
238+
211239
// Test tuning disabled
212240
config.set(AutoScalerOptions.MEMORY_TUNING_ENABLED, false);
213241
assertThat(

0 commit comments

Comments
 (0)