【问题标题】:OutOfMemoryError while Logistic regression in SparkRSparkR中的逻辑回归时出现OutOfMemoryError
【发布时间】:2014-12-01 05:31:53
【问题描述】:

我已经成功安装了 Apache Spark、Hadoop over Ubuntu 12.04(单独立模式)用于逻辑回归。还使用小型 csv 数据集进行了测试,但它不适用于具有 269369 行的大型数据集。

library(SparkR)
sc <- sparkR.init()
iterations <- as.integer(11)
D <- 540

readPartition <- function(part){
part = strsplit(part, ",", fixed = T)
list(matrix(as.numeric(unlist(part)), ncol = length(part[[1]])))
}
w <- runif(n=D, min = -1, max = 1)

cat("Initial w: ", w, "\n")

# Compute logistic regression gradient for a matrix of data points
gradient <- function(partition) {
  partition = partition[[1]]
  Y <- partition[, 1] # point labels (first column of input file)

  X <- partition[, -1] # point coordinates
  # For each point (x, y), compute gradient function
  #print(w)
  dot <- X %*% w      
  logit <- 1 / (1 + exp(-Y * dot))
  grad <- t(X) %*% ((logit - 1) * Y)
  list(grad)
}


for (i in 1:iterations) {
  cat("On iteration ", i, "\n")
  w <- w - reduce(lapplyPartition(points, gradient), "+")
}

> points <- cache(lapplyPartition(textFile(sc, "hdfs://localhost:54310/henry/cdata_mr.csv"), readPartition))

我得到的错误信息:

14/10/07 01:47:16 INFO FileInputFormat: Total input paths to process : 1
14/10/07 01:47:28 WARN CacheManager: Not enough space to cache partition rdd_23_0 in memory! Free memory is 235841615 bytes.
14/10/07 01:47:42 WARN CacheManager: Not enough space to cache partition rdd_23_1 in memory! Free memory is 236015334 bytes.
14/10/07 01:47:55 WARN CacheManager: Not enough space to cache partition rdd_23_2 in memory! Free memory is 236015334 bytes.
14/10/07 01:48:10 WARN CacheManager: Not enough space to cache partition rdd_23_3 in memory! Free memory is 236015334 bytes.
14/10/07 01:48:29 ERROR Executor: Exception in task 0.0 in stage 13.0 (TID 17)
java.lang.OutOfMemoryError: Java heap space
    at edu.berkeley.cs.amplab.sparkr.RRDD$$anon$2.read(RRDD.scala:144)
    at edu.berkeley.cs.amplab.sparkr.RRDD$$anon$2.<init>(RRDD.scala:156)
    at edu.berkeley.cs.amplab.sparkr.RRDD.compute(RRDD.scala:129)
    at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:262)
    at org.apache.spark.CacheManager.getOrCompute(CacheManager.scala:61)
    at org.apache.spark.rdd.RDD.iterator(RDD.scala:227)
    at edu.berkeley.cs.amplab.sparkr.RRDD.compute(RRDD.scala:120)
    at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:262)
    at org.apache.spark.rdd.RDD.iterator(RDD.scala:229)
    at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:62)
    at org.apache.spark.scheduler.Task.run(Task.scala:54)
    at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:177)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:701)
14/10/07 01:48:29 ERROR ExecutorUncaughtExceptionHandler: Uncaught exception in thread Thread[Executor task launch worker-0,5,main]

数据维度(样本):

data <- read.csv("/home/Henry/data.csv")

dim(data)

[1] 269369 541

我还尝试在本地文件系统和 HDFS 上托管相同的 csv 文件。我认为它需要更多的 Hadoop 数据注释来存储大型数据集?如果是这样,我该如何设置 Spark Hadoop 集群来摆脱这种情况。 (或者我做错了什么)

提示:我认为增加 Java 和 Spark 堆空间将有助于我运行它。我做了很多尝试,但没有成功。谁能知道增加两者的堆空间的方法是什么。

【问题讨论】:

    标签: r apache-spark


    【解决方案1】:

    您能否尝试将spark.executor.memory 设置为更大的值,如here 所记录的那样?作为粗略计算,假设数据集中的每个条目占用 4 个字节,内存中的整个文件将花费 269369 * 541 * 4 bytes ~= 560MB,这超过了该参数的默认 512m 值。

    例如,尝试类似(假设集群中的每个工作节点都有超过 1GB 的可用内存):

    sc <- sparkR.init("local[2]", "SparkR", "/home/spark",
                      list(spark.executor.memory="1g"))
    

    【讨论】:

      猜你喜欢
      • 2015-06-30
      • 1970-01-01
      • 2014-11-21
      • 2018-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-01
      • 1970-01-01
      相关资源
      最近更新 更多