weixiuli commented on code in PR #36162:
URL: https://github.com/apache/spark/pull/36162#discussion_r862449272


##########
core/src/main/scala/org/apache/spark/scheduler/TaskSetManager.scala:
##########
@@ -1069,24 +1085,64 @@ private[spark] class TaskSetManager(
    * speculative run.
    */
   private def checkAndSubmitSpeculatableTask(
-      tid: Long,
       currentTimeMillis: Long,
-      threshold: Double): Boolean = {
-    val info = taskInfos(tid)
-    val index = info.index
-    if (!successful(index) && copiesRunning(index) == 1 &&
-        info.timeRunning(currentTimeMillis) > threshold && 
!speculatableTasks.contains(index)) {
-      addPendingTask(index, speculatable = true)
-      logInfo(
-        ("Marking task %d in stage %s (on %s) as speculatable because it ran 
more" +
-          " than %.0f ms(%d speculatable tasks in this taskset now)")
-          .format(index, taskSet.id, info.host, threshold, 
speculatableTasks.size + 1))
-      speculatableTasks += index
-      sched.dagScheduler.speculativeTaskSubmitted(tasks(index))
-      true
-    } else {
-      false
+      threshold: Double,
+      numSuccessfulTasks: Int,
+      customizedThreshold: Boolean = false): Boolean = {
+    var foundTasksResult = false
+    var recomputeInefficientTasks = true
+    for (tid <- runningTasksSet) {
+      val info = taskInfos(tid)
+      val index = info.index
+      val runtimeMs = info.timeRunning(currentTimeMillis)
+      if (!successful(index) && copiesRunning(index) == 1 && 
!speculatableTasks.contains(index)) {
+
+        def checkMaySpeculate: Boolean = if (customizedThreshold) {
+          true
+        } else {
+          if (recomputeInefficientTasks && numSuccessfulTasks > 0 && sched.sc 
!= null) {
+            this.maybeRecompute(currentTimeMillis)
+            recomputeInefficientTasks = false
+          }
+          val longTimeTask = (numTasks <= 1) ||
+            (runtimeMs > speculationTaskDurationFactor *
+              max(speculationTaskMinDuration, threshold))
+          longTimeTask || inefficientTask.maySpeculateTask(tid, runtimeMs, 
info)
+        }
+
+        val maySpeculate = (runtimeMs > threshold) && checkMaySpeculate

Review Comment:
   The `threshold` may be a large one (Please check the assignment logic of 
threshold) when the  `numTasks == 1`, so it is not going to result in always 
speculating. 



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to