-
Notifications
You must be signed in to change notification settings - Fork 29k
[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 14 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,89 @@ | ||
| /* | ||
| * 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
Show resolved
Hide resolved
|
||
| */ | ||
| private[spark] object ResourceDiscoverer extends Logging { | ||
|
|
||
| private implicit val formats = DefaultFormats | ||
|
|
||
| def findResources(sparkconf: SparkConf, isDriver: Boolean): Map[String, ResourceInformation] = { | ||
|
||
| val prefix = if (isDriver) { | ||
| SPARK_DRIVER_RESOURCE_PREFIX | ||
| } else { | ||
| SPARK_EXECUTOR_RESOURCE_PREFIX | ||
| } | ||
| // get unique resource types by grabbing first part config with multiple periods, | ||
| // ie resourceType.count, grab resourceType part | ||
| val resourceTypes = sparkconf.getAllWithPrefix(prefix).map { case (k, _) => | ||
tgravescs marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| k.split('.').head | ||
| }.toSet | ||
| resourceTypes.map { rtype => { | ||
| val rInfo = getResourceAddrsForType(sparkconf, prefix, rtype) | ||
| (rtype -> rInfo) | ||
| }}.toMap | ||
| } | ||
|
|
||
| private def getResourceAddrsForType( | ||
tgravescs marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| sparkconf: SparkConf, | ||
tgravescs marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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) => | ||
| 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,41 @@ | ||
| /* | ||
| * 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 units are resource specific and could be something like MB or GB for memory. | ||
| * 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 don't apply to that resource. | ||
| * | ||
| * 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 | ||
|
||
| * @param count the number of resources available | ||
|
||
| * @param addresses an optional array of strings describing the addresses of the resource | ||
| */ | ||
| @Evolving | ||
| case class ResourceInformation( | ||
tgravescs marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| val name: String, | ||
| val units: String, | ||
| val count: Long, | ||
| val addresses: Array[String] = Array.empty) | ||
Uh oh!
There was an error while loading. Please reload this page.