Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spark cache only keeps a fraction of RDD

When I explicitly call rdd.cache, I can see from the spark console storage tab that only a fraction of the rdd is actually cached. My question is where are the remaining parts? How does Spark decide which part to leave in cache?

The same question applies to the initial raw data read in by sc.textFile(). I understand these rdd's are automatically cached, even though the spark console storage table does not display any information on their cache status. Do we know how much of those are cached vs. missing?

like image 325
bhomass Avatar asked Apr 07 '15 22:04

bhomass


People also ask

How much data we can cache in Spark?

It is 0.6 x (JVM heap space - 300MB) by default.

What happens when cache memory is full in Spark?

unpersist() . If the caching layer becomes full, Spark will start evicting the data from memory using the LRU (least recently used) strategy. So it is good practice to use unpersist to stay more in control about what should be evicted.

What is the default storage level of cache () in Spark?

The cache method calls persist method with default storage level MEMORY_AND_DISK. Other storage levels are discussed later. The rule of thumb for caching is to identify the Dataframe that you will be reusing in your Spark Application and cache it.


1 Answers

cache() is the same as persist(StorageLevel.MEMORY_ONLY), and your amount of data probably exceeds the available memory. Spark then evicts caches in a "least recently used" manner.

You can tweak the reserved memory for caching by setting configuration options. See the Spark Documentation for details and look out for: spark.driver.memory, spark.executor.memory, spark.storage.memoryFraction

Not an expert, but I do not think that textFile() automatically caches anything; the Spark Quick Start explicitly caches a text file RDD: sc.textFile(logFile, 2).cache()

like image 147
stholzm Avatar answered Oct 21 '22 10:10

stholzm