Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-26632][Core] Separate Thread Configurations of Driver and Executor #23560

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4c16bf8
separate thread configurations of driver and executor for serverThrea…
jiafuzha Jan 16, 2019
81b4bf0
Revert "separate thread configurations of driver and executor for ser…
jiafuzha Jan 25, 2019
d5ec0a0
separate thread configurations of driver and executor for serverThrea…
jiafuzha Jan 16, 2019
dd8405d
correct some style issue
jiafuzha Jan 16, 2019
ab9b965
correct style issue
jiafuzha Jan 16, 2019
5427eb8
correct style issue
jiafuzha Jan 16, 2019
ecab1cc
add check for driver's legacy identifier
jiafuzha Jan 17, 2019
7519af3
override io threads with specific values for driver and executor
jiafuzha Jan 29, 2019
64e9536
correct indent
jiafuzha Jan 30, 2019
d0b319d
Merge remote-tracking branch 'upstream/master'
jiafuzha Feb 1, 2019
1f813ec
Merge branch 'master' into thread_conf_separation
jiafuzha Feb 1, 2019
0fafe21
use role instead of boolean to differentiate driver and executor
jiafuzha Feb 13, 2019
11233d2
more accurate code to look for driver and executor thread configuration
jiafuzha Mar 13, 2019
59f9922
remove SparkContext.LEGACY_DRIVER_IDENTIFIER
jiafuzha Mar 13, 2019
bedf0fe
fix binary incompatibility issue
jiafuzha Mar 13, 2019
d73cfb5
refined code
jiafuzha Mar 13, 2019
cb4e5aa
restructure code and fix executor id missing issue
jiafuzha Mar 14, 2019
8f82381
Merge branch 'master' of https://github.com/apache/spark
jiafuzha Mar 14, 2019
e4b1023
merged from master to resolve conflict
jiafuzha Mar 14, 2019
05164b9
OMerge branch 'master' of https://github.com/apache/spark
jiafuzha Apr 30, 2019
5b9d86e
Merge branch 'master' into thread_conf_separation
jiafuzha Apr 30, 2019
cb27a2c
rewrite some code and add documentation
jiafuzha Apr 30, 2019
51f78ed
miscellaneous changes
jiafuzha May 6, 2019
6bdfe6d
miscellaneous udpdate
jiafuzha May 7, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package org.apache.spark.network.netty

import scala.collection.JavaConverters._

import org.apache.spark.SparkConf
import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.network.util.{ConfigProvider, NettyUtils, TransportConf}

jiafuzha marked this conversation as resolved.
Show resolved Hide resolved
/**
Expand All @@ -43,9 +43,23 @@ object SparkTransportConf {
// Specify thread configuration based on our JVM's allocation of cores (rather than necessarily
// assuming we have all the machine's cores).
// NB: Only set if serverThreads/clientThreads not already set.
val serverSpecificThreads = getSpecificNumOfThreads(conf, module, true)
val clientSpecificThreads = getSpecificNumOfThreads(conf, module, false)
val numThreads = NettyUtils.defaultNumThreads(numUsableCores)
conf.setIfMissing(s"spark.$module.io.serverThreads", numThreads.toString)
conf.setIfMissing(s"spark.$module.io.clientThreads", numThreads.toString)

// override threads configurations with side (driver and executor) specific values
val serverKey = s"spark.$module.io.serverThreads"
if (serverSpecificThreads > 0) {
conf.set(serverKey, serverSpecificThreads.toString)
} else {
conf.setIfMissing(serverKey, numThreads.toString)
}
val clientKey = s"spark.$module.io.clientThreads"
if (clientSpecificThreads > 0) {
conf.set(clientKey, clientSpecificThreads.toString)
} else {
conf.setIfMissing(clientKey, numThreads.toString)
}

new TransportConf(module, new ConfigProvider {
override def get(name: String): String = conf.get(name)
Expand All @@ -55,4 +69,27 @@ object SparkTransportConf {
}
})
}

/**
* Separate threads configuration of driver and executor
* @param conf the [[SparkConf]]
* @param module the module name
* @param server if true, it's for the serverThreads. Otherwise, it's for the clientThreads.
* @return the configured number of threads, or -1 if not configured.
*/
def getSpecificNumOfThreads(
conf: SparkConf,
jiafuzha marked this conversation as resolved.
Show resolved Hide resolved
module: String,
server: Boolean): Int = {
jiafuzha marked this conversation as resolved.
Show resolved Hide resolved
val executorId = conf.get("spark.executor.id", "")
val isDriver = executorId == SparkContext.DRIVER_IDENTIFIER ||
executorId == SparkContext.LEGACY_DRIVER_IDENTIFIER
val side = if (isDriver) "driver" else "executor"

if (server) {
conf.getInt(s"spark.$side.$module.io.serverThreads", -1)
} else {
conf.getInt(s"spark.$side.$module.io.clientThreads", -1)
}
}
}
44 changes: 29 additions & 15 deletions core/src/main/scala/org/apache/spark/rpc/netty/Dispatcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import scala.collection.JavaConverters._
import scala.concurrent.Promise
import scala.util.control.NonFatal

