mxm commented on code in PR #762: URL: https://github.com/apache/flink-kubernetes-operator/pull/762#discussion_r1478016552
########## flink-autoscaler/src/main/java/org/apache/flink/autoscaler/utils/MemoryTuningUtils.java: ########## @@ -0,0 +1,203 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.autoscaler.utils; + +import org.apache.flink.autoscaler.JobAutoScalerContext; +import org.apache.flink.autoscaler.config.AutoScalerOptions; +import org.apache.flink.autoscaler.metrics.EvaluatedMetrics; +import org.apache.flink.autoscaler.metrics.ScalingMetric; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.configuration.MemorySize; +import org.apache.flink.configuration.StateBackendOptions; +import org.apache.flink.configuration.TaskManagerOptions; +import org.apache.flink.configuration.UnmodifiableConfiguration; +import org.apache.flink.runtime.util.config.memory.JvmMetaspaceAndOverheadOptions; +import org.apache.flink.runtime.util.config.memory.ProcessMemoryOptions; +import org.apache.flink.runtime.util.config.memory.ProcessMemoryUtils; +import org.apache.flink.runtime.util.config.memory.taskmanager.TaskExecutorFlinkMemory; +import org.apache.flink.runtime.util.config.memory.taskmanager.TaskExecutorFlinkMemoryUtils; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Arrays; + +import static org.apache.commons.lang3.math.Fraction.getFraction; + +/** Tunes the TaskManager memory. */ +public class MemoryTuningUtils { + + private static final Logger LOG = LoggerFactory.getLogger(MemoryTuningUtils.class); + public static final ProcessMemoryUtils<TaskExecutorFlinkMemory> FLINK_MEMORY_UTILS = + new ProcessMemoryUtils<>(getMemoryOptions(), new TaskExecutorFlinkMemoryUtils()); + + /** + * Emits a Configuration which contains overrides for the current configuration. We are not + * modifying the config directly, but we are emitting a new configuration which contains any + * overrides. This config is persisted separately and applied by the autoscaler. That way we can + * clear any applied overrides if auto-tuning is disabled. + */ + public static Configuration tuneTaskManagerHeapMemory( + JobAutoScalerContext<?> context, EvaluatedMetrics evaluatedMetrics) { + + // Please note that this config is the original configuration created from the user spec. + // It does not contain any already applied overrides. + var config = new UnmodifiableConfiguration(context.getConfiguration()); Review Comment: Thanks Rui! I originally had another method on the context to retrieve the original config ("deploy" config). Let me see if we need that. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org