You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2020/01/25 17:19:35 UTC

[GitHub] [flink] tillrohrmann commented on a change in pull request #10946: [FLINK-15763][Runtime] Running TM checks only necessary resource cofig, set to default for local execution

tillrohrmann commented on a change in pull request #10946: [FLINK-15763][Runtime] Running TM checks only necessary resource cofig, set to default for local execution
URL: https://github.com/apache/flink/pull/10946#discussion_r370944239
 
 

 ##########
 File path: flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskExecutorResourceUtils.java
 ##########
 @@ -0,0 +1,179 @@
+/*
+ * 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.runtime.taskexecutor;
+
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.api.common.resources.CPUResource;
+import org.apache.flink.configuration.ConfigOption;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.IllegalConfigurationException;
+import org.apache.flink.configuration.MemorySize;
+import org.apache.flink.configuration.ReadableConfig;
+import org.apache.flink.configuration.TaskManagerOptions;
+import org.apache.flink.runtime.clusterframework.types.ResourceProfile;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Utility class for {@link TaskExecutorResourceSpec} of running {@link TaskExecutor}.
+ */
+public class TaskExecutorResourceUtils {
+	private static final Logger LOG = LoggerFactory.getLogger(TaskExecutorResourceUtils.class);
+
+	static final List<ConfigOption<?>> CONFIG_OPTIONS = Arrays.asList(
+		TaskManagerOptions.CPU_CORES,
+		TaskManagerOptions.TASK_HEAP_MEMORY,
+		TaskManagerOptions.TASK_OFF_HEAP_MEMORY,
+		TaskManagerOptions.NETWORK_MEMORY_MIN,
+		TaskManagerOptions.NETWORK_MEMORY_MAX,
+		TaskManagerOptions.MANAGED_MEMORY_SIZE
+	);
+
+	private static final List<ConfigOption<?>> UNUSED_CONFIG_OPTIONS = Arrays.asList(
+		TaskManagerOptions.TOTAL_PROCESS_MEMORY,
+		TaskManagerOptions.TOTAL_FLINK_MEMORY,
+		TaskManagerOptions.FRAMEWORK_HEAP_MEMORY,
+		TaskManagerOptions.FRAMEWORK_OFF_HEAP_MEMORY,
+		TaskManagerOptions.JVM_METASPACE,
+		TaskManagerOptions.JVM_OVERHEAD_MIN,
+		TaskManagerOptions.JVM_OVERHEAD_MAX,
+		TaskManagerOptions.JVM_OVERHEAD_FRACTION
+	);
+
+	static final MemorySize DEFAULT_SHUFFLE_MEMORY_SIZE = MemorySize.parse("64m");
+	static final MemorySize DEFAULT_MANAGED_MEMORY_SIZE = MemorySize.parse("128m");
+
+	private TaskExecutorResourceUtils() {}
+
+	static TaskExecutorResourceSpec resourceSpecFromConfig(Configuration config) {
+		try {
+			checkTaskExecutorResourceConfigSet(config);
+		} catch (IllegalConfigurationException e) {
+			throw new IllegalConfigurationException("Failed to create TaskExecutorResourceSpec", e);
+		}
+		return new TaskExecutorResourceSpec(
+			new CPUResource(config.getDouble(TaskManagerOptions.CPU_CORES)),
+			config.get(TaskManagerOptions.TASK_HEAP_MEMORY),
+			config.get(TaskManagerOptions.TASK_OFF_HEAP_MEMORY),
+			config.get(TaskManagerOptions.NETWORK_MEMORY_MIN),
+			config.get(TaskManagerOptions.MANAGED_MEMORY_SIZE)
+		);
+	}
+
+	private static void checkTaskExecutorResourceConfigSet(Configuration config) {
+		CONFIG_OPTIONS.forEach(option -> checkConfigOptionIsSet(config, option));
+		checkTaskExecutorNetworkConfigSet(config);
+	}
+
+	private static void checkTaskExecutorNetworkConfigSet(ReadableConfig config) {
+		if (!config.get(TaskManagerOptions.NETWORK_MEMORY_MIN).equals(config.get(TaskManagerOptions.NETWORK_MEMORY_MAX))) {
+			throw new IllegalConfigurationException(
+				"The network memory min (%s) and max (%s) mismatch, " +
+					"the network memory has to be fixed after task executor has started",
+				config.get(TaskManagerOptions.NETWORK_MEMORY_MIN),
+				config.get(TaskManagerOptions.NETWORK_MEMORY_MAX));
+		}
+	}
 
 Review comment:
   Is this condition required? If min and max are not equal, then we should be able to take any value from the specified range (e.g. the minimum).

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services