Skip to content

Commit

Permalink
Modified Master to prevent from 0 divide
Browse files Browse the repository at this point in the history
  • Loading branch information
sarutak committed Sep 17, 2014
1 parent 4817ecd commit 4e51e35
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions core/src/main/scala/org/apache/spark/deploy/master/Master.scala
Original file line number Diff line number Diff line change
Expand Up @@ -490,24 +490,28 @@ private[spark] class Master(
// Randomization helps balance drivers
val shuffledAliveWorkers = Random.shuffle(workers.toSeq.filter(_.state == WorkerState.ALIVE))
val aliveWorkerNum = shuffledAliveWorkers.size
var curPos = 0
var stopPos = aliveWorkerNum
for (driver <- waitingDrivers.toList) { // iterate over a copy of waitingDrivers
// We assign workers to each waiting driver in a round-robin fashion. For each driver, we
// start from the last worker that was assigned a driver, and continue onwards until we have
// explored all alive workers.
var launched = false
while (curPos != stopPos && !launched) {
val worker = shuffledAliveWorkers(curPos)
if (worker.memoryFree >= driver.desc.mem && worker.coresFree >= driver.desc.cores) {
launchDriver(worker, driver)
waitingDrivers -= driver
launched = true

if (aliveWorkerNum > 0) {
var curPos = 0
var stopPos = aliveWorkerNum
for (driver <- waitingDrivers.toList) {
// iterate over a copy of waitingDrivers
// We assign workers to each waiting driver in a round-robin fashion. For each driver, we
// start from the last worker that was assigned a driver, and continue onwards until we have
// explored all alive workers.
var launched = false
while (curPos != stopPos && !launched) {
val worker = shuffledAliveWorkers(curPos)
if (worker.memoryFree >= driver.desc.mem && worker.coresFree >= driver.desc.cores) {
launchDriver(worker, driver)
waitingDrivers -= driver
launched = true
}
curPos = (curPos + 1) % aliveWorkerNum
}
curPos = (curPos + 1) % aliveWorkerNum
curPos = (stopPos + 1) % aliveWorkerNum
stopPos = curPos + aliveWorkerNum
}
curPos = (stopPos + 1) % aliveWorkerNum
stopPos = curPos + aliveWorkerNum
}

// Right now this is a very simple FIFO scheduler. We keep trying to fit in the first app
Expand Down

0 comments on commit 4e51e35

Please sign in to comment.