-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-27959][YARN] Change YARN resource configs to use .amount #24989
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
Closed
tgravescs
wants to merge
6
commits into
apache:master
from
tgravescs:SPARK-27959-yarn-resourceconfigs
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
481abaf
[SPARK-27959] Change YARN resource configs to use .amount
tgravescs bef554b
Fix unit test
tgravescs 428f63a
fix conflicting resources
tgravescs 0d87d08
Fix tests for change to .amount
tgravescs 6af9988
fix import order:
tgravescs 6e86ab9
rework
tgravescs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,11 +26,11 @@ import scala.util.Try | |
| import org.apache.hadoop.yarn.api.records.Resource | ||
|
|
||
| import org.apache.spark.{SparkConf, SparkException} | ||
| import org.apache.spark.deploy.yarn.YarnSparkHadoopUtil._ | ||
| import org.apache.spark.deploy.yarn.config._ | ||
| import org.apache.spark.internal.Logging | ||
| import org.apache.spark.internal.config._ | ||
| import org.apache.spark.resource.ResourceID | ||
| import org.apache.spark.resource.ResourceUtils.{AMOUNT, FPGA, GPU} | ||
| import org.apache.spark.util.{CausedBy, Utils} | ||
|
|
||
| /** | ||
|
|
@@ -40,6 +40,45 @@ import org.apache.spark.util.{CausedBy, Utils} | |
| private object ResourceRequestHelper extends Logging { | ||
| private val AMOUNT_AND_UNIT_REGEX = "([0-9]+)([A-Za-z]*)".r | ||
| private val RESOURCE_INFO_CLASS = "org.apache.hadoop.yarn.api.records.ResourceInformation" | ||
| val YARN_GPU_RESOURCE_CONFIG = "yarn.io/gpu" | ||
| val YARN_FPGA_RESOURCE_CONFIG = "yarn.io/fpga" | ||
|
|
||
| private[yarn] def getYarnResourcesAndAmounts( | ||
| sparkConf: SparkConf, | ||
| componentName: String): Map[String, String] = { | ||
|
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. Nit: in |
||
| sparkConf.getAllWithPrefix(s"$componentName").map { case (key, value) => | ||
| val splitIndex = key.lastIndexOf('.') | ||
| if (splitIndex == -1) { | ||
| val errorMessage = s"Missing suffix for ${componentName}${key}, you must specify" + | ||
| s" a suffix - $AMOUNT is currently the only supported suffix." | ||
| throw new IllegalArgumentException(errorMessage.toString()) | ||
| } | ||
| val resourceName = key.substring(0, splitIndex) | ||
| val resourceSuffix = key.substring(splitIndex + 1) | ||
| if (!AMOUNT.equals(resourceSuffix)) { | ||
| val errorMessage = s"Unsupported suffix: $resourceSuffix in: ${componentName}${key}, " + | ||
| s"only .$AMOUNT is supported." | ||
| throw new IllegalArgumentException(errorMessage.toString()) | ||
| } | ||
| (resourceName, value) | ||
| }.toMap | ||
| } | ||
|
|
||
| /** | ||
| * Convert Spark resources into YARN resources. | ||
| * The only resources we know how to map from spark configs to yarn configs are | ||
| * gpus and fpgas, everything else the user has to specify them in both the | ||
| * spark.yarn.*.resource and the spark.*.resource configs. | ||
| */ | ||
| private[yarn] def getYarnResourcesFromSparkResources( | ||
| confPrefix: String, | ||
| sparkConf: SparkConf | ||
| ): Map[String, String] = { | ||
| Map(GPU -> YARN_GPU_RESOURCE_CONFIG, FPGA -> YARN_FPGA_RESOURCE_CONFIG).map { | ||
| case (rName, yarnName) => | ||
| (yarnName -> sparkConf.get(ResourceID(confPrefix, rName).amountConf, "0")) | ||
| }.filter { case (_, count) => count.toLong > 0 } | ||
| } | ||
|
|
||
| /** | ||
| * Validates sparkConf and throws a SparkException if any of standard resources (memory or cores) | ||
|
|
@@ -81,8 +120,9 @@ private object ResourceRequestHelper extends Logging { | |
| val errorMessage = new mutable.StringBuilder() | ||
|
|
||
| resourceDefinitions.foreach { case (sparkName, resourceRequest) => | ||
| if (sparkConf.contains(resourceRequest)) { | ||
| errorMessage.append(s"Error: Do not use $resourceRequest, " + | ||
| val resourceRequestAmount = s"${resourceRequest}.${AMOUNT}" | ||
| if (sparkConf.contains(resourceRequestAmount)) { | ||
| errorMessage.append(s"Error: Do not use $resourceRequestAmount, " + | ||
| s"please use $sparkName instead!\n") | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to reuse
ResourceUtils.GPUandResourceUtils.FPGAhere?Like:
For suggesting using as close mapping as possible between the Spark config keys and YARN resource config keys (now and the future).
I know your PR does not touched this part:
spark/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/ResourceRequestHelper.scala
Lines 111 to 118 in 6e86ab9
But at that place using the right constant (
$GPUor$FPGA) instead of the string literal is reasonable.