Skip to content

Commit 4dbb27b

Browse files
witgomateiz
authored andcommitted
[SPARK-1712]: TaskDescription instance is too big causes Spark to hang
Author: witgo <[email protected]> Closes #694 from witgo/SPARK-1712_new and squashes the following commits: 0f52483 [witgo] review commit 83ce29b [witgo] Merge branch 'master' of https://github.com/apache/spark into SPARK-1712_new 52e6752 [witgo] reset test SparkContext 63636b6 [witgo] review commit 44a59ee [witgo] review commit 3b6d48c [witgo] Merge branch 'master' of https://github.com/apache/spark into SPARK-1712_new 926bd6a [witgo] Merge branch 'master' of https://github.com/apache/spark into SPARK-1712_new 9a5cfad [witgo] Merge branch 'master' of https://github.com/apache/spark into SPARK-1712_new 03cc562 [witgo] Merge branch 'master' of https://github.com/apache/spark into SPARK-1712_new b0930b0 [witgo] review commit b1174bd [witgo] merge master f76679b [witgo] merge master 689495d [witgo] fix scala style bug 1d35c3c [witgo] Merge branch 'master' of https://github.com/apache/spark into SPARK-1712_new 062c182 [witgo] fix small bug for code style 0a428cf [witgo] add unit tests 158b2dc [witgo] review commit 4afe71d [witgo] review commit 9e4ffa7 [witgo] review commit 1d35c7d [witgo] fix hang 7965580 [witgo] fix Statement order 0e29eac [witgo] Merge branch 'master' of https://github.com/apache/spark into SPARK-1712_new 3ea1ca1 [witgo] remove duplicate serialize 743a7ad [witgo] Merge branch 'master' of https://github.com/apache/spark into SPARK-1712_new 86e2048 [witgo] Merge branch 'master' of https://github.com/apache/spark into SPARK-1712_new 2a89adc [witgo] SPARK-1712: TaskDescription instance is too big causes Spark to hang
1 parent 4312cf0 commit 4dbb27b

File tree

4 files changed

+73
-8
lines changed

4 files changed

+73
-8
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ import java.nio.ByteBuffer
2222
import akka.actor._
2323
import akka.remote._
2424

25-
import org.apache.spark.{Logging, SecurityManager, SparkConf}
25+
import org.apache.spark.{SparkEnv, Logging, SecurityManager, SparkConf}
2626
import org.apache.spark.TaskState.TaskState
2727
import org.apache.spark.deploy.SparkHadoopUtil
2828
import org.apache.spark.deploy.worker.WorkerWatcher
2929
import org.apache.spark.scheduler.cluster.CoarseGrainedClusterMessages._
30+
import org.apache.spark.scheduler.TaskDescription
3031
import org.apache.spark.util.{AkkaUtils, Utils}
3132

