Built with Tutify.io

    AIStudyLabs

    Spark Persistence Levels

    Spark Persistence Levels

    Spark Persistence Storage Levels

    All different storage levels of Spark supports are available in org.apache.spark.storage.StorageLevel class. The storage level specifies how and where to persist or cache a Spark DataFrame and Dataset.

    MEMORY_ONLY – This is the default behavior of the RDD cache() method and stores the RDD or DataFrame as deserialized objects in JVM memory. When there is not enough memory available, it will not save RDD of some partitions and these will be re-computed as and when required. This takes more memory. 

    MEMORY_ONLY_SER – This is the same as MEMORY_ONLY but the difference is that it stores RDD as serialized objects in JVM memory. It takes less memory (space-efficient) than MEMORY_ONLY as it saves objects as serialized and takes an additional few more CPU cycles in order to deserialize.

    MEMORY_ONLY_2 – Same as MEMORY_ONLY storage level but replicate each partition to two cluster nodes.

    MEMORY_ONLY_SER_2 – Same as MEMORY_ONLY_SER storage level but replicate each partition to two cluster nodes.

    MEMORY_AND_DISK – This is the default behavior of the DataFrame or Dataset. In this Storage Level, The DataFrame will be stored in JVM memory as a deserialized object. When required storage is greater than available memory, it stores some of the excess partitions into the disk and reads the data from the disk when required. It is slower as there is I/O involved.

    MEMORY_AND_DISK_SER – This is the same as MEMORY_AND_DISK storage level difference being it serializes the DataFrame objects in memory and on disk when space is not available.

    MEMORY_AND_DISK_2 – Same as MEMORY_AND_DISK storage level but replicate each partition to two cluster nodes.

    MEMORY_AND_DISK_SER_2 – Same as MEMORY_AND_DISK_SER storage level but replicate each partition to two cluster nodes.

    DISK_ONLY – In this storage level, DataFrame is stored only on disk and the CPU computation time is high as I/O is involved.

    DISK_ONLY_2 – Same as DISK_ONLY storage level but replicate each partition to two cluster nodes.

    Below is the table representation of the Storage level, Go through the impact of space, CPU, and performance. Choose the one that best fits your needs.

    Storage Level    Space used  CPU time  In memory  On-disk  Serialized   Recompute some partitions
    ----------------------------------------------------------------------------------------------------
    MEMORY_ONLY          High        Low       Y          N        N         Y    
    MEMORY_ONLY_SER      Low         High      Y          N        Y         Y
    MEMORY_AND_DISK      High        Medium    Some       Some     Some      N
    MEMORY_AND_DISK_SER  Low         High      Some       Some     Y         N
    DISK_ONLY            Low         High      N          Y        Y         N
    

    Some Points to note on Persistence

    Apache Spark Tutorial with Scala Examples — Cache, Persistence and Shared Variables

    Introduction to Apache Spark

    Setup Apache Spark Environment

    SparkSession & SparkContext

    Resilient Distributed Datasets (RDDs)

    Apache Spark Concepts

    Cache, Persistence and Shared Variables

    DataFrame Introduction

    DataFrame Narrow Transformation

    DataFrame Wider Transformation

    DataFrame Actions

    Spark SQL Functions

    Advanced DataFrame Features

    Using SQL Queries

    Spark Read & Write CSV Files

    Working with JSON Files

    Working with Parquet Files

    Spark Dataset

    What Next?

    Tutorial Not Found