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.

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!