【发布时间】:2018-06-19 19:21:25
【问题描述】:
我有一个 Spark Streaming 应用程序正在运行,它使用 mapWithState 函数来跟踪 RDD 的状态。 该应用程序可以正常运行几分钟,但随后会因
而崩溃org.apache.spark.shuffle.MetadataFetchFailedException: Missing an output location for shuffle 373
我观察到,即使我为 mapWithStateRDD 设置了超时,Spark 应用程序的内存使用量也会随着时间线性增加。请看下面的代码 sn -p 和内存使用情况 -
val completedSess = sessionLines
.mapWithState(StateSpec.function(trackStateFunction _)
.numPartitions(80)
.timeout(Minutes(5)))
如果每个 RDD 都有明确的超时,为什么内存应该随着时间线性增加?
我试过增加内存,但没关系。我错过了什么?
编辑 - 参考代码
def trackStateFunction(batchTime: Time, key: String, value: Option[String], state: State[(Boolean, List[String], Long)]): Option[(Boolean, List[String])] = {
def updateSessions(newLine: String): Option[(Boolean, List[String])] = {
val currentTime = System.currentTimeMillis() / 1000
if (state.exists()) {
val newLines = state.get()._2 :+ newLine
//check if end of Session reached.
// if yes, remove the state and return. Else update the state
if (isEndOfSessionReached(value.getOrElse(""), state.get()._4)) {
state.remove()
Some(true, newLines)
}
else {
val newState = (false, newLines, currentTime)
state.update(newState)
Some(state.get()._1, state.get()._2)
}
}
else {
val newState = (false, List(value.get), currentTime)
state.update(newState)
Some(state.get()._1, state.get()._2)
}
}
value match {
case Some(newLine) => updateSessions(newLine)
case _ if state.isTimingOut() => Some(true, state.get()._2)
case _ => {
println("Not matched to any expression")
None
}
}
}
【问题讨论】:
-
您有多少传入流量?多少内存/磁盘?我们需要更多信息。
-
另外,你多久检查一次?
-
我有一个由 4 个工作人员组成的集群(8 个内核,32 GB RAM,每个 128 GB SSD)。来自 Kinesis Stream 的传入流量为 10-15 MB/s。批处理间隔为 10 秒。检查点间隔为60s
-
你在状态中存储了多少数据(也许共享代码)?有什么东西在不应该的时候保持静态吗?
-
@YuvalItzchakov 用代码 sn-p 更新了问题。它的灵感来自您的博文 :)
标签: scala apache-spark spark-streaming