作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图保留一个 spark RDD,其中每个分区的元素都共享对单个大对象的访问。但是,这个对象似乎多次存储在内存中。将我的问题简化为只有 200 个元素的单个分区的玩具箱:
val nElements = 200
class Elem(val s:Array[Int])
val rdd = sc.parallelize(Seq(1)).mapPartitions( _ => {
val sharedArray = Array.ofDim[Int](10000000) // Should require ~40MB
(1 to nElements).toIterator.map(i => new Elem(sharedArray))
}).cache()
rdd.count() //force computation
storage.MemoryStore: Block rdd_1_0 stored as values in memory (estimated size 38.2 MB, free 5.7 GB)
nElements=201
产量:
storage.MemoryStore: Block rdd_1_0 stored as values in memory (estimated size 76.7 MB, free 5.7 GB)
rdd.map(_.s.hashCode).min == rdd.map(_.s.hashCode).max // returns true
storage.MemoryStore: Not enough space to cache rdd_1_0 in memory! (computed 6.1 GB so far)
nExamples=500
它成功地将 rdd 保留在内存中,说估计大小为 1907.4 MB,但我可以看到我的内存使用量的实际增加远小于这个。
最佳答案
对于将来遇到此问题的任何人,我最终想出了一个 super 黑客的解决方案(尽管我仍然很高兴听到更好的解决方案)。我没有使用 rdd.cache(),而是定义:
def cached[T: ClassTag](rdd:RDD[T]) = {
rdd.mapPartitions(p =>
Iterator(p.toSeq)
).cache().mapPartitions(p =>
p.next().toIterator
)
}
cached(rdd)
返回从“缓存”列表生成的 RDD
关于scala - Spark RDD 在每个分区内具有共享指针(以及魔数(Magic Number) 200??),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27079724/
我是一名优秀的程序员,十分优秀!