Github user squito commented on a diff in the pull request:

    https://github.com/apache/spark/pull/6394#discussion_r31954453
  
    --- Diff: 
yarn/src/main/scala/org/apache/spark/deploy/yarn/YarnAllocator.scala ---
    @@ -225,12 +243,74 @@ private[yarn] class YarnAllocator(
           logInfo(s"Will request $missing executor containers, each with 
${resource.getVirtualCores} " +
             s"cores and ${resource.getMemory} MB memory including 
$memoryOverhead MB overhead")
     
    -      for (i <- 0 until missing) {
    -        val request = createContainerRequest(resource)
    -        amClient.addContainerRequest(request)
    -        val nodes = request.getNodes
    -        val hostStr = if (nodes == null || nodes.isEmpty) "Any" else 
nodes.last
    -        logInfo(s"Container request (host: $hostStr, capability: 
$resource)")
    +      // Calculated the number of executors we expected to satisfy all the 
preferred locality tasks
    +      val localityAwareTaskCores = localityAwarePendingTaskNum * 
CPUS_PER_TASK
    +      val expectedLocalityAwareContainerNum =
    +        (localityAwareTaskCores + resource.getVirtualCores - 1) / 
resource.getVirtualCores
    +
    +      // Get the all the existed and locality matched containers
    +      val existedMatchedContainers = allocatedHostToContainersMap.filter { 
case (host, _) =>
    +        preferredLocalityToCounts.contains(host)
    +      }
    +      val existedMatchedContainerNum = 
existedMatchedContainers.values.map(_.size).sum
    +
    +      // The number of containers to allocate, divided into two groups, 
one with node locality,
    +      // and the other without locality preference.
    +      var requiredLocalityFreeContainerNum: Int = 0
    +      var requiredLocalityAwareContainerNum: Int = 0
    +
    +      if (expectedLocalityAwareContainerNum <= existedMatchedContainerNum) 
{
    +        // If the current allocated executor can satisfy all the locality 
preferred tasks,
    +        // allocate the new container with no locality preference
    +        requiredLocalityFreeContainerNum = missing
    +      } else {
    +        if (expectedLocalityAwareContainerNum - existedMatchedContainerNum 
>= missing) {
    +          // If newly requested containers cannot satisfy the locality 
preferred tasks,
    +          // allocate all the new container with locality preference
    +          requiredLocalityAwareContainerNum = missing
    +        } else {
    +          // If part of newly requested can satisfy the locality preferred 
tasks, allocate part of
    +          // the containers with locality preference, and another part 
with no locality preference
    +          requiredLocalityAwareContainerNum =
    +            expectedLocalityAwareContainerNum - existedMatchedContainerNum
    +          requiredLocalityFreeContainerNum = missing -
    +            (expectedLocalityAwareContainerNum - 
existedMatchedContainerNum)
    +        }
    +      }
    +
    +      if (requiredLocalityFreeContainerNum > 0) {
    +        for (i <- 0 until requiredLocalityFreeContainerNum) {
    +          val request = createContainerRequest(resource, null, null)
    +          amClient.addContainerRequest(request)
    +          val nodes = request.getNodes
    +          val hostStr = if (nodes == null || nodes.isEmpty) "Any" else 
nodes.last
    +          logInfo(s"Container request (host: $hostStr, capability: 
$resource)")
    +        }
    +      }
    +
    +      if (requiredLocalityAwareContainerNum > 0) {
    +        var largestRatio = 0
    +        for ( (_, ratio) <- preferredLocalityToCounts if ratio > 
largestRatio) {
    +          largestRatio = ratio
    +        }
    +
    +        // Calculate the ratio of locality preference
    +        var preferredLocalityRatio = preferredLocalityToCounts.mapValues { 
ratio =>
    +          val adjustedRatio = ratio.toDouble * 
requiredLocalityAwareContainerNum / largestRatio
    +          adjustedRatio.floor.toInt
    +        }
    +
    +        for (i <- 0 until requiredLocalityAwareContainerNum) {
    --- End diff --
    
    Can you add a high-level comment on what is going on here?  Admittedly I am 
not an expert in this part of the code but I have a hard time following.  Eg., 
`largestRatio` seems to actually be a count, I'm not sure what ratios are 
getting computed and updated, and what the side effect is of each time through 
the loop.


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

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

Reply via email to