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

    https://github.com/apache/spark/pull/1140#discussion_r14164279
  
    --- Diff: 
core/src/main/scala/org/apache/spark/scheduler/cluster/mesos/MesosSchedulerBackend.scala
 ---
    @@ -206,14 +203,13 @@ private[spark] class MesosSchedulerBackend(
             val taskLists = scheduler.resourceOffers(offerableWorkers)
     
             // Build a list of Mesos tasks for each slave
    -        val mesosTasks = offers.map(o => 
Collections.emptyList[MesosTaskInfo]())
    +        val mesosTasks = offers.map(o => new JArrayList[MesosTaskInfo]())
             for ((taskList, index) <- taskLists.zipWithIndex) {
               if (!taskList.isEmpty) {
    -            val offerNum = offerableIndices(index)
    -            val slaveId = offers(offerNum).getSlaveId.getValue
    -            slaveIdsWithExecutors += slaveId
    -            mesosTasks(offerNum) = new 
JArrayList[MesosTaskInfo](taskList.size)
                 for (taskDesc <- taskList) {
    +              val slaveId = taskDesc.executorId
    +              val offerNum = offers.indexWhere(_.getSlaveId.getValue == 
slaveId)
    --- End diff --
    
    So I think that the assumption that there is a <-> relationship between 
offers and slaves already exists elsewhere in the code, so that's fine.
    
    But this is basically an `N^2` approach since you iterate over all offers 
for each accepted offer. It would be better to just replace `offerableIndices` 
with a hash map from the slaveId to the index in `offerableWorkers`. That way 
you could do a constant time look up here. The performance of this function is 
actually pretty important since scheduling can be a bottleneck in fine-grained 
mesos mode.


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

Reply via email to