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
[Python] Dataset.to_batches accumulates memory usage and leaks #39808
Describe the bug, including details regarding any error messages, version, and platform.
If you want to read in a large parquet file or series of parquet files, the dataset reader accumulates the memory it allocates as you iterate through the batches.
To recreate:
importpyarrowaspaimportpyarrow.parquetaspqimportpyarrow.datasetasds# Create dataset from large parquet file or filesdataset=ds.dataset('data/parquet', format='parquet')
# Iterate through batchesforbatchindataset.to_batches(batch_size=1000, batch_readahead=0, fragment_readahead=0):
print(pa.total_allocated_bytes())
passprint(pa.total_allocated_bytes())
I am running this on OSX, which I believe uses mimalloc backend by default. It's worth noting that this is not the behavior that ParquetFile.iter_batches has. If you swap in that iterator, it will de-allocate the memory as soon as the batch leaves scope.
Component(s)
Parquet, Python
Reacted by Julianus Pfeuffer, Balaji Veeramani, John Bai, Alexey Volkov, Ilya Kochankov, Richard Liaw, Bo, Hanxun Huang, Takanori MAEHARA, bwi-earth and 15 more
changed the title [-]Dataset.to_batches accumulates memory usage and leaks[/-][+][Python] Dataset.to_batches accumulates memory usage and leaks[/+]on Jan 27, 2024
Can you print the output of what you see locally? (and ideally share a full reproducer that includes creating a dummy parquet file that reproduces the issue for you, in case it is dependent on the content/characteristics of the parquet file)
I am trying to reproduce this on my linux laptop, but I don't see a continuous increase in allocated bytes.
I see the following numbers (pyarrow 16.1.0, python 3.11.6):
Dataset.to_batches:
./pyarrow_39808_repro.py Dataset
Using Dataset.to_batches API
New max total_allocated_bytes 549322688
New max total_allocated_bytes 794176064
New max total_allocated_bytes 1094879616
New max total_allocated_bytes 1340710656
New max total_allocated_bytes 3732962048
New max total_allocated_bytes 4236869504
New max total_allocated_bytes 4849658496
New max total_allocated_bytes 6188106432
Final: 185074688
ParquetFile.iter_batches:
./pyarrow_39808_repro.py ParquetFile
Using ParquetFile.iter_batches API
New max total_allocated_bytes 252396608
New max total_allocated_bytes 252403456
<cut>
New max total_allocated_bytes 274519744
New max total_allocated_bytes 274521024
Final: 35072
i.e. ParquetFile.iter_batches requires at most ~261MB, whereas Dataset.to_batches requires ~5901MB - 22x more (!) - plus an additinal 176MB of RAM still in use after iteration complete.
Reacted by Varvara Kazarina, Higor E., Mike O'Connor, Yucai Yu, Marshall Ge, Michael Frye, Ilya Kochankov, Hanxun Huang, mtimmonsbrown-jumptrading, Julianus Pfeuffer and 2 more
Is it possible to ask for an update on this issue? I am currently running into the same memory leak in my project which gets mitigated when using Parquetfile.iter_batches instead of Dataset.to_batches. However, I'd like to use the HivePartition-discovering within Dataset.
Is there any update on this issue? I am also running into the same memory leak and would like to stick with Dataset.to_batches because of the HivePartition-discovering within PyArrow Dataset.
Activity
[-]Dataset.to_batches accumulates memory usage and leaks[/-][+][Python] Dataset.to_batches accumulates memory usage and leaks[/+]jorisvandenbossche commentedon Jan 30, 2024
Can you print the output of what you see locally? (and ideally share a full reproducer that includes creating a dummy parquet file that reproduces the issue for you, in case it is dependent on the content/characteristics of the parquet file)
I am trying to reproduce this on my linux laptop, but I don't see a continuous increase in allocated bytes.
daverigby commentedon Jun 12, 2024
I am observing the same thing with a single parquet file of 10M records (https://storage.googleapis.com/pinecone-datasets-dev/yfcc-10M-filter-euclidean-formatted/passages/part-0.parquet - 2.3GB).
Using code equivalent to OPs, I see
total_allocated_bytesincrease consistently over the run, requiring over 5.9GB to iterate the file.Using
ParquetFile.iter_batchesas suggested, memory usage is much more stable (although increases a little over the duration).Variation of the OPs reproducer code which includes the two modes:
I see the following numbers (pyarrow 16.1.0, python 3.11.6):
i.e.
ParquetFile.iter_batchesrequires at most ~261MB, whereasDataset.to_batchesrequires ~5901MB - 22x more (!) - plus an additinal 176MB of RAM still in use after iteration complete.WIP: Switch from Dataset.to_batches to ParquetFile.iter_batches
Switch from Dataset.to_batches to ParquetFile.iter_batches
PatrikBernhard commentedon Jul 30, 2024
Is it possible to ask for an update on this issue? I am currently running into the same memory leak in my project which gets mitigated when using
Parquetfile.iter_batchesinstead ofDataset.to_batches. However, I'd like to use the HivePartition-discovering within Dataset.mats-werrebrouck commentedon Nov 4, 2024
Is there any update on this issue? I am also running into the same memory leak and would like to stick with
Dataset.to_batchesbecause of the HivePartition-discovering within PyArrow Dataset.bveeramani commentedon Feb 5, 2025
Hey, is there any update on this issue? It impacts Ray's
read_parquetimplementation: ray-project/ray#49158alexeykudinkin commentedon Feb 5, 2025
@jorisvandenbossche would it be possible to clarify at least if the exhibited behavior is expected side-effect or not?
cherry pick e64047f - convert from dataset to ParquetFile because of …
HanxunH commentedon Apr 23, 2025
Any workaround? I'm also getting similar issues.
wingkitlee0 commentedon Apr 24, 2025
Came across this issue recently and I can still see this #39808 (comment)
Previously I tried
pre_buffer=Falseanduse_stream_buffer=TrueinParquetFragmentScanOptions, in which thetotal_allocated_bytesstopped growing.There is also a new option
cache_metadatainto_batches(not released yet; only dev version), which seems to reduce some %.However, the "memory usage" difference between dataset and ParquetFile is still quite big.
49 remaining items
apacheGH-39808: [C++][Parquet] Evict entries spanning filtered row gr…
apacheGH-39808: [C++] Replace EvictEntriesInRange with EvictEntriesBe…
apacheGH-39808: [C++][Parquet] Evict pre-buffered bytes via offset wa…
apacheGH-39808: [C++][Parquet] Test out-of-order pre-buffer eviction
apacheGH-39808: [C++][Parquet] Trim redundant comments
apacheGH-39808: [C++][Parquet] Fix cross-row-group test cache limits
apacheGH-39808: [C++][Parquet] Fall back after read-cache eviction
apacheGH-39808: [C++] Use deque for read-cache eviction
apacheGH-39808: [C++][Parquet] Address read-cache eviction review fee…
[Data] arrow-rs test: record, don't assert, the scanner's batch_size …
[data] DataSourceV2: don't disable pre_buffer in Parquet scanner opti…
[Data] Specify logical memory for `read_large_parquet` (ray-project#6…
[Core] Compute per component memory usage in MiB (ray-project#63932)
apacheGH-39808: [C++][Parquet] Simplify read cache and strengthen evi…