squito commented on a change in pull request #26284: [SPARK-29415][Core]Stage Level Sched: Add base ResourceProfile and Request classes URL: https://github.com/apache/spark/pull/26284#discussion_r343797341
########## File path: core/src/main/scala/org/apache/spark/resource/ResourceProfile.scala ########## @@ -0,0 +1,186 @@ +/* + * 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.spark.resource + +import java.util.{Map => JMap} +import java.util.concurrent.atomic.{AtomicInteger, AtomicReference} + +import scala.collection.JavaConverters._ +import scala.collection.immutable.HashSet +import scala.collection.mutable + +import org.apache.spark.SparkConf +import org.apache.spark.annotation.Evolving +import org.apache.spark.internal.Logging +import org.apache.spark.internal.config._ +import org.apache.spark.resource.ResourceUtils.{RESOURCE_DOT, RESOURCE_PREFIX} + +/** + * Resource profile to associate with an RDD. A ResourceProfile allows the user to + * specify executor and task requirements for an RDD that will get applied during a + * stage. This allows the user to change the resource requirements between stages. + * + * Only supports a subset of the resources for now. The config names supported correspond to the + * regular Spark configs with the prefix removed. For instance overhead memory in this api + * is memoryOverhead, which is spark.executor.memoryOverhead with spark.executor removed. + * Resources like GPUs are resource.gpu (spark configs spark.executor.resource.gpu.*) + * + * Executor: + * memory - heap + * memoryOverhead + * pyspark.memory + * cores + * resource.[resourceName] - GPU, FPGA, etc + * + * Task requirements: + * cpus + * resource.[resourceName] - GPU, FPGA, etc + * + * This class is private now for initial development, once we have the feature in place + * this will become public. + */ +@Evolving +private[spark] class ResourceProfile() extends Serializable { + + private val _id = ResourceProfile.getNextProfileId + private val _taskResources = new mutable.HashMap[String, TaskResourceRequest]() + private val _executorResources = new mutable.HashMap[String, ExecutorResourceRequest]() + + private val allowedExecutorResources = HashSet[String]( + ResourceProfile.MEMORY, + ResourceProfile.OVERHEAD_MEM, + ResourceProfile.PYSPARK_MEM, + ResourceProfile.CORES) + + private val allowedTaskResources = HashSet[String](ResourceProfile.CPUS) + + def id: Int = _id + + def taskResources: Map[String, TaskResourceRequest] = _taskResources.toMap + + def executorResources: Map[String, ExecutorResourceRequest] = _executorResources.toMap + + /** + * (Java-specific) gets a Java Map of resources to TaskResourceRequest + */ + def taskResourcesJMap: JMap[String, TaskResourceRequest] = _taskResources.asJava + + /** + * (Java-specific) gets a Java Map of resources to ExecutorResourceRequest + */ + def executorResourcesJMap: JMap[String, ExecutorResourceRequest] = _executorResources.asJava + + + def reset(): Unit = { + _taskResources.clear() + _executorResources.clear() + } + + def require(request: TaskResourceRequest): this.type = { + val rName = request.resourceName + if (allowedTaskResources.contains(rName) || rName.startsWith(RESOURCE_DOT)) { Review comment: can you do these checks in the constructors of TaskResourceRequest and ExecutorResourceRequest instead? also, is there any advantage to having these be strings instead of Enums? If we really want to enforce its a closed universe here, then enum seems better? ---------------------------------------------------------------- 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: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
