Skip to content

Commit

Permalink
[SPARK-8059] [YARN] Wake up allocation thread when new requests arrive.
Browse files Browse the repository at this point in the history
This should help reduce latency for new executor allocations.

Author: Marcelo Vanzin <[email protected]>

Closes #6600 from vanzin/SPARK-8059 and squashes the following commits:

8387a3a [Marcelo Vanzin] [SPARK-8059] [yarn] Wake up allocation thread when new requests arrive.
  • Loading branch information
Marcelo Vanzin authored and Andrew Or committed Jun 3, 2015
1 parent bfbf12b commit aa40c44
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ private[spark] class ApplicationMaster(

@volatile private var reporterThread: Thread = _
@volatile private var allocator: YarnAllocator = _
private val allocatorLock = new Object()

// Fields used in client mode.
private var rpcEnv: RpcEnv = null
Expand Down Expand Up @@ -359,7 +360,9 @@ private[spark] class ApplicationMaster(
}
logDebug(s"Number of pending allocations is $numPendingAllocate. " +
s"Sleeping for $sleepInterval.")
Thread.sleep(sleepInterval)
allocatorLock.synchronized {
allocatorLock.wait(sleepInterval)
}
} catch {
case e: InterruptedException =>
}
Expand Down Expand Up @@ -546,8 +549,15 @@ private[spark] class ApplicationMaster(
override def receiveAndReply(context: RpcCallContext): PartialFunction[Any, Unit] = {
case RequestExecutors(requestedTotal) =>
Option(allocator) match {
case Some(a) => a.requestTotalExecutors(requestedTotal)
case None => logWarning("Container allocator is not ready to request executors yet.")
case Some(a) =>
allocatorLock.synchronized {
if (a.requestTotalExecutors(requestedTotal)) {
allocatorLock.notifyAll()
}
}

case None =>
logWarning("Container allocator is not ready to request executors yet.")
}
context.reply(true)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,16 @@ private[yarn] class YarnAllocator(
* Request as many executors from the ResourceManager as needed to reach the desired total. If
* the requested total is smaller than the current number of running executors, no executors will
* be killed.
*
* @return Whether the new requested total is different than the old value.
*/
def requestTotalExecutors(requestedTotal: Int): Unit = synchronized {
def requestTotalExecutors(requestedTotal: Int): Boolean = synchronized {
if (requestedTotal != targetNumExecutors) {
logInfo(s"Driver requested a total number of $requestedTotal executor(s).")
targetNumExecutors = requestedTotal
true
} else {
false
}
}

Expand Down

0 comments on commit aa40c44

Please sign in to comment.