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

    https://github.com/apache/spark/pull/731#discussion_r28288621
  
    --- Diff: core/src/main/scala/org/apache/spark/deploy/master/Master.scala 
---
    @@ -582,32 +555,63 @@ private[master] class Master(
               pos = (pos + 1) % numUsable
             }
             // Now that we've decided how many cores to give on each node, 
let's actually give them
    -        for (pos <- 0 until numUsable) {
    -          if (assigned(pos) > 0) {
    -            val exec = app.addExecutor(usableWorkers(pos), assigned(pos))
    -            launchExecutor(usableWorkers(pos), exec)
    -            app.state = ApplicationState.RUNNING
    -          }
    +        for (pos <- 0 until numUsable if assigned(pos) > 0) {
    +          allocateWorkerResourceToExecutors(app, assigned(pos), 
usableWorkers(pos))
             }
           }
         } else {
    -      // Pack each app into as few nodes as possible until we've assigned 
all its cores
    +      // Pack each app into as few workers as possible until we've 
assigned all its cores
           for (worker <- workers if worker.coresFree > 0 && worker.state == 
WorkerState.ALIVE) {
    -        for (app <- waitingApps if app.coresLeft > 0) {
    -          if (canUse(app, worker)) {
    -            val coresToUse = math.min(worker.coresFree, app.coresLeft)
    -            if (coresToUse > 0) {
    -              val exec = app.addExecutor(worker, coresToUse)
    -              launchExecutor(worker, exec)
    -              app.state = ApplicationState.RUNNING
    -            }
    -          }
    +        for (app <- waitingApps if app.coresLeft > 0 &&
    +          worker.memoryFree >= app.desc.memoryPerExecutorMB) {
    +            allocateWorkerResourceToExecutors(app, app.coresLeft, worker)
    +        }
    +      }
    +    }
    +  }
    +
    +  /**
    +   * Allocate a worker's resources to one or more executors.
    +   * @param app the info of the application which the executors belong to
    +   * @param coresToAllocate cores on this worker to be allocated to this 
application
    +   * @param worker the worker info
    +   */
    +  private def allocateWorkerResourceToExecutors(
    +      app: ApplicationInfo,
    +      coresToAllocate: Int,
    +      worker: WorkerInfo): Unit = {
    +    val memoryPerExecutor = app.desc.memoryPerExecutorMB
    +    val coresPerExecutor = 
app.desc.coresPerExecutor.getOrElse(coresToAllocate)
    +    var coresLeft = coresToAllocate
    +    while (coresLeft >= coresPerExecutor && worker.memoryFree >= 
memoryPerExecutor) {
    +      val exec = app.addExecutor(worker, coresPerExecutor)
    +      coresLeft -= coresPerExecutor
    +      launchExecutor(worker, exec)
    +      app.state = ApplicationState.RUNNING
    +    }
    +  }
    +
    +  /**
    +   * Schedule the currently available resources among waiting apps. This 
method will be called
    +   * every time a new app joins or resource availability changes.
    +   */
    +  private def schedule(): Unit = {
    +    if (state != RecoveryState.ALIVE) { return }
    +    // start in-cluster drivers, they take strict precedence over 
applications
    +    val shuffledWorkers = Random.shuffle(workers) // Randomization helps 
balance drivers
    +    for (worker <- shuffledWorkers if worker.state == WorkerState.ALIVE) {
    +      for (driver <- waitingDrivers) {
    +        if (worker.memoryFree >= driver.desc.mem && worker.coresFree >= 
driver.desc.cores) {
    +          launchDriver(worker, driver)
    +          waitingDrivers -= driver
             }
           }
         }
    +    // start executors
    --- End diff --
    
    remove this comment, as it doesn't convey any information


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