Github user squito commented on a diff in the pull request: https://github.com/apache/spark/pull/17533#discussion_r110434821 --- Diff: core/src/main/scala/org/apache/spark/scheduler/TaskSetManager.scala --- @@ -512,6 +521,51 @@ private[spark] class TaskSetManager( } } + private[this] def sortPendingTasks(): Unit = { + val taskIndexs = (0 until numTasks).toArray + def ordFunc(x: Int, y: Int): Boolean = { + getTaskInputSizeFromShuffledRDD(tasks(x)) < getTaskInputSizeFromShuffledRDD(tasks(y)) + } + if (tasks.nonEmpty) { + // Sort the tasks based on their input size from ShuffledRDD. + pendingTasksForExecutor.foreach { + case (k, v) => pendingTasksForExecutor(k) = v.sortWith(ordFunc) + } + pendingTasksForHost.foreach { + case (k, v) => pendingTasksForHost(k) = v.sortWith(ordFunc) + } + pendingTasksForRack.foreach { + case (k, v) => pendingTasksForRack(k) = v.sortWith(ordFunc) + } + pendingTasksWithNoPrefs = pendingTasksWithNoPrefs.sortWith(ordFunc) + allPendingTasks = allPendingTasks.sortWith(ordFunc) + } + } + + // Visible for testing + private[spark] def setTaskInputSizeFromShuffledRDD(inputSize: Map[Task[_], Long]) = { + taskInputSizeFromShuffledRDD.clear() + taskInputSizeFromShuffledRDD ++= inputSize + } + + private[this] def getTaskInputSizeFromShuffledRDD(task: Task[_]): Long = { + taskInputSizeFromShuffledRDD.get(task) match { + case Some(size) => size + case None => + val size = + sched.dagScheduler.parentSplitsInShuffledRDD(task.stageId, task.partitionId).map { --- End diff -- I think the major complaint is this call, we don't want the TSM requesting info from the DAGSCheduler. But you could change that -- instead the DAGScheduler could *push* this info into the TSM after it has the input sizes. This actually might not be that bad, since in any case the DAGScheduler has to know this info when it calls `submitMissingTasks`. I don't think this info should change at all after the taskset has been submitted, right, so you'd have it all available at construction time?
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org