如何解决 Amazon EMR 上 Spark 中的“设备上没有剩余空间”阶段故障?
上次更新时间:2020 年 1 月 8 日
我向 Apache EMR 集群提交了 Apache Spark 应用程序。应用程序失败,出现“设备上没有剩余空间”阶段失败,如下所示:
Job aborted due to stage failure: Task 31 in stage 8.0 failed 4 times, most recent failure: Lost task 31.3 in stage 8.0 (TID 2036, ip-xxx-xxx-xx-xxx.compute.internal, executor 139): org.apache.spark.memory.SparkOutOfMemoryError: error while calling spill() on org.apache.spark.util.collection.unsafe.sort.UnsafeExternalSorter@1a698b89 : No space left on device
简短描述
Spark 使用核心节点和任务节点上的本地磁盘来存储中间数据。如果磁盘空间不足,则作业将失败,并显示“设备上没有剩余空间”错误。使用以下方法之一来解决此错误:
- 添加更多 Amazon Elastic Block Store (Amazon EBS) 容量。
- 添加更多 Spark 分区。
- 使用引导操作以动态扩展核心节点和任务节点上的存储。有关更多信息和建议的引导操作脚本,请参阅在 Amazon EMR 集群上动态扩展存储。
解决方法
添加更多 EBS 容量
对于新集群:使用更大的 EBS 卷
启动 Amazon EMR 集群,然后选择具有更大 EBS 卷的 Amazon Elastic Compute Cloud (Amazon EC2) 实例类型。有关为每种实例类型分配的存储量和卷数量的更多信息,请参阅实例的默认 EBS 存储。
对于正在运行的集群:增加 EBS 卷
1. 如果使用更大的 EBS 卷仍无法解决问题,请将更多的 EBS 卷挂载到核心节点和任务节点。
2. 格式化并安装挂载的卷。请务必使用正确的磁盘编号(例如,/mnt1 或 /mnt2 而不是 /data)。
3. 使用 SSH 连接到节点。
4. 创建 /mnt2/yarn 目录,然后 将目录所有权设置为 YARN 用户:
sudo mkdir /mnt2/yarn
chown yarn:yarn /mnt2/yarn
5. 在 /etc/hadoop/conf/yarn-site.xml 的 yarn.nodemanager.local-dirs 属性内部添加目录 /mnt2/yarn。示例:
<property>
<name>yarn.nodemanager.local-dirs</name>
<value>/mnt/yarn,/mnt1/yarn,/mnt2/yarn</value>
</property>
6. 重启 NodeManager 服务:
sudo stop hadoop-yarn-nodemanager
sudo start hadoop-yarn-nodemanager
添加更多 Spark 分区
根据集群中的核心节点和任务节点的数量,考虑增加 Spark 分区数。使用以下 Scala 代码添加更多 Spark 分区:
val numPartitions = 500
val newDF = df.repartition(numPartitions)