cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Disk cache for csv file in Databricks

NhanNguyen
Contributor II

Dear team,

I'm investigate to improve performance when reading large csv file as input and find this https://learn.microsoft.com/en-us/azure/databricks/optimizations/disk-cache.

I just wonder Do disk-cache also apply for csv file?

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions

-werners-
Esteemed Contributor III

The answer is "yes but".
If you read a csv into a dataframe, and apply a cache action, no matter what file format, it will be cached (if spark can read it of course).
That being said: spark applies lazy evaluation. So this means the csv is only actually read when an action is executed (like write, count, ...).  Before that Spark will only generate a query plan.
So to speed up your code, it is important to find out what the best location is to apply the cache.  Because caching is an expensive operation (it actually writes the data to disk) and it will only come in handy if the cached dataframe is used more than once afterwards.
Not sure if that makes sense?

View solution in original post

3 REPLIES 3

-werners-
Esteemed Contributor III

The answer is "yes but".
If you read a csv into a dataframe, and apply a cache action, no matter what file format, it will be cached (if spark can read it of course).
That being said: spark applies lazy evaluation. So this means the csv is only actually read when an action is executed (like write, count, ...).  Before that Spark will only generate a query plan.
So to speed up your code, it is important to find out what the best location is to apply the cache.  Because caching is an expensive operation (it actually writes the data to disk) and it will only come in handy if the cached dataframe is used more than once afterwards.
Not sure if that makes sense?

-werners-
Esteemed Contributor III

To add on that: Disk cache (formerly detla cache/dbio cache) automates some things, but the principle remains:
you will only gain if the cached df is used multiple times.

NhanNguyen
Contributor II

Thanks @-werners-,

That's right, I tried and get some significantly performance.

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group