-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-27024] Executor interface for cluster managers to support GPU and other resources #24406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
5905f51
916991e
6ff9953
bee34a0
6170342
4bbaf2a
55a3bd5
eb0a8ed
abff33f
484a086
e90582a
d2ed08f
c07b405
01f97c8
b5afbd0
dd5b765
a9642b8
01a6061
9187c6d
636fef8
3d8e5cd
4165c60
dbb61fb
dd60e42
b9dacef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| /* | ||
| * 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 | ||
|
|
||
| import java.io.File | ||
|
|
||
| import com.fasterxml.jackson.core.JsonParseException | ||
| import org.json4s.{DefaultFormats, MappingException} | ||
| import org.json4s.jackson.JsonMethods._ | ||
|
|
||
| import org.apache.spark.internal.Logging | ||
| import org.apache.spark.internal.config._ | ||
| import org.apache.spark.util.Utils.executeAndGetOutput | ||
|
|
||
| /** | ||
| * Discovers resources (GPUs/FPGAs/etc). | ||
| * This class find resources by running and parses the output of the user specified script | ||
| * from the config spark.{driver/executor}.{resourceType}.discoveryScript. | ||
| * The output of the script it runs is expected to be JSON in the format of the | ||
| * ResourceInformation class, with addresses being optional. | ||
| * | ||
| * For example: {"name": "gpu","count":2, "units":"", "addresses": ["0","1"]} | ||
|
tgravescs marked this conversation as resolved.
Outdated
|
||
| */ | ||
| private[spark] object ResourceDiscoverer extends Logging { | ||
|
|
||
| private implicit val formats = DefaultFormats | ||
|
|
||
| def findResources(sparkconf: SparkConf, isDriver: Boolean): Map[String, ResourceInformation] = { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I agree, there are lots of pieces of code that need to know driver vs executor, to me passing in the prefix is a bit weird because the user has to know what its being used for, with the driver/executor boolean the function can do any number of things with it if needed. |
||
| val prefix = if (isDriver) { | ||
| SPARK_DRIVER_RESOURCE_PREFIX | ||
| } else { | ||
| SPARK_EXECUTOR_RESOURCE_PREFIX | ||
| } | ||
| // get unique resource types | ||
| val resourceTypes = sparkconf.getAllWithPrefix(prefix).map(x => x._1.split('.')(0)).toSet | ||
|
tgravescs marked this conversation as resolved.
Outdated
|
||
| resourceTypes.map{ rtype => { | ||
|
tgravescs marked this conversation as resolved.
Outdated
|
||
| val rInfo = getResourceAddrsForType(sparkconf, prefix, rtype) | ||
| (rtype -> rInfo) | ||
| }}.toMap | ||
| } | ||
|
|
||
| private def getResourceAddrsForType( | ||
|
tgravescs marked this conversation as resolved.
Outdated
|
||
| sparkconf: SparkConf, | ||
|
tgravescs marked this conversation as resolved.
Outdated
|
||
| prefix: String, | ||
| resourceType: String): ResourceInformation = { | ||
| val discoveryConf = prefix + resourceType + SPARK_RESOURCE_DISCOVERY_SCRIPT_POSTFIX | ||
| val script = sparkconf.getOption(discoveryConf) | ||
| val result = if (script.nonEmpty) { | ||
| val scriptFile = new File(script.get) | ||
| // check that script exists and try to execute | ||
| if (scriptFile.exists()) { | ||
| try { | ||
| val output = executeAndGetOutput(Seq(script.get), new File(".")) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any access control concern here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just the normal ones that I think we need to document ( I just added an item to the documentation jira specifically about this.) Normally the script should be sent with the job and needs to have the correct permissions on it, if they point at a script on the system that has been compromised then there are.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In standalone mode, worker needs to run the script provided by users. Could you leave a TODO inline?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what TODO you want me to leave here, standalone mode has its own jira, which I don't know how its going to be designed so don't see why I would leave a TODO in this jira. I would expect that scrip tto not be provided by the users, but by the cluster administrator when they start the workers.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nvm, I was thinking about users might be able to let manager/executor run arbitrary scripts. |
||
| val parsedJson = parse(output) | ||
| parsedJson.extract[ResourceInformation] | ||
| } catch { | ||
| case e@(_: SparkException | _: MappingException | _: JsonParseException) => | ||
|
tgravescs marked this conversation as resolved.
Outdated
|
||
| throw new SparkException(s"Error running the resource discovery script: $scriptFile" + | ||
| s" for $resourceType", e) | ||
| } | ||
| } else { | ||
| throw new SparkException(s"Resource script: $scriptFile to discover $resourceType" + | ||
| s" doesn't exist!") | ||
| } | ||
| } else { | ||
| throw new SparkException(s"User is expecting to use $resourceType resources but " + | ||
| s"didn't specify a script via conf: $discoveryConf, to find them!") | ||
| } | ||
| result | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| * 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 | ||
|
|
||
| import org.apache.spark.annotation.Evolving | ||
|
|
||
| /** | ||
| * Class to hold information about a type of Resource. A resource could be a GPU, FPGA, etc. | ||
| * The array of addresses are resource specific and its up to the user to interpret the address. | ||
| * The units and addresses could be empty if they doesn't apply to that resource. | ||
|
tgravescs marked this conversation as resolved.
Outdated
|
||
| * | ||
| * One example is GPUs, where the addresses would be the indices of the GPUs, the count would be the | ||
| * number of GPUs and the units would be an empty string. | ||
| * | ||
| * @param name the name of the resource | ||
| * @param units the units of the resources, can be an empty string if units don't apply | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is my major feedback to this PR.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok I will remove |
||
| * @param count the number of resources available | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok will remove for now |
||
| * @param addresses an optional array of strings describing the addresses of the resource | ||
| */ | ||
| @Evolving | ||
| case class ResourceInformation( | ||
|
tgravescs marked this conversation as resolved.
Outdated
|
||
| private val name: String, | ||
| private val units: String, | ||
| private val count: Long, | ||
| private val addresses: Array[String] = Array.empty) { | ||
|
|
||
| def getName(): String = name | ||
|
tgravescs marked this conversation as resolved.
Outdated
|
||
| def getUnits(): String = units | ||
| def getCount(): Long = count | ||
| def getAddresses(): Array[String] = addresses | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.