-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-49057][SQL] Do not block the AQE loop when submitting query stages #47533
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
3 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
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 |
|---|---|---|
|
|
@@ -27,7 +27,7 @@ import scala.util.control.NonFatal | |
| import org.apache.spark.{broadcast, SparkException} | ||
| import org.apache.spark.internal.LogKeys._ | ||
| import org.apache.spark.internal.MDC | ||
| import org.apache.spark.rdd.RDD | ||
| import org.apache.spark.rdd.{RDD, RDDOperationScope} | ||
| import org.apache.spark.sql.catalyst.InternalRow | ||
| import org.apache.spark.sql.catalyst.expressions.UnsafeRow | ||
| import org.apache.spark.sql.catalyst.plans.logical.Statistics | ||
|
|
@@ -61,23 +61,49 @@ trait BroadcastExchangeLike extends Exchange { | |
| */ | ||
| def relationFuture: Future[broadcast.Broadcast[Any]] | ||
|
|
||
| @transient | ||
| private lazy val promise = Promise[Unit]() | ||
|
|
||
| @transient | ||
| private lazy val scalaFuture: scala.concurrent.Future[Unit] = promise.future | ||
|
|
||
| @transient | ||
| private lazy val triggerFuture: Future[Any] = { | ||
| SQLExecution.withThreadLocalCaptured(session, BroadcastExchangeExec.executionContext) { | ||
| try { | ||
| // Trigger broadcast preparation which can involve expensive operations like waiting on | ||
| // subqueries and file listing. | ||
| executeQuery(null) | ||
| promise.trySuccess(()) | ||
| } catch { | ||
| case e: Throwable => | ||
| promise.tryFailure(e) | ||
| throw e | ||
| } | ||
| } | ||
| } | ||
|
|
||
| protected def completionFuture: scala.concurrent.Future[broadcast.Broadcast[Any]] | ||
|
|
||
| /** | ||
| * The asynchronous job that materializes the broadcast. It's used for registering callbacks on | ||
| * `relationFuture`. Note that calling this method may not start the execution of broadcast job. | ||
| * It also does the preparations work, such as waiting for the subqueries. | ||
| */ | ||
| final def submitBroadcastJob: scala.concurrent.Future[broadcast.Broadcast[Any]] = executeQuery { | ||
ulysses-you marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| materializationStarted.set(true) | ||
| completionFuture | ||
| final def submitBroadcastJob(): scala.concurrent.Future[broadcast.Broadcast[Any]] = { | ||
| triggerFuture | ||
| scalaFuture.flatMap { _ => | ||
| RDDOperationScope.withScope(sparkContext, nodeName, false, true) { | ||
| completionFuture | ||
| } | ||
| }(BroadcastExchangeExec.executionContext) | ||
| } | ||
|
|
||
| protected def completionFuture: scala.concurrent.Future[broadcast.Broadcast[Any]] | ||
|
|
||
| /** | ||
| * Cancels broadcast job with an optional reason. | ||
| */ | ||
| final def cancelBroadcastJob(reason: Option[String]): Unit = { | ||
| if (isMaterializationStarted() && !this.relationFuture.isDone) { | ||
| if (!this.relationFuture.isDone) { | ||
|
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 do not re-implement broadcast cancellation, as we need more refactoring to move the creation of |
||
| reason match { | ||
| case Some(r) => sparkContext.cancelJobsWithTag(this.jobTag, r) | ||
| case None => sparkContext.cancelJobsWithTag(this.jobTag) | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.
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 you explain why we pick this number? It might create memory pressure on the driver
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.
The shuffle async job is just waiting for other work (subquery expression execution) to finish, which is very light-weighted. The broadcast async job executes a query and collects the result in the driver, which is very heavy. That's why we can give much larger parallelism to the shuffle async jobs. In our benchmark we found this number is reasonably good for TPC.
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.
Is there a correlation with the number of system cores?
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.
I don't think so, the
BROADCAST_EXCHANGE_MAX_THREAD_THRESHOLDis also way larger than the driver system cores.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.
I'm not sure if this parameter has anything to do with SPARK-49091 or if it was just caused by SPARK-41914 which the reporter pointed to.
Also cc @wangyum
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.
Update: SPARK-49091 is not related