3233
private[spark] class CoarseGrainedExecutorBackend(
@@ -61,12 +62,14 @@ private[spark] class CoarseGrainedExecutorBackend(
6162
logError("Slave registration failed: " + message)
6263
System.exit(1)
6364

64-
case LaunchTask(taskDesc) =>
65-
logInfo("Got assigned task " + taskDesc.taskId)
65+
case LaunchTask(data) =>
6666
if (executor == null) {
6767
logError("Received LaunchTask command but executor was null")
6868
System.exit(1)
6969
} else {
70+
val ser = SparkEnv.get.closureSerializer.newInstance()
71+
val taskDesc = ser.deserialize[TaskDescription](data.value)
72+
logInfo("Got assigned task " + taskDesc.taskId)
7073
executor.launchTask(this, taskDesc.taskId, taskDesc.serializedTask)
7174
}
7275

core/src/main/scala/org/apache/spark/scheduler/cluster/CoarseGrainedClusterMessage.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ private[spark] sealed trait CoarseGrainedClusterMessage extends Serializable
2828
private[spark] object CoarseGrainedClusterMessages {
2929

3030
// Driver to executors
31-
case class LaunchTask(task: TaskDescription) extends CoarseGrainedClusterMessage
31+
case class LaunchTask(data: SerializableBuffer) extends CoarseGrainedClusterMessage
3232

3333
case class KillTask(taskId: Long, executor: String, interruptThread: Boolean)
3434
extends CoarseGrainedClusterMessage

core/src/main/scala/org/apache/spark/scheduler/cluster/CoarseGrainedSchedulerBackend.scala

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ import akka.actor._
2727
import akka.pattern.ask
2828
import akka.remote.{DisassociatedEvent, RemotingLifecycleEvent}
2929

30-
import org.apache.spark.{Logging, SparkException, TaskState}
30+
import org.apache.spark.{SparkEnv, Logging, SparkException, TaskState}
3131
import org.apache.spark.scheduler.{SchedulerBackend, SlaveLost, TaskDescription, TaskSchedulerImpl, WorkerOffer}
3232
import org.apache.spark.scheduler.cluster.CoarseGrainedClusterMessages._
33-
import org.apache.spark.util.{AkkaUtils, Utils}
33+
import org.apache.spark.util.{SerializableBuffer, AkkaUtils, Utils}
3434

3535
/**
3636
* A scheduler backend that waits for coarse grained executors to connect to it through Akka.
@@ -48,6 +48,7 @@ class CoarseGrainedSchedulerBackend(scheduler: TaskSchedulerImpl, actorSystem: A
4848
var totalCoreCount = new AtomicInteger(0)
4949
val conf = scheduler.sc.conf
5050
private val timeout = AkkaUtils.askTimeout(conf)
51+
private val akkaFrameSize = AkkaUtils.maxFrameSizeBytes(conf)
5152

5253
class DriverActor(sparkProperties: Seq[(String, String)]) extends Actor {
5354
private val executorActor = new HashMap[String, ActorRef]
@@ -140,8 +141,26 @@ class CoarseGrainedSchedulerBackend(scheduler: TaskSchedulerImpl, actorSystem: A
140141
// Launch tasks returned by a set of resource offers
141142
def launchTasks(tasks: Seq[Seq[TaskDescription]]) {
142143
for (task <- tasks.flatten) {
143-
freeCores(task.executorId) -= scheduler.CPUS_PER_TASK
144-
executorActor(task.executorId) ! LaunchTask(task)
144+
val ser = SparkEnv.get.closureSerializer.newInstance()
145+
val serializedTask = ser.serialize(task)
146+
if (serializedTask.limit >= akkaFrameSize - 1024) {
147+
val taskSetId = scheduler.taskIdToTaskSetId(task.taskId)
148+
scheduler.activeTaskSets.get(taskSetId).foreach { taskSet =>
149+
try {
150+
var msg = "Serialized task %s:%d was %d bytes which " +
151+
"exceeds spark.akka.frameSize (%d bytes). " +
152+
"Consider using broadcast variables for large values."
153+
msg = msg.format(task.taskId, task.index, serializedTask.limit, akkaFrameSize)
154+
taskSet.abort(msg)
155+
} catch {
156+
case e: Exception => logError("Exception in error callback", e)
157+
}
158+
}
159+
}
160+
else {
161+
freeCores(task.executorId) -= scheduler.CPUS_PER_TASK
162+
executorActor(task.executorId) ! LaunchTask(new SerializableBuffer(serializedTask))
163+
}
145164
}
146165
}
147166

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.spark.scheduler
19+
20+
import org.apache.spark.{LocalSparkContext, SparkConf, SparkException, SparkContext}
21+
import org.apache.spark.util.{SerializableBuffer, AkkaUtils}
22+
23+
import org.scalatest.FunSuite
24+
25+
class CoarseGrainedSchedulerBackendSuite extends FunSuite with LocalSparkContext {
26+
27+
test("serialized task larger than akka frame size") {
28+
val conf = new SparkConf
29+
conf.set("spark.akka.frameSize","1")
30+
conf.set("spark.default.parallelism","1")
31+
sc = new SparkContext("local-cluster[2 , 1 , 512]", "test", conf)
32+
val frameSize = AkkaUtils.maxFrameSizeBytes(sc.conf)
33+
val buffer = new SerializableBuffer(java.nio.ByteBuffer.allocate(2 * frameSize))
34+
val larger = sc.parallelize(Seq(buffer))
35+
val thrown = intercept[SparkException] {
36+
larger.collect()
37+
}
38+
assert(thrown.getMessage.contains("Consider using broadcast variables for large values"))
39+
val smaller = sc.parallelize(1 to 4).collect()
40+
assert(smaller.size === 4)
41+
}
42+
43+
}

0 commit comments

Comments
 (0)