-
Notifications
You must be signed in to change notification settings - Fork 29k
SPARK-6954. [YARN] ExecutorAllocationManager can end up requesting a negative n... #5704
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
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,13 +27,20 @@ import org.apache.spark.util.{ThreadUtils, Clock, SystemClock, Utils} | |
| /** | ||
| * An agent that dynamically allocates and removes executors based on the workload. | ||
| * | ||
| * The add policy depends on whether there are backlogged tasks waiting to be scheduled. If | ||
| * the scheduler queue is not drained in N seconds, then new executors are added. If the queue | ||
| * persists for another M seconds, then more executors are added and so on. The number added | ||
| * in each round increases exponentially from the previous round until an upper bound on the | ||
| * number of executors has been reached. The upper bound is based both on a configured property | ||
| * and on the number of tasks pending: the policy will never increase the number of executor | ||
| * requests past the number needed to handle all pending tasks. | ||
| * The ExecutorAllocationManager maintains a moving target number of executors which is periodically | ||
| * synced to the cluster manager. The target starts at a configured initial value and changes with | ||
| * the number of pending and running tasks. | ||
| * | ||
| * Decreasing the target number of executors happens when the current target is more than needed to | ||
| * handle the current load. The target number of executors is always truncated to the number of | ||
| * executors that could run all current running and pending tasks at once. | ||
| * | ||
| * Increasing the target number of executors happens in response to backlogged tasks waiting to be | ||
| * scheduled. If the scheduler queue is not drained in N seconds, then new executors are added. If | ||
| * the queue persists for another M seconds, then more executors are added and so on. The number | ||
| * added in each round increases exponentially from the previous round until an upper bound has been | ||
| * reached. The upper bound is based both on a configured property and on the current number of | ||
| * running and pending tasks, as described above. | ||
| * | ||
| * The rationale for the exponential increase is twofold: (1) Executors should be added slowly | ||
| * in the beginning in case the number of extra executors needed turns out to be small. Otherwise, | ||
|
|
@@ -105,8 +112,10 @@ private[spark] class ExecutorAllocationManager( | |
| // Number of executors to add in the next round | ||
| private var numExecutorsToAdd = 1 | ||
|
|
||
| // Number of executors that have been requested but have not registered yet | ||
| private var numExecutorsPending = 0 | ||
| // The desired number of executors at this moment in time. If all our executors were to die, this | ||
| // is the number of executors we would immediately want from the cluster manager. | ||
| private var numExecutorsTarget = | ||
| conf.getInt("spark.dynamicAllocation.initialExecutors", minNumExecutors) | ||
|
|
||
| // Executors that have been requested to be removed but have not been killed yet | ||
| private val executorsPendingToRemove = new mutable.HashSet[String] | ||
|
|
@@ -199,13 +208,6 @@ private[spark] class ExecutorAllocationManager( | |
| executor.awaitTermination(10, TimeUnit.SECONDS) | ||
| } | ||
|
|
||
| /** | ||
| * The number of executors we would have if the cluster manager were to fulfill all our existing | ||
| * requests. | ||
| */ | ||
| private def targetNumExecutors(): Int = | ||
| numExecutorsPending + executorIds.size - executorsPendingToRemove.size | ||
|
|
||
| /** | ||
| * The maximum number of executors we would need under the current load to satisfy all running | ||
| * and pending tasks, rounded up. | ||
|
|
@@ -227,7 +229,7 @@ private[spark] class ExecutorAllocationManager( | |
| private def schedule(): Unit = synchronized { | ||
| val now = clock.getTimeMillis | ||
|
|
||
| addOrCancelExecutorRequests(now) | ||
| updateAndSyncNumExecutorsTarget(now) | ||
|
|
||
| removeTimes.retain { case (executorId, expireTime) => | ||
| val expired = now >= expireTime | ||
|
|
@@ -239,26 +241,28 @@ private[spark] class ExecutorAllocationManager( | |
| } | ||
|
|
||
| /** | ||
| * Updates our target number of executors and syncs the result with the cluster manager. | ||
| * | ||
| * Check to see whether our existing allocation and the requests we've made previously exceed our | ||
| * current needs. If so, let the cluster manager know so that it can cancel pending requests that | ||
| * are unneeded. | ||
| * current needs. If so, truncate our target and let the cluster manager know so that it can | ||
| * cancel pending requests that are unneeded. | ||
| * | ||
| * If not, and the add time has expired, see if we can request new executors and refresh the add | ||
| * time. | ||
| * | ||
| * @return the delta in the target number of executors. | ||
| */ | ||
| private def addOrCancelExecutorRequests(now: Long): Int = synchronized { | ||
| val currentTarget = targetNumExecutors | ||
| private def updateAndSyncNumExecutorsTarget(now: Long): Int = synchronized { | ||
| val maxNeeded = maxNumExecutorsNeeded | ||
|
|
||
| if (maxNeeded < currentTarget) { | ||
| if (maxNeeded < numExecutorsTarget) { | ||
| // The target number exceeds the number we actually need, so stop adding new | ||
| // executors and inform the cluster manager to cancel the extra pending requests. | ||
| val newTotalExecutors = math.max(maxNeeded, minNumExecutors) | ||
| client.requestTotalExecutors(newTotalExecutors) | ||
| // executors and inform the cluster manager to cancel the extra pending requests | ||
| val oldNumExecutorsTarget = numExecutorsTarget | ||
| numExecutorsTarget = math.max(maxNeeded, minNumExecutors) | ||
| client.requestTotalExecutors(numExecutorsTarget) | ||
| numExecutorsToAdd = 1 | ||
| updateNumExecutorsPending(newTotalExecutors) | ||
| numExecutorsTarget - oldNumExecutorsTarget | ||
| } else if (addTime != NOT_SET && now >= addTime) { | ||
| val delta = addExecutors(maxNeeded) | ||
| logDebug(s"Starting timer to add more executors (to " + | ||
|
|
@@ -281,21 +285,30 @@ private[spark] class ExecutorAllocationManager( | |
| */ | ||
| private def addExecutors(maxNumExecutorsNeeded: Int): Int = { | ||
| // Do not request more executors if it would put our target over the upper bound | ||
| val currentTarget = targetNumExecutors | ||
| if (currentTarget >= maxNumExecutors) { | ||
| logDebug(s"Not adding executors because there are already ${executorIds.size} " + | ||
| s"registered and $numExecutorsPending pending executor(s) (limit $maxNumExecutors)") | ||
| if (numExecutorsTarget >= maxNumExecutors) { | ||
| val numExecutorsPending = numExecutorsTarget - executorIds.size | ||
| logDebug(s"Not adding executors because there are already ${executorIds.size} registered" + | ||
| s"and ${numExecutorsPending} pending executor(s) (limit $maxNumExecutors)") | ||
| numExecutorsToAdd = 1 | ||
| return 0 | ||
| } | ||
|
|
||
| val actualMaxNumExecutors = math.min(maxNumExecutors, maxNumExecutorsNeeded) | ||
| val newTotalExecutors = math.min(currentTarget + numExecutorsToAdd, actualMaxNumExecutors) | ||
| val addRequestAcknowledged = testing || client.requestTotalExecutors(newTotalExecutors) | ||
| val oldNumExecutorsTarget = numExecutorsTarget | ||
| // There's no point in wasting time ramping up to the number of executors we already have, so | ||
| // make sure our target is at least as much as our current allocation: | ||
| numExecutorsTarget = math.max(numExecutorsTarget, executorIds.size) | ||
| // Boost our target with the amount to add for this round: | ||
|
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: with the number to add (executors are countable!) |
||
| numExecutorsTarget += numExecutorsToAdd | ||
| // Ensure that our target doesn't exceed what we need at the present moment: | ||
| numExecutorsTarget = math.min(numExecutorsTarget, maxNumExecutorsNeeded) | ||
| // Ensure that our target fits within configured bounds: | ||
| numExecutorsTarget = math.max(math.min(numExecutorsTarget, maxNumExecutors), minNumExecutors) | ||
|
|
||
| val addRequestAcknowledged = testing || client.requestTotalExecutors(numExecutorsTarget) | ||
| if (addRequestAcknowledged) { | ||
| val delta = updateNumExecutorsPending(newTotalExecutors) | ||
| val delta = numExecutorsTarget - oldNumExecutorsTarget | ||
| logInfo(s"Requesting $delta new executor(s) because tasks are backlogged" + | ||
| s" (new desired total will be $newTotalExecutors)") | ||
| s" (new desired total will be $numExecutorsTarget)") | ||
| numExecutorsToAdd = if (delta == numExecutorsToAdd) { | ||
| numExecutorsToAdd * 2 | ||
| } else { | ||
|
|
@@ -304,23 +317,11 @@ private[spark] class ExecutorAllocationManager( | |
| delta | ||
| } else { | ||
| logWarning( | ||
| s"Unable to reach the cluster manager to request $newTotalExecutors total executors!") | ||
| s"Unable to reach the cluster manager to request $numExecutorsTarget total executors!") | ||
| 0 | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Given the new target number of executors, update the number of pending executor requests, | ||
| * and return the delta from the old number of pending requests. | ||
| */ | ||
| private def updateNumExecutorsPending(newTotalExecutors: Int): Int = { | ||
| val newNumExecutorsPending = | ||
| newTotalExecutors - executorIds.size + executorsPendingToRemove.size | ||
| val delta = newNumExecutorsPending - numExecutorsPending | ||
| numExecutorsPending = newNumExecutorsPending | ||
| delta | ||
| } | ||
|
|
||
| /** | ||
| * Request the cluster manager to remove the given executor. | ||
| * Return whether the request is received. | ||
|
|
@@ -372,10 +373,6 @@ private[spark] class ExecutorAllocationManager( | |
| // as idle again so as not to forget that it is a candidate for removal. (see SPARK-4951) | ||
| executorIds.filter(listener.isExecutorIdle).foreach(onExecutorIdle) | ||
| logInfo(s"New executor $executorId has registered (new total is ${executorIds.size})") | ||
| if (numExecutorsPending > 0) { | ||
| numExecutorsPending -= 1 | ||
| logDebug(s"Decremented number of pending executors ($numExecutorsPending left)") | ||
| } | ||
| } else { | ||
| logWarning(s"Duplicate executor $executorId has registered") | ||
| } | ||
|
|
||
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.
nit: insert a space before 'and'