问题: spark driver 或者 executor pod频繁被k8s kill。被kill前,查看spark ui,发现driver或者executor的gc根本不严重,明显不是jvm问题。
The executor with id 4 exited with exit code 137(SIGKILL, possible container OOM).
出现场景: 一般出现在spark任务和磁盘、网络等有大量数据交互等情形。此时,pod占用里大量非jvm内存,所以即使增加spark.executor. memory 值,也无法解决问题。
原因: 出现这种情况,说明pod申请使用的内存超过pod 的 limit 限制,容器被强制杀掉了
容器对正在运行的executor的最大内存大小由spark.executor. memoryoverhead和spark.executor.memory, spark.memory.offHeap.size和spark.executor.pyspark.memory的总和决定的。
由于我们没有使用pySpark和offHeap menory,所以spark.executor. memory + spark.executor. memoryoverhead = 容器 limit memory。
所以只需要增大spark.executor. memoryoverhead即可
(memoryoverhead:为每个执行程序进程分配额外的非堆内存。这是用于VM开销、内部字符串、其他本机开销等的内存。这往往随着容器的大小而增长)
修改方法:
1.适当调大spark参数的值:spark.kubernetes.memoryOverheadFactor=0.2 (默认0.1)
2.也可以单独增加driver或者executor的值(这两个参数从spark3.3.0才开始支持):spark.driver.memoryOverheadFactor和spark.executor.memoryOverheadFactor
参考文档:https://spark.apache.org/docs/latest/running-on-kubernetes.html#spark-properties