Spark Driver内存计算

Spark Driver Memory calculation

我知道如何计算执行器内核 memory.But 谁能解释一下 spark.driver.memory 是根据什么计算的?

Spark 驱动程序内存 是用于驱动程序进程的内存量,即 进程 运行 的 main() 函数应用程序和初始化 SparkContext 的地方,格式与带有大小单位后缀的 JVM 内存字符串相同("k"、"m"、"g" 或 "t") (例如 512m、2g)。

JVM 内存 被分成独立的部分。从广义上讲,JVM 堆内存在物理上分为两部分——新生代老年代.

年轻代是所有新对象创建的地方。当年轻代被填满时,就会进行垃圾回收。这种垃圾收集称为次要 GC。

Old Generation内存中包含了经过多轮Minor GC后存活时间长的对象。通常垃圾回收是在老年代内存满的时候进行的。 Old Generation Garbage Collection称为Major GC,通常需要更长的时间。

Java 垃圾收集 是从内存中识别和删除未使用的对象并释放 space 分配给在未来处理。 java 编程语言的最佳特性之一是自动垃圾收集,这与 C 等其他编程语言不同,后者的内存分配和释放是手动过程。

垃圾收集器是后台程序运行,它查看内存中的所有对象并找出未被任何部分引用的对象程序。所有这些未引用的对象都被删除,space 被回收以分配给其他对象。

来源:

https://spark.apache.org/docs/latest/configuration.html

https://www.journaldev.com/2856/java-jvm-memory-model-memory-management-in-java#java-memory-model-8211-permanent-generation

Dataset 的操作,例如 collect take 需要将所有数据移动到应用程序的驱动程序进程中,并且在非常大的数据集上这样做可能会使驱动程序进程崩溃OutOfMemoryError.

当您向驱动程序收集大量数据时,您会增加 spark.driver.memory

根据

High Performance Spark by Holden Karau and Rachel Warren (O’Reilly)

most of the computational work of a Spark query is performed by the executors, so increasing the size of the driver rarely speeds up a computation. However, jobs may fail if they collect too much data to the driver or perform large local computations. Thus, increasing the driver memory and correspondingly the value of spark.driver.maxResultSize may prevent the out-of-memory errors in the driver.

A good heuristic for setting the Spark driver memory is simply the lowest possible value that does not lead to memory errors in the driver, i.e., which gives the maximum possible resources to the executors.