-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-29976][CORE] Trigger speculation for stages with too few tasks #26614
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
13 commits
Select commit
Hold shift + click to select a range
bc0f7e1
new conf for single task stage speculation
yuchenhuo 58362cd
address comments
yuchenhuo 48b90b8
global threshold for speculation
yuchenhuo d427c69
update comments
yuchenhuo 1cd95a6
update tests
yuchenhuo 8e505ca
add doc
yuchenhuo 7ac8bbe
address comments
yuchenhuo 2f9b65b
add tests
yuchenhuo 1dcd5d3
nits and configuration
yuchenhuo bf22446
check the total number of tasks instead of number of unfinished tasks
yuchenhuo 93c2859
nits
yuchenhuo 274bcd1
fix bug and refactor test
yuchenhuo 181bd89
add test
yuchenhuo 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 |
|---|---|---|
|
|
@@ -1778,6 +1778,104 @@ class TaskSetManagerSuite extends SparkFunSuite with LocalSparkContext with Logg | |
| assert(manager.resourceOffer("exec1", "host1", ANY).isEmpty) | ||
| } | ||
|
|
||
| private def testSpeculationDurationSetup( | ||
| speculationThresholdOpt: Option[String], | ||
| speculationQuantile: Double, | ||
| numTasks: Int, | ||
| numSlots: Int): (TaskSetManager, ManualClock) = { | ||
| sc = new SparkContext("local", "test") | ||
| sc.conf.set(config.SPECULATION_ENABLED, true) | ||
| sc.conf.set(config.SPECULATION_QUANTILE.key, speculationQuantile.toString) | ||
| // Set the number of slots per executor | ||
| sc.conf.set(config.EXECUTOR_CORES.key, numSlots.toString) | ||
| sc.conf.set(config.CPUS_PER_TASK.key, "1") | ||
| if (speculationThresholdOpt.isDefined) { | ||
| sc.conf.set(config.SPECULATION_TASK_DURATION_THRESHOLD.key, speculationThresholdOpt.get) | ||
| } | ||
| sched = new FakeTaskScheduler(sc, ("exec1", "host1"), ("exec2", "host2")) | ||
| // Create a task set with the given number of tasks | ||
| val taskSet = FakeTask.createTaskSet(numTasks) | ||
| val clock = new ManualClock() | ||
| val manager = new TaskSetManager(sched, taskSet, MAX_TASK_FAILURES, clock = clock) | ||
| manager.isZombie = false | ||
|
|
||
| // Offer resources for the task to start | ||
| for (i <- 1 to numTasks) { | ||
| manager.resourceOffer(s"exec$i", s"host$i", NO_PREF) | ||
| } | ||
| (manager, clock) | ||
| } | ||
|
|
||
| private def testSpeculationDurationThreshold( | ||
| speculationThresholdProvided: Boolean, | ||
| numTasks: Int, | ||
| numSlots: Int): Unit = { | ||
| val (manager, clock) = testSpeculationDurationSetup( | ||
| // Set the threshold to be 60 minutes | ||
| if (speculationThresholdProvided) Some("60min") else None, | ||
| // Set the quantile to be 1.0 so that regular speculation would not be triggered | ||
| 1.0, | ||
| numTasks, | ||
| numSlots | ||
| ) | ||
|
|
||
| // if the time threshold has not been exceeded, no speculative run should be triggered | ||
| clock.advance(1000*60*60) | ||
| assert(!manager.checkSpeculatableTasks(0)) | ||
| assert(sched.speculativeTasks.size == 0) | ||
|
|
||
| // Now the task should have been running for 60 minutes and 1 second | ||
| clock.advance(1) | ||
| if (speculationThresholdProvided && numSlots >= numTasks) { | ||
| assert(manager.checkSpeculatableTasks(0)) | ||
| assert(sched.speculativeTasks.size == numTasks) | ||
| // Should not submit duplicated tasks | ||
| assert(!manager.checkSpeculatableTasks(0)) | ||
| assert(sched.speculativeTasks.size == numTasks) | ||
| } else { | ||
| // If the feature flag is turned off, or the stage contains too many tasks | ||
| assert(!manager.checkSpeculatableTasks(0)) | ||
| assert(sched.speculativeTasks.size == 0) | ||
| } | ||
| } | ||
|
|
||
| Seq(1, 2).foreach { numTasks => | ||
| test("SPARK-29976 when a speculation time threshold is provided, should speculative " + | ||
| s"run the task even if there are not enough successful runs, total tasks: $numTasks") { | ||
| testSpeculationDurationThreshold(true, numTasks, numTasks) | ||
| } | ||
|
|
||
| test("SPARK-29976: when the speculation time threshold is not provided," + | ||
| s"don't speculative run if there are not enough successful runs, total tasks: $numTasks") { | ||
| testSpeculationDurationThreshold(false, numTasks, numTasks) | ||
| } | ||
| } | ||
|
|
||
| test("SPARK-29976 when a speculation time threshold is provided, should not speculative " + | ||
| "if there are too many tasks in the stage even though time threshold is provided") { | ||
| testSpeculationDurationThreshold(true, 2, 1) | ||
| } | ||
|
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. it would be nice to add anther test here that that test interaction of the speculative configs. Meaning I have both the threshold set and the speculation quantile is smaller, the threshold can still apply and vice versa, the quantile can still apply. |
||
|
|
||
| test("SPARK-29976 Regular speculation configs should still take effect even when a " + | ||
| "threshold is provided") { | ||
| val (manager, clock) = testSpeculationDurationSetup( | ||
| Some("60min"), | ||
| speculationQuantile = 0.5, | ||
| numTasks = 2, | ||
| numSlots = 2 | ||
| ) | ||
|
|
||
| // Task duration can't be 0, advance 1 sec | ||
| clock.advance(1000) | ||
| // Mark one of the task succeeded, which should satisfy the quantile | ||
| manager.handleSuccessfulTask(0, createTaskResult(0)) | ||
| // Advance 1 more second so the remaining task takes longer than medium but doesn't satisfy the | ||
| // duration threshold yet | ||
| clock.advance(1000) | ||
| assert(manager.checkSpeculatableTasks(0)) | ||
| assert(sched.speculativeTasks.size == 1) | ||
| } | ||
|
|
||
| test("TaskOutputFileAlreadyExistException lead to task set abortion") { | ||
| sc = new SparkContext("local", "test") | ||
| sched = new FakeTaskScheduler(sc, ("exec1", "host1")) | ||
|
|
||
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
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.
can we add a simple
.docto explain what this config does?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.
Do I need to change https://github.com/apache/spark/blob/master/docs/configuration.md?
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.
yes please