vanzin commented on a change in pull request #23951: [SPARK-13704][CORE][YARN] 
Re-implement RackResolver to reduce resolving time
URL: https://github.com/apache/spark/pull/23951#discussion_r268348390
 
 

 ##########
 File path: 
core/src/main/scala/org/apache/spark/scheduler/TaskSchedulerImpl.scala
 ##########
 @@ -811,8 +818,38 @@ private[spark] class TaskSchedulerImpl(
     
blacklistTrackerOpt.map(_.nodeBlacklist()).getOrElse(scala.collection.immutable.Set())
   }
 
+  // Add a on-off switch to save time for rack resolving
+  private def skipRackResolving: Boolean = sc.conf.get(LOCALITY_WAIT_RACK) == 
0L
+
+  /**
+   * Get racks info for hosts. This is the internal method of 
[[getRacksForHosts]].
+   * It should be override in different TaskScheduler.
+   * The return racks must have to be the same length as the hosts passed in.
+   * Return [[defaultRackValue]] sequence by default.
+   */
+  protected def doGetRacksForHosts(hosts: Seq[String]): Seq[Option[String]] = {
+    hosts.map(_ => defaultRackValue)
+  }
+
   // By default, rack is unknown
-  def getRackForHost(value: String): Option[String] = None
+  def getRackForHost(hosts: String): Option[String] = {
+    if (skipRackResolving) {
+      defaultRackValue
+    } else {
+      doGetRacksForHosts(Seq(hosts)).head
+    }
+  }
+
+  /**
+   * null in return sequences will be replaced to [[defaultRackValue]].
 
 Review comment:
   Not sure what this is explaining? The code in this method doesn't seem to 
have any `null` handling at all.

----------------------------------------------------------------
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