You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@arrow.apache.org by "kubat-square-sense (via GitHub)" <gi...@apache.org> on 2025/01/13 09:53:27 UTC
[I] pyarrow 18 high memory consumption [arrow]
kubat-square-sense opened a new issue, #45236:
URL: https://github.com/apache/arrow/issues/45236
### Describe the bug, including details regarding any error messages, version, and platform.
We noticed high memory consumption while reading parquet files with pyarrow 18.1.
Loading a 600Kb parquet file into a 22Mb consumes over 1 Gb of memory. On 3 different machines (wsl, linux, macos), profiling with memray showed a peak memory of 1 Gb, 1.1 Gb and 1.8 Gb.
Running the same code with pyarrow 17 consumes less than 200 Mb.
Its quite simple to reproduce. I've attached a dummy parquet which consume slightly less but still over 1 GB.
```python
import pyarrow.parquet as pq
data = pq.read_table('test.parquet')
print(data.nbytes / 1024**2)
```
[test.zip](https://github.com/user-attachments/files/18395000/test.zip)
### Component(s)
Python
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@arrow.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] pyarrow 18 high memory consumption [arrow]
Posted by "raulcd (via GitHub)" <gi...@apache.org>.
raulcd commented on issue #45236:
URL: https://github.com/apache/arrow/issues/45236#issuecomment-2587099634
Thanks for opening the issue.
Could you explain what do you mean by the following?
> Loading a 600Kb parquet file into a 22Mb
Did you found out anything with memray on where the memory was being used or did you just checked the peak memory consumption? It would be really helpful if you could help investigate a little further on where the issue is coming from.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Python][[Parquet][C++] pyarrow 18 high memory consumption [arrow]
Posted by "kubat-square-sense (via GitHub)" <gi...@apache.org>.
kubat-square-sense commented on issue #45236:
URL: https://github.com/apache/arrow/issues/45236#issuecomment-2589990638
Maybe you had a different pyarrow build?
I have the same result in a Dockerfile
```Dockerfile
FROM python:3.12
RUN pip install pyarrow==18.1.0 memray
COPY test.parquet test.parquet
RUN echo "import pyarrow.parquet as pq\ndata = pq.read_table('test.parquet')\nprint(data.nbytes / 1024**2)" > /test.py
RUN memray run --native -o report.bin test.py
CMD memray stats report.bin
```
`docker build --tag test_image .`
`docker run test_image`
Running the above (current pyarrow distro 18.1.0) yields:
📏 Total allocations:
75319
📦 Total memory allocated:
1.476GB
📊 Histogram of allocation size:
min: 1.000B
--------------------------------------------
< 6.000B : 4688 ▇▇▇▇▇
< 36.000B : 22577 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇
< 222.000B : 28911 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇
< 1.319KB : 16851 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇
< 7.999KB : 1397 ▇▇
< 48.503KB : 831 ▇
< 294.066KB: 34 ▇
< 1.741MB : 7 ▇
< 10.556MB : 0
<=64.000MB : 23 ▇
--------------------------------------------
max: 64.000MB
📂 Allocator type distribution:
MALLOC: 71282
CALLOC: 3149
REALLOC: 838
MMAP: 50
🥇 Top 5 largest allocating locations (by size):
- <stack trace unavailable> -> 1.378GB
- _call_with_frames_removed:<frozen importlib._bootstrap>:488 -> 84.912MB
- dedent:/usr/local/lib/python3.12/textwrap.py:436 -> 4.572MB
- sub:/usr/local/lib/python3.12/re/__init__.py:186 -> 3.808MB
- dedent:/usr/local/lib/python3.12/textwrap.py:435 -> 1.117MB
🥇 Top 5 largest allocating locations (by number of allocations):
- <stack trace unavailable> -> 29539
- _call_with_frames_removed:<frozen importlib._bootstrap>:488 -> 17261
- <module>:test.py:3 -> 5130
- sub:/usr/local/lib/python3.12/re/__init__.py:186 -> 4586
- dedent:/usr/local/lib/python3.12/textwrap.py:436 -> 4382
Changing to pyarrow==17.0.0
📦 Total memory allocated:
219.388MB
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Python][[Parquet][C++] pyarrow 18 high memory consumption [arrow]
Posted by "kubat-square-sense (via GitHub)" <gi...@apache.org>.
kubat-square-sense closed issue #45236: [Python][[Parquet][C++] pyarrow 18 high memory consumption
URL: https://github.com/apache/arrow/issues/45236
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Python][[Parquet][C++] pyarrow 18 high memory consumption [arrow]
Posted by "kubat-square-sense (via GitHub)" <gi...@apache.org>.
kubat-square-sense commented on issue #45236:
URL: https://github.com/apache/arrow/issues/45236#issuecomment-2587133808
I meant the size of the parquet file is around 600 Kb, and checking the loaded pyarrow table's size (data.nbytes) gives 22Mb. Meaning the table is actually quite small.
Here's the memray flamegraph for the above test.parquet file, Most of the allocations appear to come from native code. I don't have the symbols so its hard to read. [
[memray-flamegraph-perf_pyarrow.py.11595.zip](https://github.com/user-attachments/files/18397443/memray-flamegraph-perf_pyarrow.py.11595.zip)
](url)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Python][[Parquet][C++] pyarrow 18 high memory consumption [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on issue #45236:
URL: https://github.com/apache/arrow/issues/45236#issuecomment-2589494821
Your "dummy parquet file" doesn't reproduce the issue for me. I see a peak consumption of around 226 MB, and that's with Arrow compiled in debug mode.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Python][[Parquet][C++] pyarrow 18 high memory consumption [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on issue #45236:
URL: https://github.com/apache/arrow/issues/45236#issuecomment-2634370103
Ok, so it seems to be because you are using memray to account for memory.
With PyArrow 19.0, by default memray tells me 1.8 GB have been allocated, however `ps` only shows 169 MB RSS. The explanation is that memray is not able to instrument the memory pool Arrow uses by default: https://github.com/bloomberg/memray/issues/577
To get reliable memray results with Arrow, you have to switch to the system memory pool, for example by setting the environment variable `ARROW_DEFAULT_MEMORY_POOL=system`. Then memray shows 178 MB of allocated memory for the same example.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org