Skip to content

Commit 64f8398

Browse files
committed
Use ThreadLocal for serializer instance in CoarseGrainedExecutorBackend
1 parent aeb680e commit 64f8398

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

core/src/main/scala/org/apache/spark/executor/CoarseGrainedExecutorBackend.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ private[spark] class CoarseGrainedExecutorBackend(
4848
var executor: Executor = null
4949
@volatile var driver: Option[RpcEndpointRef] = None
5050

51-
private[this] val ser: SerializerInstance = env.closureSerializer.newInstance()
51+
// This is a thread-local in case we ever decide to change this to a non-thread-safe RpcEndpoint
52+
private[this] val ser: ThreadLocal[SerializerInstance] = new ThreadLocal[SerializerInstance] {
53+
override def initialValue: SerializerInstance = env.closureSerializer.newInstance()
54+
}
5255

5356
override def onStart() {
5457
import scala.concurrent.ExecutionContext.Implicits.global
@@ -86,7 +89,7 @@ private[spark] class CoarseGrainedExecutorBackend(
8689
logError("Received LaunchTask command but executor was null")
8790
System.exit(1)
8891
} else {
89-
val taskDesc = ser.deserialize[TaskDescription](data.value)
92+
val taskDesc = ser.get().deserialize[TaskDescription](data.value)
9093
logInfo("Got assigned task " + taskDesc.taskId)
9194
executor.launchTask(this, taskId = taskDesc.taskId, attemptNumber = taskDesc.attemptNumber,
9295
taskDesc.name, taskDesc.serializedTask)

0 commit comments

Comments
 (0)