Spark Caching:RDD只缓存了8%

时间:2016-03-17 11:01:17

标签: scala memory-management apache-spark distributed-computing rdd

我的代码段如下:

val levelsFile = sc.textFile(levelsFilePath)
val levelsSplitedFile = levelsFile.map(line => line.split(fileDelimiter, -1))
val levelPairRddtemp = levelsSplitedFile
                              .filter(linearr => ( linearr(pogIndex).length!=0))
                              .map(linearr => (linearr(pogIndex).toLong, levelsIndexes.map(x => linearr(x))
                              .filter(value => (!value.equalsIgnoreCase("") && !value.equalsIgnoreCase(" ") && !value.equalsIgnoreCase("null")))))
                              .mapValues(value => value.mkString(","))
                              .partitionBy(new HashPartitioner(24))
                              .persist(StorageLevel.MEMORY_ONLY_SER)

levelPairRddtemp.count // just to trigger rdd creation

信息

  1. 文件大小为~4G
  2. 我正在使用2 executors(每个5G)和 12核。
  3. Spark版本:1.5.2
  4. 问题

    当我查看SparkUI中的Storage tab时,我看到的是:

    enter image description here

    查看RDD内部,似乎只缓存了24 partitions中的2个。

    enter image description here

    对此行为的任何解释,以及如何解决此问题。

    编辑1 :我刚试过HashPartitioner的60个分区:

    ..
    .partitionBy(new HashPartitioner(60))
    ..
    

    工作。现在我得到了整个RDD缓存。有什么猜测这里可能发生了什么?数据偏差会导致这种行为吗?

    编辑-2 :当我再次使用24 BlockManagerInfo运行时,包含partitions的日志。这次3/24 partitions被缓存:

    16/03/17 14:15:28 INFO BlockManagerInfo: Added rdd_294_14 in memory on ip-10-1-34-66.ec2.internal:47526 (size: 107.3 MB, free: 2.6 GB) 
    16/03/17 14:15:30 INFO BlockManagerInfo: Added rdd_294_17 in memory on ip-10-1-34-65.ec2.internal:57300 (size: 107.3 MB, free: 2.6 GB) 
    16/03/17 14:15:30 INFO BlockManagerInfo: Added rdd_294_21 in memory on ip-10-1-34-65.ec2.internal:57300 (size: 107.4 MB, free: 2.5 GB)
    

1 个答案:

答案 0 :(得分:1)

我认为发生这种情况是因为达到了内存限制,甚至更多,你使用的内存选项不会让你的工作利用所有资源。

增加#partitions意味着减少每个任务的大小,这可以解释行为。