Repository navigation
Description
I am trying to convert a number of large .csv files to the parquet format using python and dask.
This is the code that I use:
client = Client()
trans = dd.read_csv(os.path.join(TRANS_PATH, "*.TXT"),
sep=";", dtype=col_types, parse_dates=['salesdate'])
trans = trans.drop('salestime', axis=1)
trans['month_year'] = trans['salesdate'].dt.strftime('M_%Y_%m')
trans['key'] = trans['chainid'] + trans['barcode']
trans = trans.join(attribs[['catcode']], on=['key'])
trans.to_parquet(PARQUET_PATH, engine="fastparquet", compression='snappy',
partition_on=['catcode', 'month_year'], append=False)
The code seems to run fine and all the parquet files are created under the correct directories with no warnings almost until the end. The graph execution reaches until here:

At this point the program gets stuck for a minute or so, and then the following warnings get raised:
distributed.nanny - WARNING - Worker exceeded 95% memory budget. Restarting
distributed.nanny - WARNING - Worker process 16996 was killed by signal 15
distributed.nanny - WARNING - Restarting worker
After the warning, a few hundred processes get restarted and are executed again:

This happens three times and the program finally crashes:
tornado.application - ERROR - Exception in callback <bound method Nanny.memory_monitor of <Nanny: tcp://127.0.0.1:49290, threads: 2>>
Traceback (most recent call last):
File "C:\Users\mrfksiv\Anaconda3\envs\tensorflow\lib\site-packages\psutil\_pswindows.py", line 635, in wrapper
return fun(self, *args, **kwargs)
File "C:\Users\mrfksiv\Anaconda3\envs\tensorflow\lib\site-packages\psutil\_pswindows.py", line 751, in memory_info
t = self._get_raw_meminfo()
File "C:\Users\mrfksiv\Anaconda3\envs\tensorflow\lib\site-packages\psutil\_pswindows.py", line 726, in _get_raw_meminfo
return cext.proc_memory_info(self.pid)
ProcessLookupError: [Errno 3] No such process
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\mrfksiv\Anaconda3\envs\tensorflow\lib\site-packages\tornado\ioloop.py", line 1026, in _run
return self.callback()
File "C:\Users\mrfksiv\Anaconda3\envs\tensorflow\lib\site-packages\distributed\nanny.py", line 262, in memory_monitor
memory = proc.memory_info().rss
File "C:\Users\mrfksiv\Anaconda3\envs\tensorflow\lib\site-packages\psutil\_common.py", line 338, in wrapper
return fun(self)
File "C:\Users\mrfksiv\Anaconda3\envs\tensorflow\lib\site-packages\psutil\__init__.py", line 1044, in memory_info
return self._proc.memory_info()
File "C:\Users\mrfksiv\Anaconda3\envs\tensorflow\lib\site-packages\psutil\_pswindows.py", line 640, in wrapper
raise NoSuchProcess(self.pid, self._name)
I believe that this is a bug because if I use fewer .csv files then everything works. Even then however, if I then try to append the rest of the data using the dd.read_parquet( ... append=True) the same error occurs. I have also tried reducing the number of workers by passing a LocalCluster to Client so that they have more memory available, but this didn't help either.
python 3.5.5
dask 0.18.2
distributed 1.22.0
fastparquet 0.1.5
Activity
TomAugspurger commentedon Aug 14, 2018
I ran into this last week. I almost have a reproducible example ready to go.
martindurant commentedon Aug 14, 2018
It seems unlikely, but it is possible that 397 sets of chunk metadata is very large in memory, if the number of columns is also very large. I have never done explicit measures of how many bytes of metadata such be expected, and where noticeable cuts could be made.
MrfksIv commentedon Aug 14, 2018
Hi @martindurant , the image above is from when i was trying to load the entire collection of the csv files at once. I have already tried using subsets of the files and setting append=True but the same thing happened. The total number of columns is 16 by the way.
martindurant commentedon Aug 14, 2018
Append also requires all of the metadata in memory at once, so I would not expect any difference there.
MrfksIv commentedon Aug 14, 2018
Actually this clears up another thing that i have noticed, that by looping through the files, it took longer and longer for execution to commence and sometimes it threw a warning that the size of the graph was too big.
Does this mean that currently there is an ‘upper bound’ to the amount of data that dask with fastparquet can handle or is this strictly a metadata issue? If it is the latter then maybe joining the csv files to reduce the number of tasks will help?
martindurant commentedon Aug 14, 2018
Yes and no. There is the problem of metadata presented here, which goes as the (number of partitions * the number of columns) and which, as I have said, I haven't strictly tried to measure or ameliorate. Some parquet frameworks do not use a metadata file, perhaps for this reason - but fastparquet would scan all files if given a list without a metadata file and come to the same problem.
There are also some internal limits in the parquet spec to do with the binary types of the variables describing the bytesize of a given block, the number of rows in a page, the number of rows in a row-group (partition), etc. We have met some of these, but the combination is generally flexible enough to accommodate very large data.
Yes, that may well help. Of course, you don't want partitions for which any one takes up too much memory either, so there is a trade-off.
martindurant commentedon Aug 14, 2018
Note that it would be technically possible for fastparquet to open many files without merging into one in-memory metadata to do so, but this would take an not-insignificant amount of coding. If it existed, that would allow "append" to be the same as just writing more files to an existing parquet directory.
mrocklin commentedon Oct 22, 2018
@TomAugspurger you mention running into this as well. I know that this was a while ago, but do you recall what might have triggered things?
TomAugspurger commentedon Oct 23, 2018
IIRC, the thing that most helped me was avoiding
DataFrame.categorize. When I switched away from that to roughlyI noticed that things were better behaved memory-wise. Is it possible that
categorizethrows of the distributed scheduler's memory estimates? This is all from memory though, so I could be mis-remembering.jcrist commentedon May 13, 2022
With #8901, we no longer write
_metadatafiles by default, which should remove this problem. There may be some upstream fixes in pyarrow that could improve the scalability limit of producing the_metadatafile, but at some point the full dataset metadata will always become too large for a single worker to process. Other tools like spark have come to the same conclusion and made the same change. Closing.Don't write metadata file (#875)