Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions core/src/main/scala/org/apache/spark/deploy/master/Master.scala
Original file line number Diff line number Diff line change
Expand Up @@ -581,20 +581,22 @@ private[deploy] class Master(

/** Return whether the specified worker can launch an executor for this app. */
def canLaunchExecutor(pos: Int): Boolean = {
val keepScheduling = coresToAssign >= minCoresPerExecutor
val enoughCores = usableWorkers(pos).coresFree - assignedCores(pos) >= minCoresPerExecutor

// If we allow multiple executors per worker, then we can always launch new executors.
// Otherwise, we may have already started assigning cores to the executor on this worker.
// Otherwise, if there is already an executor on this worker, just give it more cores.
val launchingNewExecutor = !oneExecutorPerWorker || assignedExecutors(pos) == 0
val underLimit =
if (launchingNewExecutor) {
assignedExecutors.sum + app.executors.size < app.executorLimit
} else {
true
}
val assignedMemory = assignedExecutors(pos) * memoryPerExecutor
usableWorkers(pos).memoryFree - assignedMemory >= memoryPerExecutor &&
usableWorkers(pos).coresFree - assignedCores(pos) >= minCoresPerExecutor &&
coresToAssign >= minCoresPerExecutor &&
underLimit
if (launchingNewExecutor) {
val assignedMemory = assignedExecutors(pos) * memoryPerExecutor
val enoughMemory = usableWorkers(pos).memoryFree - assignedMemory >= memoryPerExecutor
val underLimit = assignedExecutors.sum + app.executors.size < app.executorLimit
keepScheduling && enoughCores && enoughMemory && underLimit
} else {
// We're adding cores to an existing executor, so no need
// to check memory and executor limits
keepScheduling && enoughCores
}
}

// Keep launching executors until no more workers can accommodate any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ class MasterSuite extends SparkFunSuite with Matchers with Eventually with Priva
basicScheduling(spreadOut = false)
}

test("basic scheduling with more memory - spread out") {
basicSchedulingWithMoreMemory(spreadOut = true)
}

test("basic scheduling with more memory - no spread out") {
basicSchedulingWithMoreMemory(spreadOut = false)
}

test("scheduling with max cores - spread out") {
schedulingWithMaxCores(spreadOut = true)
}
Expand Down Expand Up @@ -214,6 +222,13 @@ class MasterSuite extends SparkFunSuite with Matchers with Eventually with Priva
assert(scheduledCores === Array(10, 10, 10))
}

private def basicSchedulingWithMoreMemory(spreadOut: Boolean): Unit = {
val master = makeMaster()
val appInfo = makeAppInfo(3072)
val scheduledCores = scheduleExecutorsOnWorkers(master, appInfo, workerInfos, spreadOut)
assert(scheduledCores === Array(10, 10, 10))
}

private def schedulingWithMaxCores(spreadOut: Boolean): Unit = {
val master = makeMaster()
val appInfo1 = makeAppInfo(1024, maxCores = Some(8))
Expand Down