Spark 运行产生Unable to acquire xxx bytes of memory 错误解决方法

背景:
对单月日志进行分析时(120G左右),生成结果csv文件时

      .coalesce(1)
      .write
      .mode(SaveMode.Overwrite)
      .format("com.databricks.spark.csv")
      .option("header", "true")
      .save("periodowntop10.csv")

**coalesce函数为控制结果文件个数为1 因为有多少个partition 就会在指定目录下生成对应个数的csv小文件

在集群运行时
会产生
Spark 运行产生Unable to acquire xxx bytes of memory 错误解决方法_第1张图片
Unable to acquire xxx bytes of memor这个错误

之前在估算数据源大小和产生数据大小时 最后生成的csv大概在10MB左右
查看运行参数设置

--master yarn --deploy-mode cluster  --executor-memory 6g --num-executors 3 --executor-cores 3 --driver-memory 2g --conf spark.default.parallelism=300

查看stage对应信息 发现问题产生在写入csv文件时,读取日志数据源时可以正确读取
所以没必要像大多数网上给出的答案直接粗暴加大executor内存

因为在写的时候在尽量避免shuffle的前提下,所以选择了coalesce
其实问题在.coalesce(1)上

根据
Dataset.coalesce().

However, if you’re doing a drastic coalesce, e.g. to numPartitions = 1, this may result in your computation taking place on fewer nodes than you like (e.g. one node in the case of numPartitions = 1). To avoid this, you can call repartition(1) instead. This will add a shuffle step, but means the current upstream partitions will be executed in parallel (per whatever the current partitioning is).

coalesce在参数过小时 例如1 并行度不够 只会在很少的节点上运行
而repartition(1)虽然会加入shuffle步骤,但是上游的分区会并行执行

结果: coalesce(1)改为 repartition(1) 问题解决

你可能感兴趣的:(Spark)