How do I resolve "no space left on device" stage failures in Spark on Amazon EMR?
"I submitted an Apache Spark application to an Amazon EMR cluster. The application fails with a "no space left on device" stage failure similar to the following: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"
"I submitted an Apache Spark application to an Amazon EMR cluster. The application fails with a "no space left on device" stage failure similar to the following: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 deviceShort descriptionSpark uses local disks on the core and task nodes to store intermediate data. If the disks run out of space, then the job fails with a "no space left on device" error. Use one of the following methods to resolve this error:Add more Amazon Elastic Block Store (Amazon EBS) capacity.Add more Spark partitions.Use a bootstrap action to dynamically scale up storage on the core and task nodes. For more information and an example bootstrap action script, see Dynamically scale up storage on Amazon EMR clusters.ResolutionAdd more EBS capacityFor new clusters: use larger EBS volumesLaunch an Amazon EMR cluster and choose an Amazon Elastic Compute Cloud (Amazon EC2) instance type with larger EBS volumes. For more information about the amount of storage and number of volumes allocated for each instance type, see Default Amazon EBS storage for instances.For running clusters: add more EBS volumes1.    If larger EBS volumes don't resolve the problem, attach more EBS volumes to the core and task nodes.2.    Format and mount the attached volumes. Be sure to use the correct disk number (for example, /mnt1 or /mnt2 instead of /data).3.    Connect to the node using SSH.4.    Create a /mnt2/yarn directory, and then  set ownership of the directory to the YARN user:sudo mkdir /mnt2/yarnchown yarn:yarn /mnt2/yarn5.    Add the /mnt2/yarn directory inside the yarn.nodemanager.local-dirs property of /etc/hadoop/conf/yarn-site.xml. Example:<property>    <name>yarn.nodemanager.local-dirs</name>    <value>/mnt/yarn,/mnt1/yarn,/mnt2/yarn</value></property>6.    Restart the NodeManager service:sudo stop hadoop-yarn-nodemanagersudo start hadoop-yarn-nodemanagerAdd more Spark partitionsDepending on how many core and task nodes are in the cluster, consider increasing the number of Spark partitions. Use the following Scala code to add more Spark partitions:val numPartitions = 500val newDF = df.repartition(numPartitions)Related informationHow can I troubleshoot stage failures in Spark jobs on Amazon EMR?Follow"