【发布时间】:2015-05-15 03:51:05
【问题描述】:
我有一个 csv 文件存储了维度为 6,365x214 的用户项的数据,我正在使用 org.apache.spark.mllib.linalg.distributed.CoordinateMatrix 的 columnSimilarities() 来查找用户与用户的相似性。
我的代码如下所示:
import org.apache.spark.mllib.linalg.{Vector, Vectors}
import org.apache.spark.mllib.linalg.distributed.{RowMatrix,
MatrixEntry, CoordinateMatrix}
import org.apache.spark.rdd.RDD
def rddToCoordinateMatrix(input_rdd: RDD[String]) : CoordinateMatrix = {
// Convert RDD[String] to RDD[Tuple3]
val coo_matrix_input: RDD[Tuple3[Long,Long,Double]] = input_rdd.map(
line => line.split(',').toList
).map{
e => (e(0).toLong, e(1).toLong, e(2).toDouble)
}
// Convert RDD[Tuple3] to RDD[MatrixEntry]
val coo_matrix_matrixEntry: RDD[MatrixEntry] = coo_matrix_input.map(e => MatrixEntry(e._1, e._2, e._3))
// Convert RDD[MatrixEntry] to CoordinateMatrix
val coo_matrix: CoordinateMatrix = new CoordinateMatrix(coo_matrix_matrixEntry)
return coo_matrix
}
// Read CSV File to RDD[String]
val input_rdd: RDD[String] = sc.textFile("user_item.csv")
// Read RDD[String] to CoordinateMatrix
val coo_matrix = rddToCoordinateMatrix(input_rdd)
// Transpose CoordinateMatrix
val coo_matrix_trans = coo_matrix.transpose()
// Convert CoordinateMatrix to RowMatrix
val mat: RowMatrix = coo_matrix_trans.toRowMatrix()
// Compute similar columns perfectly, with brute force
// Return CoordinateMatrix
val simsPerfect: CoordinateMatrix = mat.columnSimilarities()
// CoordinateMatrix to RDD[MatrixEntry]
val simsPerfect_entries = simsPerfect.entries
simsPerfect_entries.count()
// Write results to file
val results_rdd = simsPerfect_entries.map(line => line.i+","+line.j+","+line.value)
results_rdd.saveAsTextFile("similarity-output")
// Close the REPL terminal
System.exit(0)
并且,当我在 spark-shell 上运行此脚本时
在运行代码行 simsPerfect_entries.count() 后出现以下错误:
java.lang.OutOfMemoryError: GC overhead limit exceeded
更新:
我尝试了很多其他人已经给出的解决方案,但我没有成功。
1 通过增加每个执行程序进程使用的内存量spark.executor.memory=1g
2 通过减少用于驱动程序进程的内核数量
spark.driver.cores=1
建议我解决此问题的方法。
【问题讨论】:
-
"我尝试了很多其他人已经给出的解决方案,但我没有成功。"你应该列出哪些,这样我们就可以避免多余的答案。
-
Akshay 好像我也面临同样的问题这是问题http://stackoverflow.com/q/37958522/1662775。我尝试增加驱动程序内存,但没有成功。
标签: scala apache-spark garbage-collection