为缓存的 RDD 分配了多少内存?

How much memory is allocated for cached RDDs?

我有一个 5 个工作节点集群,每个集群有 6 GB 内存(Spark 执行程序内存设置为 4608 GB)。

我一直 运行 内存不足,Spark 告诉我我的一位执行者试图使用超过 5.0 GB 的内存。如果每个执行程序获得 5 GB 的内存,那么我的整个集群之间应该有 25 GB 的内存。

ExecutorLostFailure (executor 4 exited caused by one of the running tasks) 
Reason: Container killed by YARN for exceeding memory limits. 5.0 GB of 5.0 
GB physical memory used. Consider boosting spark.yarn.executor.memoryOverhead.

在我的 spark 应用程序开始时,当我在“存储”选项卡中查看我的一个 RDD(此时它是缓存中唯一的 rdd)时,我看到:

RDD Name    Storage Level                   Cached Partitions   Fraction Cached Size in Memory  Size on Disk
myRDD       Memory Serialized 1x Replicated 20                  100%     3.2 GB 0.0 B

Host    On Heap Memory Usage            Off Heap Memory Usage   Disk Usage
Node 1  643.5 MB (1931.3 MB Remaining)  0.0 B (0.0 B Remaining) 0.0 B
Master  0.0 B (366.3 MB Remaining)      0.0 B (0.0 B Remaining) 0.0 B
Node 2  654.8 MB (1920.0 MB Remaining)  0.0 B (0.0 B Remaining) 0.0 B
Node 3  644.2 MB (1930.6 MB Remaining)  0.0 B (0.0 B Remaining) 0.0 B
Node 4  656.2 MB (1918.6 MB Remaining)  0.0 B (0.0 B Remaining) 0.0 B
Node 5  652.4 MB (1922.4 MB Remaining)  0.0 B (0.0 B Remaining) 0.0 B

这似乎表明每个节点只有大约 2.5 GB 的可用内存。在我的 spark 应用程序出现内存不足错误之前,存储选项卡也永远不会接近显示 25 GB 的缓存 RDD。

如何知道为缓存的 RDD 分配了多少内存?

提交作业时,可以指定参数spark.memory.storageFraction。默认值为 0.5。

因此,在您为执行程序分配 5G 内存的情况下,将保留 2.5G 用于缓存,其余 2.5G 将用于执行。

来自Memory Management

spark.memory.storageFraction

Amount of storage memory immune to eviction, expressed as a fraction of the size of the region set aside by s​park.memory.fraction. The higher this is, the less working memory may be available to execution and tasks may spill to disk more often. Leaving this at the default value is recommended. For more detail, see this description.