You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "beliefer (via GitHub)" <gi...@apache.org> on 2025/02/27 13:41:50 UTC
[PR] [SPARK-51341][SQL] Cancel time task with suitable way. [spark]
beliefer opened a new pull request, #50107:
URL: https://github.com/apache/spark/pull/50107
### What changes were proposed in this pull request?
This PR proposes to cancel task with suitable way.
### Why are the changes needed?
According to the discussion at
https://github.com/apache/spark/pull/47956#issuecomment-2328035086
TimerTask.cancel() doesn't work.
### Does this PR introduce _any_ user-facing change?
'No'.
### How was this patch tested?
GA
### Was this patch authored or co-authored using generative AI tooling?
'No'.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51341][CORE] Cancel time task with suitable way. [spark]
Posted by "beliefer (via GitHub)" <gi...@apache.org>.
beliefer commented on code in PR #50107:
URL: https://github.com/apache/spark/pull/50107#discussion_r1976295039
##########
core/src/main/scala/org/apache/spark/scheduler/TaskSchedulerImpl.scala:
##########
@@ -169,6 +171,7 @@ private[spark] class TaskSchedulerImpl(
protected val executorIdToHost = new HashMap[String, String]
private val abortTimer = ThreadUtils.newDaemonSingleThreadScheduledExecutor("task-abort-timer")
+ private val abortFutures = new CopyOnWriteArrayList[ScheduledFuture[_]]
Review Comment:
Yeah. less reads and more writes here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51341][CORE] Cancel time task with suitable way. [spark]
Posted by "beliefer (via GitHub)" <gi...@apache.org>.
beliefer commented on code in PR #50107:
URL: https://github.com/apache/spark/pull/50107#discussion_r1976289910
##########
core/src/main/scala/org/apache/spark/BarrierTaskContext.scala:
##########
@@ -300,11 +300,7 @@ object BarrierTaskContext {
@Since("2.4.0")
def get(): BarrierTaskContext = TaskContext.get().asInstanceOf[BarrierTaskContext]
- private val timer = {
- val executor = ThreadUtils.newDaemonSingleThreadScheduledExecutor(
- "Barrier task timer for barrier() calls.")
- assert(executor.isInstanceOf[ScheduledThreadPoolExecutor])
- executor.asInstanceOf[ScheduledThreadPoolExecutor]
- }
+ private val timer = ThreadUtils.newSingleThreadScheduledExecutor(
Review Comment:
Because all the `BarrierTaskContext` share the `timer`, so we can't shut down it.
It seems good to revert it with daemon thread.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51341][CORE] Cancel time task with suitable way. [spark]
Posted by "srowen (via GitHub)" <gi...@apache.org>.
srowen commented on code in PR #50107:
URL: https://github.com/apache/spark/pull/50107#discussion_r1979417965
##########
core/src/main/scala/org/apache/spark/scheduler/TaskSchedulerImpl.scala:
##########
@@ -959,7 +965,9 @@ private[spark] class TaskSchedulerImpl(
barrierCoordinator.stop()
}
}
+ starvationFutures.asScala.foreach(_.cancel(false))
Review Comment:
My last concern is, do these Futures build up and cause a potential memory leak? I don't think they hold onto large result objects. The Future itself isn't big either. So maybe not an issue. I don't know of a clean way to delete them on completion of individual tasks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51341][CORE] Cancel time task with suitable way. [spark]
Posted by "beliefer (via GitHub)" <gi...@apache.org>.
beliefer commented on code in PR #50107:
URL: https://github.com/apache/spark/pull/50107#discussion_r1975351020
##########
core/src/main/scala/org/apache/spark/ui/ConsoleProgressBar.scala:
##########
@@ -121,5 +121,8 @@ private[spark] class ConsoleProgressBar(sc: SparkContext) extends Logging {
* Tear down the timer thread. The timer thread is a GC root, and it retains the entire
* SparkContext if it's not terminated.
*/
- def stop(): Unit = ThreadUtils.shutdown(timer)
+ def stop(): Unit = {
+ timerFuture.cancel(true)
+ ThreadUtils.shutdown(timer)
+ }
Review Comment:
Good question!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51341][CORE] Cancel time task with suitable way. [spark]
Posted by "srowen (via GitHub)" <gi...@apache.org>.
srowen commented on code in PR #50107:
URL: https://github.com/apache/spark/pull/50107#discussion_r1975478508
##########
core/src/main/scala/org/apache/spark/scheduler/TaskSchedulerImpl.scala:
##########
@@ -169,6 +171,7 @@ private[spark] class TaskSchedulerImpl(
protected val executorIdToHost = new HashMap[String, String]
private val abortTimer = ThreadUtils.newDaemonSingleThreadScheduledExecutor("task-abort-timer")
+ private val abortFutures = new CopyOnWriteArrayList[ScheduledFuture[_]]
Review Comment:
Why CopyOnWriteArrayList in particular? maybe fine but would a simple synchronized list be easier?
##########
core/src/main/scala/org/apache/spark/BarrierTaskContext.scala:
##########
@@ -300,11 +300,7 @@ object BarrierTaskContext {
@Since("2.4.0")
def get(): BarrierTaskContext = TaskContext.get().asInstanceOf[BarrierTaskContext]
- private val timer = {
- val executor = ThreadUtils.newDaemonSingleThreadScheduledExecutor(
- "Barrier task timer for barrier() calls.")
- assert(executor.isInstanceOf[ScheduledThreadPoolExecutor])
- executor.asInstanceOf[ScheduledThreadPoolExecutor]
- }
+ private val timer = ThreadUtils.newSingleThreadScheduledExecutor(
Review Comment:
This timer is never shut down. Is there a decent place to do it? otherwise, I think daemon is correct here. Non-daemon threads would stop the JVM from exiting, in theory
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51341][CORE] Cancel time task with suitable way. [spark]
Posted by "beliefer (via GitHub)" <gi...@apache.org>.
beliefer commented on PR #50107:
URL: https://github.com/apache/spark/pull/50107#issuecomment-2690560779
ping @mridulm @LuciferYang @srowen cc @jjayadeep06
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51341][CORE] Cancel time task with suitable way. [spark]
Posted by "the-sakthi (via GitHub)" <gi...@apache.org>.
the-sakthi commented on code in PR #50107:
URL: https://github.com/apache/spark/pull/50107#discussion_r1974290564
##########
core/src/main/scala/org/apache/spark/ui/ConsoleProgressBar.scala:
##########
@@ -121,5 +121,8 @@ private[spark] class ConsoleProgressBar(sc: SparkContext) extends Logging {
* Tear down the timer thread. The timer thread is a GC root, and it retains the entire
* SparkContext if it's not terminated.
*/
- def stop(): Unit = ThreadUtils.shutdown(timer)
+ def stop(): Unit = {
+ timerFuture.cancel(true)
+ ThreadUtils.shutdown(timer)
+ }
Review Comment:
Thanks for the change @beliefer .
Interested in knowing how this change in the ui consoleprogress bar was tested?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51341][CORE] Cancel time task with suitable way. [spark]
Posted by "beliefer (via GitHub)" <gi...@apache.org>.
beliefer closed pull request #50107: [SPARK-51341][CORE] Cancel time task with suitable way.
URL: https://github.com/apache/spark/pull/50107
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51341][CORE] Cancel time task with suitable way. [spark]
Posted by "beliefer (via GitHub)" <gi...@apache.org>.
beliefer commented on code in PR #50107:
URL: https://github.com/apache/spark/pull/50107#discussion_r1973643904
##########
core/src/main/scala/org/apache/spark/BarrierTaskContext.scala:
##########
@@ -300,11 +300,7 @@ object BarrierTaskContext {
@Since("2.4.0")
def get(): BarrierTaskContext = TaskContext.get().asInstanceOf[BarrierTaskContext]
- private val timer = {
- val executor = ThreadUtils.newDaemonSingleThreadScheduledExecutor(
- "Barrier task timer for barrier() calls.")
- assert(executor.isInstanceOf[ScheduledThreadPoolExecutor])
- executor.asInstanceOf[ScheduledThreadPoolExecutor]
- }
+ private val timer = ThreadUtils.newSingleThreadScheduledExecutor(
Review Comment:
The origin code is non-daemon thread here.
Please see
https://github.com/apache/spark/commit/5d5b3a54b7b5fb4308fe40da696ba805c72983fc#diff-e9f66d336ded6632366be06dbd70e74afe9595cfc92a962f2c8554f09af53d0fL286
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51341][CORE] Cancel time task with suitable way. [spark]
Posted by "beliefer (via GitHub)" <gi...@apache.org>.
beliefer commented on code in PR #50107:
URL: https://github.com/apache/spark/pull/50107#discussion_r1976406171
##########
core/src/main/scala/org/apache/spark/ui/ConsoleProgressBar.scala:
##########
@@ -121,5 +121,8 @@ private[spark] class ConsoleProgressBar(sc: SparkContext) extends Logging {
* Tear down the timer thread. The timer thread is a GC root, and it retains the entire
* SparkContext if it's not terminated.
*/
- def stop(): Unit = ThreadUtils.shutdown(timer)
+ def stop(): Unit = {
+ timerFuture.cancel(true)
+ ThreadUtils.shutdown(timer)
+ }
Review Comment:
To be honestly, I don't know it too.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51341][CORE] Cancel time task with suitable way. [spark]
Posted by "beliefer (via GitHub)" <gi...@apache.org>.
beliefer commented on code in PR #50107:
URL: https://github.com/apache/spark/pull/50107#discussion_r1976289910
##########
core/src/main/scala/org/apache/spark/BarrierTaskContext.scala:
##########
@@ -300,11 +300,7 @@ object BarrierTaskContext {
@Since("2.4.0")
def get(): BarrierTaskContext = TaskContext.get().asInstanceOf[BarrierTaskContext]
- private val timer = {
- val executor = ThreadUtils.newDaemonSingleThreadScheduledExecutor(
- "Barrier task timer for barrier() calls.")
- assert(executor.isInstanceOf[ScheduledThreadPoolExecutor])
- executor.asInstanceOf[ScheduledThreadPoolExecutor]
- }
+ private val timer = ThreadUtils.newSingleThreadScheduledExecutor(
Review Comment:
Because all the BarrierTaskContext share the timer, so we can't shut down it.
It seems good to revert it with daemon thread.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51341][CORE] Cancel time task with suitable way. [spark]
Posted by "beliefer (via GitHub)" <gi...@apache.org>.
beliefer commented on code in PR #50107:
URL: https://github.com/apache/spark/pull/50107#discussion_r1980618502
##########
core/src/main/scala/org/apache/spark/scheduler/TaskSchedulerImpl.scala:
##########
@@ -959,7 +965,9 @@ private[spark] class TaskSchedulerImpl(
barrierCoordinator.stop()
}
}
+ starvationFutures.asScala.foreach(_.cancel(false))
Review Comment:
Good thinking. Let me revert this part. Maybe `ThreadUtils.shutdown(starvationTimer)` is good enough.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51341][CORE] Cancel time task with suitable way. [spark]
Posted by "beliefer (via GitHub)" <gi...@apache.org>.
beliefer commented on PR #50107:
URL: https://github.com/apache/spark/pull/50107#issuecomment-2705285514
Merged into master.
@srowen @the-sakthi Thank you!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org