import org.apache.spark.SparkException
import org.apache.spark.{SparkConf, SparkContext, SparkException}
import org.apache.spark.internal.Logging
import org.apache.spark.internal.config.Network.RPC_NETTY_DISPATCHER_NUM_THREADS
import org.apache.spark.network.client.RpcResponseCallback
Expand All @@ -40,9 +40,9 @@ import org.apache.spark.util.ThreadUtils
private[netty] class Dispatcher(nettyEnv: NettyRpcEnv, numUsableCores: Int) extends Logging {

private class EndpointData(
val name: String,
val endpoint: RpcEndpoint,
val ref: NettyRpcEndpointRef) {
val name: String,
val endpoint: RpcEndpoint,
val ref: NettyRpcEndpointRef) {
jiafuzha marked this conversation as resolved.
Show resolved Hide resolved
val inbox = new Inbox(ref, endpoint)
}

Expand Down Expand Up @@ -113,10 +113,10 @@ private[netty] class Dispatcher(nettyEnv: NettyRpcEnv, numUsableCores: Int) exte
val iter = endpoints.keySet().iterator()
while (iter.hasNext) {
val name = iter.next
postMessage(name, message, (e) => { e match {
case e: RpcEnvStoppedException => logDebug (s"Message $message dropped. ${e.getMessage}")
case e: Throwable => logWarning(s"Message $message dropped. ${e.getMessage}")
}}
postMessage(name, message, (e) => { e match {
jiafuzha marked this conversation as resolved.
Show resolved Hide resolved
case e: RpcEnvStoppedException => logDebug (s"Message $message dropped. ${e.getMessage}")
case e: Throwable => logWarning(s"Message $message dropped. ${e.getMessage}")
}}
)}
}

Expand Down Expand Up @@ -150,9 +150,9 @@ private[netty] class Dispatcher(nettyEnv: NettyRpcEnv, numUsableCores: Int) exte
* @param callbackIfStopped callback function if the endpoint is stopped.
*/
private def postMessage(
endpointName: String,
message: InboxMessage,
callbackIfStopped: (Exception) => Unit): Unit = {
endpointName: String,
message: InboxMessage,
callbackIfStopped: (Exception) => Unit): Unit = {
jiafuzha marked this conversation as resolved.
Show resolved Hide resolved
val error = synchronized {
val data = endpoints.get(endpointName)
if (stopped) {
Expand Down Expand Up @@ -194,12 +194,26 @@ private[netty] class Dispatcher(nettyEnv: NettyRpcEnv, numUsableCores: Int) exte
endpoints.containsKey(name)
}

def getNumOfThreads(conf: SparkConf): Int = {
jiafuzha marked this conversation as resolved.
Show resolved Hide resolved
val executorId = conf.get("spark.executor.id", "")
jiafuzha marked this conversation as resolved.
Show resolved Hide resolved
val isDriver = executorId == SparkContext.DRIVER_IDENTIFIER ||
executorId == SparkContext.LEGACY_DRIVER_IDENTIFIER
val side = if (isDriver) "driver" else "executor"
jiafuzha marked this conversation as resolved.
Show resolved Hide resolved

val num = conf.getInt(s"spark.$side.rpc.netty.dispatcher.numThreads", -1)
if (num > 0) {
num
} else {
val availableCores =
if (numUsableCores > 0) numUsableCores else Runtime.getRuntime.availableProcessors()
nettyEnv.conf.get(RPC_NETTY_DISPATCHER_NUM_THREADS)
.getOrElse(math.max(2, availableCores))
}
}

/** Thread pool used for dispatching messages. */
private val threadpool: ThreadPoolExecutor = {
val availableCores =
if (numUsableCores > 0) numUsableCores else Runtime.getRuntime.availableProcessors()
val numThreads = nettyEnv.conf.get(RPC_NETTY_DISPATCHER_NUM_THREADS)
.getOrElse(math.max(2, availableCores))
val numThreads = getNumOfThreads(nettyEnv.conf)
val pool = ThreadUtils.newDaemonFixedThreadPool(numThreads, "dispatcher-event-loop")
for (i <- 0 until numThreads) {
pool.execute(new MessageLoop)
Expand Down