Skip to content

Commit bbc7087

Browse files
Optimize the schedule in Master
1 parent 1904bac commit bbc7087

File tree

1 file changed

+8
-4
lines changed
  • core/src/main/scala/org/apache/spark/deploy/master

1 file changed

+8
-4
lines changed

core/src/main/scala/org/apache/spark/deploy/master/Master.scala

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,12 +481,16 @@ private[spark] class Master(
481481
if (state != RecoveryState.ALIVE) { return }
482482

483483
// First schedule drivers, they take strict precedence over applications
484-
val shuffledWorkers = Random.shuffle(workers) // Randomization helps balance drivers
485-
for (worker <- shuffledWorkers if worker.state == WorkerState.ALIVE) {
486-
for (driver <- List(waitingDrivers: _*)) { // iterate over a copy of waitingDrivers
487-
if (worker.memoryFree >= driver.desc.mem && worker.coresFree >= driver.desc.cores) {
484+
for (driver <- List(waitingDrivers: _*)) {
485+
val shuffledWorkers = Random.shuffle(workers) // Randomization helps balance drivers
486+
val shuffledWorkersIter = shuffledWorkers.iterator
487+
var launched = false
488+
while(shuffledWorkersIter.hasNext && !launched) {
489+
val worker = shuffledWorkersIter.next()
490+
if (worker.state == WorkerState.ALIVE && worker.memoryFree >= driver.desc.mem && worker.coresFree >= driver.desc.cores) {
488491
launchDriver(worker, driver)
489492
waitingDrivers -= driver
493+
launched = true
490494
}
491495
}
492496
}

0 commit comments

Comments
 (0)