【发布时间】:2019-07-18 00:24:15
【问题描述】:
我正在使用一个火花程序,它需要在循环中不断更新一些 RDD:
var totalRandomPath: RDD[String] = null
for (iter <- 0 until config.numWalks) {
var randomPath: RDD[String] = examples.map { case (nodeId, clickNode) =>
clickNode.path.mkString("\t")
}
for (walkCount <- 0 until config.walkLength) {
randomPath = edge2attr.join(randomPath.mapPartitions { iter =>
iter.map { pathBuffer =>
val paths: Array[String] = pathBuffer.split("\t")
(paths.slice(paths.size - 2, paths.size).mkString(""), pathBuffer)
}
}).mapPartitions { iter =>
iter.map { case (edge, (attr, pathBuffer)) =>
try {
if (pathBuffer != null && pathBuffer.nonEmpty && attr.dstNeighbors != null && attr.dstNeighbors.nonEmpty) {
val nextNodeIndex: PartitionID = GraphOps.drawAlias(attr.J, attr.q)
val nextNodeId: VertexId = attr.dstNeighbors(nextNodeIndex)
s"$pathBuffer\t$nextNodeId"
} else {
pathBuffer //add
}
} catch {
case e: Exception => throw new RuntimeException(e.getMessage)
}
}.filter(_ != null)
}
}
if (totalRandomPath != null) {
totalRandomPath = totalRandomPath.union(randomPath)
} else {
totalRandomPath = randomPath
}
}
在这个程序中,RDD totalRandomPath 和 randomPath 不断更新着大量的转换操作:join 和 mapPartitions。该程序将以操作collect 结束。
那么我需要坚持那些不断更新的 RDD(totalRandomPath, randomPath) 来加快我的 spark 程序吗?
而且我注意到这个程序在单节点机器上运行速度很快,但是在三节点集群上运行就变慢了,为什么会出现这种情况?
【问题讨论】:
标签: scala apache-spark hadoop rdd