squito commented on a change in pull request #23677: [SPARK-26755][SCHEDULER] : 
Optimize Spark Scheduler to dequeue speculative tasks…
URL: https://github.com/apache/spark/pull/23677#discussion_r299576627
 
 

 ##########
 File path: core/src/main/scala/org/apache/spark/scheduler/TaskSetManager.scala
 ##########
 @@ -336,37 +327,30 @@ private[spark] class TaskSetManager(
   private def dequeueTaskFromList(
       execId: String,
       host: String,
-      list: ArrayBuffer[Int]): Option[Int] = {
-    var indexOffset = list.size
-    while (indexOffset > 0) {
-      indexOffset -= 1
-      val index = list(indexOffset)
-      if (!isTaskBlacklistedOnExecOrNode(index, execId, host)) {
-        // This should almost always be list.trimEnd(1) to remove tail
-        list.remove(indexOffset)
-        if (copiesRunning(index) == 0 && !successful(index)) {
-          return Some(index)
+      list: ArrayBuffer[Int],
+      speculative: Boolean = false): Option[Int] = {
+    if (speculative) {
+      if (!list.isEmpty) {
+        for (index <- list) {
+          if (!isTaskBlacklistedOnExecOrNode(index, execId, host) &&
+            !hasAttemptOnHost(index, host)) {
+            // This should almost always be list.trimEnd(1) to remove tail
+            list -= index
+            if (!successful(index)) {
+              return Some(index)
+            }
+          }
         }
       }
-    }
-    None
-  }
-
-  /**
-   * Dequeue a pending speculative task from the given list and return its 
index. Runs similar
-   * to the method 'dequeueTaskFromList' with additional constraints. Return 
None if the
-   * list is empty.
-   */
-  private def dequeueSpeculativeTaskFromList(
-    execId: String,
-    host: String,
-    list: HashSet[Int]): Option[Int] = {
-    if (!list.isEmpty) {
-      for (index <- list) {
-        if (!isTaskBlacklistedOnExecOrNode(index, execId, host) && 
!hasAttemptOnHost(index, host)) {
+    } else {
+      var indexOffset = list.size
+      while (indexOffset > 0) {
+        indexOffset -= 1
+        val index = list(indexOffset)
+        if (!isTaskBlacklistedOnExecOrNode(index, execId, host)) {
           // This should almost always be list.trimEnd(1) to remove tail
-          list -= index
-          if (!successful(index)) {
+          list.remove(indexOffset)
+          if (copiesRunning(index) == 0 && !successful(index)) {
 
 Review comment:
   again, can these be combined more?  There is a small logical difference 
here, but seems that can be pushed down.  Otherwise the differences are 
confusing (and even sometimes wrong -- eg. for speculative tasks, you're 
scanning from the front of the list, so the comment about removing tail is 
incorrect).
   
   ```scala
       var indexOffset = list.size
       while (indexOffset > 0) {
         indexOffset -= 1
         val index = list(indexOffset)
         if (!isTaskBlacklistedOnExecOrNode(index, execId, host) && 
             !(speculative && hasAttemptOnHost(index, host))) {
           // This should almost always be list.trimEnd(1) to remove tail
           list.remove(indexOffset)
           if ((copiesRunning(index) == 0 || speculative) && 
!successful(index)) {
             return Some(index)
           }
         }
       }
       None
   ```
   
   (I'm also wondering if we need `copiesRunning <= 1` even with speculation, 
since you've got multiple lists now, will need to step through that carefully 
and make sure there is a test)

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

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

Reply via email to