Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to uncache RDD?

I used cache() to cache the data in memory but I realized to see the performance without cached data I need to uncache it to remove data from memory:

rdd.cache();
//doing some computation
...
rdd.uncache()

but I got the error said:

value uncache is not a member of org.apache.spark.rdd.RDD[(Int, Array[Float])]

I don't know how to do the uncache then!

like image 603
Rubbic Avatar asked Sep 19 '14 16:09

Rubbic


People also ask

How do I Uncache a DataFrame Pyspark?

Spark automatically monitors cache usage on each node and drops out old data partitions in a least-recently-used (LRU) fashion. If you would like to manually remove an RDD instead of waiting for it to fall out of the cache, use the RDD. unpersist() method.

How do I cache RDD?

Caching RDDs in Spark There are two function calls for caching an RDD: cache() and persist(level: StorageLevel). The difference among them is that cache() will cache the RDD into memory, whereas persist(level) can cache in memory, on disk, or off-heap memory according to the caching strategy specified by level.

What does it mean to cache an RDD?

By default, each transformed RDD may be recomputed each time you run an action on it. However, you may also persist an RDD in memory using the persist (or cache) method, in which case Spark will keep the elements around on the cluster for much faster access the next time you query it.

How do I clear my Spark cache?

You can't clear cache in Spark 😔 You can reinstall the app.


3 Answers

RDD can be uncached using unpersist()

rdd.unpersist() 

source

like image 198
Josh Rosen Avatar answered Sep 24 '22 12:09

Josh Rosen


The uncache function doesn't exist. I think that you were looking for unpersist. Which according to the Spark ScalaDoc mark the RDD as non-persistent, and remove all blocks for it from memory and disk.

like image 31
eliasah Avatar answered Sep 21 '22 12:09

eliasah


If you want to remove all the cached RDDs, use this ::

for ((k,v) <- sc.getPersistentRDDs) {
  v.unpersist()
}
like image 23
Sankar Avatar answered Sep 21 '22 12:09

Sankar