Repository navigation
Description
Describe the bug, including details regarding any error messages, version, and platform.
I'm debugging slow performance in Dask DataFrame and have tracked things down, I think, to slow parquet deserialization in PyArrow. Based on what I know of Arrow I expect to get GB/s and I'm getting more in the range of 100-200 MB/s. What's more is that this seems to depend strongly on the environment (Linux / OSX) I'm using. I could use help tracking this down.
Experiment
I've isolated the performance difference down to the following simple experiment (notebook here):
# Create dataset
import pyarrow as pa
import pyarrow.parquet as pq
import numpy as np
import pandas as pd
import time
import io
x = np.random.randint(0, 100000, size=(1000000, 100))
df = pd.DataFrame(x)
t = pa.Table.from_pandas(df)
# Write to local parquet file
pq.write_table(t, "foo.parquet")
# Time Disk speeds
start = time.time()
with open("foo.parquet", mode="rb") as f:
bytes = f.read()
nbytes = len(bytes)
stop = time.time()
print("Disk Bandwidth:", int(nbytes / (stop - start) / 2**20), "MiB/s")
# Time Arrow Parquet Speeds
start = time.time()
_ = pq.read_table("foo.parquet")
stop = time.time()
print("PyArrow Read Bandwidth:", int(nbytes / (stop - start) / 2**20), "MiB/s")
# Time In-Memory Read Speeds
start = time.time()
pq.read_table(io.BytesIO(bytes))
stop = time.time()
print("PyArrow In-Memory Bandwidth:", int(nbytes / (stop - start) / 2**20), "MiB/s")Results
I've tried this on a variety of cloud machines (intel/arm, VMs/metal, 8-core/64-core, AWS/GCP) and they all get fast disk speeds (probably cached), but only about 150MB/s parquet deserialization speeds. I've tried this on two laptops, one a MBP and one a ThinkPad running Ubuntu and I get ...
- MacBookPro: 1GiB/s PyArrow deserialization performance (what I expect)
- Ubuntu/Thinkpad: 150MB/s PyArrow deserialization
In all cases I've installed latest release, PyArrow 13 from conda-forge
Summary
I'm confused by this. I've seen Arrow go way faster than this. I've tried to isolate the problem as much as possible to identify something in my environment that is the cause, but I can't. Everything seems to point to the conclusion that "PyArrow Parquet is just slow on Linux" which doesn't make any sense to me.
I'd welcome any help. Thank you all for your work historically.
Component(s)
Parquet, Python
Activity
mrocklin commentedon Oct 22, 2023
Here is a rendered notebook from my Ubuntu Thinkpad to make the numbers more concrete: https://gist.github.com/mrocklin/526120bb5231cc5d9d4e3ca87fc09c68
This run was actually a bit faster than I usually see. On Cloud VMs (even very nice ones) it's hard to get above 150MB/s on real data.
jorisvandenbossche commentedon Oct 23, 2023
For reference, I ran your snippet above and repeated the timing part multiple times on a Linux (Ubuntu 20.04) Dell XPS 13 9380 (more than 4 years old, 8th gen Intel Core i7, 4 cores / 8 threads), and I get almost 2 GB/s for disk speed and around 1 GB/s for reading (just under for from file, just above for in-memory).
(so at least it's not a simple mac vs linux issue)
One environment characteristic that will significantly influence those numbers is the parallelization (the Parquet reading will by default use all the available cores). So it might be worth to run those timings with and without threads enabled, to check if also single-threaded performance is bad and ensure it's not related to bad scaling on that front.
On my laptop, I get the expected 3-4x speedup with threads enabled (the numbers above), as I get around 250-300 MB/s using
use_threads=False.fjetter commentedon Oct 23, 2023
I ran a couple of pyspy benchmarks on pure
pq.read_tabledownloading from S3. I ran two tests, one with column projection and one with bulk reading. Both show basically the same profile but with different weighting of components.This profile shows the case where I'm reading a file and are selecting about half it's columns (a mix between different dtypes)
Note how the read_table request is split into three parts
arrow/python/pyarrow/parquet/core.py
Line 2481 in ac2d207
FileSystemDatasetobject. In native profiles, this points toarrow::dataset::Fragment::ReadPhysicalSchemaso I assume this is fetching the footer. This is probably unavoidable but at least this request could be used to pre-fetch some payload data but I'm not sure if this is actually done (I guess not since, thebuffer_sizekwarg is zero by default). In this specific example, this is about 10% of the readSo, that's 30% where we're doing nothing/not a lot? I'm not sure at which point the pre_buffering can kick on or how this works. This stuff does not show up in my profile since it's the arrow native threadpool.
At least this initial HEAD request appears to be bad, particularly if we're fetching just a couple of columns from otherwise already small-ish files. The file I was looking at is one of the TPCH lineitem files which in our dataset version is 22.4MiB large.
Edit: This all ran on a Coiled VM and I was basically running the read request in a for loop. No multi threading on my side, just the pyarrow native stuff.
mapleFU commentedon Oct 23, 2023
About (1) some optimization will be included later, see:
Seems we can enable larger prefetch-depth to arrow fetching multiple files concurrently.
fjetter commentedon Oct 23, 2023
Sorry, I just realize that my comment is also slightly off topic. The OP discusses pure deserialization without S3 in between
fjetter commentedon Oct 23, 2023
FWIW I slightly modified the above script to run each operation N times since I noticed quite some variance on my machine (M1 2020 MacBook)
Details
and I get M1 (using
pyarrow-13.0.0-py310h382c99a_11_cpufrom conda-forgewhile on the cloud using a
m6i.xlarge(a coiled based, dask bootstrapped VM, see below) (4vCPUs) it is just (usingpyarrow-13.0.0-py310hf9e7431_11_cpufrom conda-forge)fjetter commentedon Oct 23, 2023
@jorisvandenbossche have you used the same conda forge build for your measurements or did you build it yourself? It would be nice to rule out any build differences
fjetter commentedon Oct 23, 2023
Ok, fun experiment. I wrapped the above script in a function
run_benchmarkand ran this on my machine...Looks like the simple fact that we're running this in the dask environment is slowing us down quite a bit. This also biases most/all Coiled-based cloud benchmarks
Code
fjetter commentedon Oct 23, 2023
Is pyarrow using either one of
OMP_NUM_THREADS,MKL_NUM_THREADS,OPENBLAS_NUM_THREADSto infer how large the threadpool is allowed to be?Edit: Looking at the code base, I see references and documentation that suggests that
OMP_NUM_THREADScontrols the size of the internal threadpoolDask is setting those to one and when I remove that, I'm back to the non-dask speed.
Do not set parallelism controlling env vars
mrocklin commentedon Oct 23, 2023
To be clear, my experiment in this issue was run without Dask and without Coiled. I wanted to isolate things.
mrocklin commentedon Oct 23, 2023
Turning threads off I get around 170MB/s on my linux machine, 600 MB/s on my OS-X machine.
I'm curious, for deserializing integers is this expected performance? I would have thought that for this kind of data (just ints) we'd be closer to GB/s speeds. I'm curious, what is the slow part here? Is there some intense compression or something?
I'm also quite curious about this.
65 remaining items
mrocklin commentedon Nov 24, 2023
I'm guessing that converting these to pandas dataframes would result in them being categorical dtype series. Is that correct?
What would folks recommend as default compression? LZ4?
If so, @milesgranger maybe it's easy to change the data generation scripts in some way with this change? I'd be fine changing things in the benchmark if we think it's a good global recommendation. (For context, I don't like changing things in benchmarks to make performance better because it results in over-tuning and non-realistic results, but if the change is good general practice as recommended by other people then it feels better I think).
mrocklin commentedon Nov 24, 2023
@pitrou if it's easy for you, I'm curious how well this parallelizes. If you do it on local four cores do you get ~800MB/s? (assuming that your filesystem can go that fast, which seems likely)
jorisvandenbossche commentedon Nov 24, 2023
And what machine did you get that number? (because above (#38389 (comment)) you reported much higher single-threaded numbers)
pitrou commentedon Nov 24, 2023
@jorisvandenbossche It wasn't the same file.
[-]Parquet deserialization speeds slower on Linux[/-][+][Python][Parquet] Parquet deserialization speeds slower on Linux[/+]pitrou commentedon Dec 13, 2023
Sorry for the delay. Basically, yes, at least with the Snappy-compressed file:
Also, do note that the speed I'm reporting here (225 MB/s on one core) is relative to file size. Relative to in-memory Table size, this is more around 525 MB/s on one core.
pitrou commentedon Dec 13, 2023
Some low-level stats using
perf stat -d -d -d:At more than 2 instructions per cycle, it seems that we are not suffering much from cache or branch prediction misses.
mrocklin commentedon Dec 13, 2023
pitrou commentedon Dec 13, 2023
I have also tried to regenerate the given file using different compressions and then compared reading performance:
So we get:
Note that only the speeds relative to in-memory Table size are comparable, since the file sizes vary. Snappy is the slowest of all options, while producing a file size not much better than lz4 and strictly worse than zstd.
pitrou commentedon Dec 13, 2023
That said, ~1 GB/s for uncompressed PLAIN-encoded fixed-width data is still very mediocre. I think this has to with the fact that
pq.read_tableconcatenates the row groups together instead of building one more chunk per row group:If I deliberately read row groups separately for these PLAIN-encoded columns, I get almost twice the speed:
GH-40142: [Python] Allow FileInfo instances to be passed to dataset i…
alippai commentedon Jul 2, 2024
@pitrou the different compression benchmarks were running using hot file cache, right? I'd be surprised if uncompressed would be faster than lz4 without the linux file cache (even if you have the latest NVMe) as reading from disk should be slower than decompression.
Also LZ4 should be (roughly) 5GB/s, Snappy 2Gb/s and ZSTD should be 1GB/s on a i7-9700k (2018) on a single thread. I know it hurts data locality and copying around data will never help, but the results keep me thinking what's missing.
pitrou commentedon Jul 2, 2024
Yes, running on hot file cache. Benchmarking with cold cache is tedious and makes numbers much more difficult to compare (IO speeds vary probably much more than single-thread CPU speeds).
Agreed, though do note that it's on a high-clocked CPU (server CPUs tend to have much lower clock speeds). And in practice it will depend on the corpus as well.