-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-28577][YARN]Resource capability requested for each executor add offHeapMemorySize #25309
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 7 commits
13b81d2
ff9e2e4
cd27192
c44a33e
9421fbe
c0ef860
4fb5362
66ae9a1
c03db87
8f37ca1
40ad336
0020a02
02c0f2a
b3b5f83
bb29488
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 |
|---|---|---|
|
|
@@ -97,6 +97,8 @@ private[spark] class Client( | |
|
|
||
| // Executor related configurations | ||
| private val executorMemory = sparkConf.get(EXECUTOR_MEMORY) | ||
| // Executor offHeap memory in MiB. | ||
| protected val executorOffHeapMemory = YarnSparkHadoopUtil.executorOffHeapMemorySizeAsMb(sparkConf) | ||
| private val executorMemoryOverhead = sparkConf.get(EXECUTOR_MEMORY_OVERHEAD).getOrElse( | ||
| math.max((MEMORY_OVERHEAD_FACTOR * executorMemory).toLong, MEMORY_OVERHEAD_MIN)).toInt | ||
|
|
||
|
|
@@ -346,12 +348,14 @@ private[spark] class Client( | |
| val maxMem = newAppResponse.getMaximumResourceCapability().getMemory() | ||
| logInfo("Verifying our application has not requested more than the maximum " + | ||
| s"memory capability of the cluster ($maxMem MB per container)") | ||
| val executorMem = executorMemory + executorMemoryOverhead + pysparkWorkerMemory | ||
| val executorMem = | ||
| executorMemory + executorOffHeapMemory +executorMemoryOverhead + pysparkWorkerMemory | ||
| if (executorMem > maxMem) { | ||
| throw new IllegalArgumentException(s"Required executor memory ($executorMemory), overhead " + | ||
| s"($executorMemoryOverhead MB), and PySpark memory ($pysparkWorkerMemory MB) is above " + | ||
| s"the max threshold ($maxMem MB) of this cluster! Please check the values of " + | ||
| s"'yarn.scheduler.maximum-allocation-mb' and/or 'yarn.nodemanager.resource.memory-mb'.") | ||
| throw new IllegalArgumentException(s"Required executor memory ($executorMemory MB), " + | ||
| s"offHeap memory ($executorOffHeapMemory) MB, overhead ($executorMemoryOverhead MB), " + | ||
| s"and PySpark memory ($pysparkWorkerMemory MB) is above the max threshold ($maxMem MB) " + | ||
| s"of this cluster! Please check the values of 'yarn.scheduler.maximum-allocation-mb' " + | ||
| s"and/or 'yarn.nodemanager.resource.memory-mb'.") | ||
|
||
| } | ||
| val amMem = amMemory + amMemoryOverhead | ||
| if (amMem > maxMem) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -131,6 +131,8 @@ private[yarn] class YarnAllocator( | |
|
|
||
| // Executor memory in MiB. | ||
| protected val executorMemory = sparkConf.get(EXECUTOR_MEMORY).toInt | ||
| // Executor offHeap memory in MiB. | ||
| protected val executorOffHeapMemory = YarnSparkHadoopUtil.executorOffHeapMemorySizeAsMb(sparkConf) | ||
| // Additional memory overhead. | ||
| protected val memoryOverhead: Int = sparkConf.get(EXECUTOR_MEMORY_OVERHEAD).getOrElse( | ||
| math.max((MEMORY_OVERHEAD_FACTOR * executorMemory).toInt, MEMORY_OVERHEAD_MIN)).toInt | ||
|
|
@@ -149,7 +151,7 @@ private[yarn] class YarnAllocator( | |
| // Resource capability requested for each executor | ||
| private[yarn] val resource: Resource = { | ||
| val resource = Resource.newInstance( | ||
| executorMemory + memoryOverhead + pysparkWorkerMemory, executorCores) | ||
| executorMemory + executorOffHeapMemory + memoryOverhead + pysparkWorkerMemory, executorCores) | ||
|
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. According line 258 to 260 in
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. Described in the document is
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. Yes, this makes me confused.
Member
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. Isn't this what
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. @srowen |
||
| ResourceRequestHelper.setResourceRequests(executorResourceRequests, resource) | ||
| logDebug(s"Created resource capability: $resource") | ||
| resource | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -26,9 +26,8 @@ import org.apache.hadoop.yarn.api.records.{ApplicationAccessType, ContainerId, P | |||
| import org.apache.hadoop.yarn.util.ConverterUtils | ||||
|
|
||||
| import org.apache.spark.{SecurityManager, SparkConf} | ||||
| import org.apache.spark.internal.config._ | ||||
| import org.apache.spark.launcher.YarnCommandBuilderUtils | ||||
| import org.apache.spark.resource.ResourceID | ||||
| import org.apache.spark.resource.ResourceUtils._ | ||||
| import org.apache.spark.util.Utils | ||||
|
|
||||
| object YarnSparkHadoopUtil { | ||||
|
|
@@ -184,4 +183,18 @@ object YarnSparkHadoopUtil { | |||
| ConverterUtils.toContainerId(containerIdString) | ||||
| } | ||||
|
|
||||
| /** | ||||
| * Convert MEMORY_OFFHEAP_SIZE to MB Unit, return 0 if MEMORY_OFFHEAP_ENABLED is false. | ||||
| */ | ||||
| def executorOffHeapMemorySizeAsMb(sparkConf: SparkConf): Int = { | ||||
| if (sparkConf.get(MEMORY_OFFHEAP_ENABLED)) { | ||||
| val sizeInMB = | ||||
| sparkConf.getSizeAsMb(MEMORY_OFFHEAP_SIZE.key, MEMORY_OFFHEAP_SIZE.defaultValueString).toInt | ||||
|
||||
| require(sizeInMB > 0, | ||||
| s"${MEMORY_OFFHEAP_SIZE.key} must be > 0 when ${MEMORY_OFFHEAP_ENABLED.key} == true") | ||||
|
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. Please check if
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.
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. Then I think we should change the code 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. 0 is defaultValue, change to ?
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. Maybe we should give a suitable defaultValue ,like 1073741824(1g)?
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. @jerryshao Do we need to change 0 to a suitable defaultValue?
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. I see, then I would suggest not to change it. Seems there's no good value which could cover most of the scenarios, so good to leave as it is.
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~
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. its odd that check is >= 0 in the config, seems like we should change but can you file a separate jira for that?
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 add a new jira to discuss this issue. |
||||
| sizeInMB | ||||
| } else { | ||||
| 0 | ||||
| } | ||||
| } | ||||
| } | ||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ import org.scalatest.Matchers | |
| import org.apache.spark.{SecurityManager, SparkConf, SparkFunSuite} | ||
| import org.apache.spark.deploy.SparkHadoopUtil | ||
| import org.apache.spark.internal.Logging | ||
| import org.apache.spark.internal.config._ | ||
| import org.apache.spark.internal.config.UI._ | ||
| import org.apache.spark.util.{ResetSystemProperties, Utils} | ||
|
|
||
|
|
@@ -140,4 +141,31 @@ class YarnSparkHadoopUtilSuite extends SparkFunSuite with Matchers with Logging | |
| } | ||
|
|
||
| } | ||
|
|
||
| test("executorOffHeapMemorySizeAsMb when MEMORY_OFFHEAP_ENABLED is false") { | ||
| val executorOffHeapMemory = YarnSparkHadoopUtil.executorOffHeapMemorySizeAsMb(new SparkConf()) | ||
| assert(executorOffHeapMemory == 0) | ||
| } | ||
|
|
||
| test("executorOffHeapMemorySizeAsMb when MEMORY_OFFHEAP_ENABLED is true") { | ||
| val offHeapMemoryInMB = 50 | ||
| val offHeapMemory: Long = offHeapMemoryInMB * 1024 * 1024 | ||
| val sparkConf = new SparkConf() | ||
| .set(MEMORY_OFFHEAP_ENABLED, true) | ||
| .set(MEMORY_OFFHEAP_SIZE, offHeapMemory) | ||
| val executorOffHeapMemory = YarnSparkHadoopUtil.executorOffHeapMemorySizeAsMb(sparkConf) | ||
| assert(executorOffHeapMemory == offHeapMemoryInMB) | ||
| } | ||
|
|
||
| test("executorMemoryOverhead when MEMORY_OFFHEAP_ENABLED is true, " + | ||
|
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. Just wondering if we could add some yarn side UT to verify the container memory size, rather than verifying the correctness of off-heap configuration.
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'll try to add it.
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. Add a new test suite |
||
| "but MEMORY_OFFHEAP_SIZE not config scene") { | ||
| val sparkConf = new SparkConf() | ||
| .set(MEMORY_OFFHEAP_ENABLED, true) | ||
| val expected = | ||
| s"${MEMORY_OFFHEAP_SIZE.key} must be > 0 when ${MEMORY_OFFHEAP_ENABLED.key} == true" | ||
| val message = intercept[IllegalArgumentException] { | ||
| YarnSparkHadoopUtil.executorOffHeapMemorySizeAsMb(sparkConf) | ||
| }.getMessage | ||
| assert(message.contains(expected)) | ||
| } | ||
| } | ||

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.
white space after
+.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.
ok