โ05-22-2024 11:57 PM
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!
โ05-23-2024 02:30 AM
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?
โ05-23-2024 02:30 AM
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?
โ05-23-2024 02:33 AM
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.
โ05-23-2024 09:00 AM
Thanks @-werners-,
That's right, I tried and get some significantly performance.
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