You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A long time before jobs start running when reading parquet files #4701
hangs longer than I have the patience to wait for (more than an hour). The workers never light up in the dask dashboard.
So, to try to get some insight, I wrote a function that just loads each parquet file into a pandas dataframe and returns its memory usage. I then randomly selected 100 of the files and submitted that function as a dask.delayed ie.
This takes about 3 minutes to run. About 5 seconds of that is the actual work being done by the workers. Each file takes up about 70-80 MB in memory, so it's not a memory overrun. (That's why I was checking this.)
What am I missing? Is there some configuration change that will make this more performant?
This is not an issue with dask-yarn. I strongly suspect that you have no _metadata file in your parquet file hierarchy. Which parquet backend are you using? With fastparquet if you do have that metadata file or if you pass infer_divisions=False, you should be able to skip fetching details of every file from the main client thread before handing work off to the cluster.
Note that, even in the best case, simply listing 16000 files takes some time, just bear this in mind.
Yeah, this is hitting several different (potential) issues with dask's parquet reader. I'm going to transfer this issue over to dask/dask as that location is a better fit.
changed the title [-]A long time before jobs start running on cluster on EMR[/-][+]A long time before jobs start running when reading parquet files[/+]on Apr 15, 2019
I suspected that it was dask's parquet reader as well, which is why I did something like this to get around it by using pandas parquet reader directly
fs=s3fs.S3FileSystem()
defread_parquet_file_from_s3(filename):
withfs.open(filename, mode='rb') asf:
returnpd.read_parquet(f, engine='pyarrow') # also tried fastparquet, pyarrow was fasterdf=dd.from_delayed(map(dask.delayed(read_parquet_file_from_s3), parquet_file_list))
Running that function takes about 300 ms in the main thread. Mapping it to 100 files takes ~3 minutes. 2:55 of that the workers weren't doing anything.
Running that function takes about 300 ms in the main thread. Mapping it to 100 files takes ~3 minutes. 2:55 of that the workers weren't doing anything.
Hmmm, that is odd. That still has nothing to do with dask-yarn (which only sets up the workers). You might look at the profile tab of the dashboard, or using Client.profile to collect some profiling information. Are the workers idle for 2:55 and then do work for the last 0:05? Is there any way you could build a reproducible example showing this issue? This is not something I've seen before when using parquet with dask.
Is that also true for your delayed way? The only thing I see there that needs pickling is the fs instance, which would surprise me a lot. (You could create the instance in the function rather than include it in the closure for pickling)
Does it try to pickle all of pandas as well or is it smart enough to know that it can import that?
cloudpickle will only serialize functions as bytecode for functions defined in __main__ (e.g. in an interpreter or script). Anything imported will be assumed to have the same import paths on the workers.
What it looks like you're seeing here is that fs is included in the closure of your function (instead of creating it in the function or using it as a parameter), leading to a potentially slower pickling path. I'm not sure why this would lead to that much of a slowdown though - cloudpickle is usually pretty smart about these things. Do you still get the speedup if you use fs as a parameter instead?
Could also try serializing the filesystem separately once to the cluster:
fs=dask.delayed(s3fs.S3FileSystem()) # keeps this as a separate value in the grapu@dask.delayeddefread_parquet_file_from_s3(fs, filename):
withfs.open(filename, mode='rb') asf:
returnpd.read_parquet(f, engine='pyarrow')
df=dd.from_delayed(read_parquet_file_from_s3(fs, fn) forfninparquet_file_list)
If these are both fast, something may be odd with cloudpickle, otherwise something is maybe odd with s3fs.
I've been having the same problem. My data is ~5000 files. The above pasted code was really helpful for being able to take a look at my data, but I was having the same problem when I tried to write my processed data out.
I was regularly seeing errors about too many files open which I never got to the bottom of fixing.
In the end what I did was this:
read my data in with spark and then out again - this assembled all my data in one directory (previously it was nested into many smaller subdirectories) and also merged it into a smaller number ~500 file (this was unintentional but seemed to help)
I then went back to dask, read my data in, repartitioned to 5000 partitions, performed all my processing and saved, and everything's working.
It turned out to be too slow to work with 5000 files, I'm down to 1200 which is the smallest I can get away with for the size of my data. Even still something as simple as df.head() on 1200 files which do have _common_metadata is taking minutes.
@martindurant can you explain the mechanism to me a little.
I'm doing my profiling on just df = dd.read_parquet('s3://file', ....) This line is taking about 5 minutes to run on for a 1200 partition parquet file on s3. I haven't tried to compute anything.
Why does dask need to read every parquet partition in order to compute start building the graph? I understand reading the directory or needing to gather all the file names, but that's different than opening every file. If it's to check metadata, could a user be able to supply a schema to bypass this step (at the user's own risk?). Or do you need to construct an index or something?
My frustration is that my parallelized operation takes seconds with the size of cluster i have, which includes the read, but getting started takes minutes. Now it may be that my read is benefit from some cacheing that's happening after the initial graph reading. Oddly though i don't benefit from any cacheing in the future. If data has been loaded on first read, I would have thought second read would be quicker.
Parquet maintains more information in its metadata besides the schema: it includes the max and min of the values of each column within each chunk. Dask uses this information to construct the "divisions" of a dataframe, if possible, so that when you do a selection df.loc[..], Dask can figure out which of the partitions don't need to be loaded. This in general is a very useful optimisation, especially when all of the max/min values are held in the special _metadata file, which can be read in a single operation.
Using dd.read_parquet(..., infer_divisions=False), tells Dask that you don't care about the divisions and don't expect to gain from this sort of optimisation - so it can skip reading the metadata parts of all of the files.
@birdsarah we recently rewrote how Dask handles Parquet in
#4995 . You might want to try things out
on master. I'm not sure that it solves all of your problems, but it may
solve some?
With #5157 I believe this is done for fastparquet.
Am I right in thinking @martindurant@pitrou that this fast load cannot be achieved with pyarrow as pyarrow insists on doing it's own on-load checks on parquet parts without metadata?
@birdsarah I think we can probably tweak the pyarrow engine to do something similar to the fastparquet engine in #5157. Hopefully I’ll have time to test this tomorrow.
Readability issues with https://github.com/dask/dask/blob/master/dask/dataframe/io/parquet/fastparquet.py aside (I had to spend some time parsing what is going on in read_metadata -- I would personally refactor to make some helper functions to help with readability) I don't see a problem with doing the same work for the Arrow engine. I believe there are still some follow up items having to do with the _metadata and _common_metadata files but I have not kept track of what they are. If you run into issues please do open JIRA issues so we don't lose track of the work
Closing this as stale and unactionable. Parquet performance has improved considerably in the last few years, and there are several other issues tracking parquet performance and heuristics that are better scoped. Closing.
Activity
martindurant commentedon Apr 15, 2019
This is not an issue with dask-yarn. I strongly suspect that you have no
_metadatafile in your parquet file hierarchy. Which parquet backend are you using? With fastparquet if you do have that metadata file or if you passinfer_divisions=False, you should be able to skip fetching details of every file from the main client thread before handing work off to the cluster.Note that, even in the best case, simply listing 16000 files takes some time, just bear this in mind.
jcrist commentedon Apr 15, 2019
Yeah, this is hitting several different (potential) issues with dask's parquet reader. I'm going to transfer this issue over to dask/dask as that location is a better fit.
[-]A long time before jobs start running on cluster on EMR[/-][+]A long time before jobs start running when reading parquet files[/+]nmerket commentedon Apr 15, 2019
I suspected that it was dask's parquet reader as well, which is why I did something like this to get around it by using pandas parquet reader directly
Running that function takes about 300 ms in the main thread. Mapping it to 100 files takes ~3 minutes. 2:55 of that the workers weren't doing anything.
jcrist commentedon Apr 15, 2019
Hmmm, that is odd. That still has nothing to do with dask-yarn (which only sets up the workers). You might look at the profile tab of the dashboard, or using
Client.profileto collect some profiling information. Are the workers idle for 2:55 and then do work for the last 0:05? Is there any way you could build a reproducible example showing this issue? This is not something I've seen before when using parquet with dask.nmerket commentedon Apr 15, 2019
When I hook it up to a profiler (snakeviz) what I'm seeing is that 383/387 seconds running were spent pickling.
martindurant commentedon Apr 15, 2019
Is that also true for your delayed way? The only thing I see there that needs pickling is the
fsinstance, which would surprise me a lot. (You could create the instance in the function rather than include it in the closure for pickling)nmerket commentedon Apr 15, 2019
Yes, that was for my delayed way. Does it try to pickle all of pandas as well or is it smart enough to know that it can import that?
nmerket commentedon Apr 15, 2019
Whoa, when I move the
fsinstance creation inside the function, it's almost immediate now.jcrist commentedon Apr 15, 2019
cloudpickle will only serialize functions as bytecode for functions defined in
__main__(e.g. in an interpreter or script). Anything imported will be assumed to have the same import paths on the workers.What it looks like you're seeing here is that
fsis included in the closure of your function (instead of creating it in the function or using it as a parameter), leading to a potentially slower pickling path. I'm not sure why this would lead to that much of a slowdown though - cloudpickle is usually pretty smart about these things. Do you still get the speedup if you usefsas a parameter instead?Could also try serializing the filesystem separately once to the cluster:
If these are both fast, something may be odd with cloudpickle, otherwise something is maybe odd with s3fs.
birdsarah commentedon Apr 28, 2019
I've been having the same problem. My data is ~5000 files. The above pasted code was really helpful for being able to take a look at my data, but I was having the same problem when I tried to write my processed data out.
I was regularly seeing errors about too many files open which I never got to the bottom of fixing.
In the end what I did was this:
birdsarah commentedon Apr 28, 2019
It turned out to be too slow to work with 5000 files, I'm down to 1200 which is the smallest I can get away with for the size of my data. Even still something as simple as df.head() on 1200 files which do have _common_metadata is taking minutes.
martindurant commentedon Apr 28, 2019
Are you using
infer_divisions=False?birdsarah commentedon Apr 28, 2019
No, should I?
4 remaining items
birdsarah commentedon May 1, 2019
Thanks to some help from @mrocklin on how to go about profiling, I've so far learned the following:
When reading from local disk, the top of my profile is:
when reading from s3 it is:
First thing to note is that _parquet.ParquetReader is getting called 2x as many partitions as I have (in both s3 and local)
After some more digging:
birdsarah commentedon May 1, 2019
@martindurant can you explain the mechanism to me a little.
I'm doing my profiling on just
df = dd.read_parquet('s3://file', ....)This line is taking about 5 minutes to run on for a 1200 partition parquet file on s3. I haven't tried to compute anything.Why does dask need to read every parquet partition in order to compute start building the graph? I understand reading the directory or needing to gather all the file names, but that's different than opening every file. If it's to check metadata, could a user be able to supply a schema to bypass this step (at the user's own risk?). Or do you need to construct an index or something?
My frustration is that my parallelized operation takes seconds with the size of cluster i have, which includes the read, but getting started takes minutes. Now it may be that my read is benefit from some cacheing that's happening after the initial graph reading. Oddly though i don't benefit from any cacheing in the future. If data has been loaded on first read, I would have thought second read would be quicker.
martindurant commentedon May 1, 2019
Parquet maintains more information in its metadata besides the schema: it includes the max and min of the values of each column within each chunk. Dask uses this information to construct the "divisions" of a dataframe, if possible, so that when you do a selection df.loc[..], Dask can figure out which of the partitions don't need to be loaded. This in general is a very useful optimisation, especially when all of the max/min values are held in the special _metadata file, which can be read in a single operation.
Using
dd.read_parquet(..., infer_divisions=False), tells Dask that you don't care about the divisions and don't expect to gain from this sort of optimisation - so it can skip reading the metadata parts of all of the files.birdsarah commentedon Jul 23, 2019
Update: pyarrow now creates _metadata https://issues.apache.org/jira/browse/ARROW-1983 (v0.14.0)
mrocklin commentedon Jul 23, 2019
birdsarah commentedon Jul 23, 2019
:) I'm just reading the PR.
birdsarah commentedon Jul 26, 2019
With #5157 I believe this is done for fastparquet.
Am I right in thinking @martindurant @pitrou that this fast load cannot be achieved with pyarrow as pyarrow insists on doing it's own on-load checks on parquet parts without metadata?
rjzamora commentedon Jul 26, 2019
@birdsarah I think we can probably tweak the pyarrow engine to do something similar to the fastparquet engine in #5157. Hopefully I’ll have time to test this tomorrow.
martindurant commentedon Jul 26, 2019
Agree, definitely think that pyarrow should be able to do this too
pitrou commentedon Jul 26, 2019
I'm not competent on this, but @wesm may have an answer.
wesm commentedon Jul 26, 2019
Readability issues with https://github.com/dask/dask/blob/master/dask/dataframe/io/parquet/fastparquet.py aside (I had to spend some time parsing what is going on in read_metadata -- I would personally refactor to make some helper functions to help with readability) I don't see a problem with doing the same work for the Arrow engine. I believe there are still some follow up items having to do with the _metadata and _common_metadata files but I have not kept track of what they are. If you run into issues please do open JIRA issues so we don't lose track of the work
jcrist commentedon Apr 13, 2022
Closing this as stale and unactionable. Parquet performance has improved considerably in the last few years, and there are several other issues tracking parquet performance and heuristics that are better scoped. Closing.