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
Suboptimal graph structure when read-writing a parquet #8445
to-parquet ops don't appear to "fuse" together with the rest of the linear chain. Since fusing chains is the current workaround for dask/distributed#3974, this results in larger-than-necessary memory usage due to workers picking up work from other partitions earlier than they should.
What you expected to happen:
to-parquet ops should be merged into the linear chain like the other ops do. See code below for more explanation.
Ideally the to-parquet op would be part of the fused chain. That way workers have no chance to prematurely switch to working on a different chain. I'm not aware of any reason that the to-parquet op should remain unfused.
Looks to me like this would be pretty easy to convert to a map_partitions once my changes in #8310 are merged (letting you pass BlockwiseDeps as arguments to map_partitions).
More broadly, I'm starting to become concerned that #7620 was premature; going to open a separate issue about that (EDIT: it's #8447).
If you're not using set_index or groupby.apply, I think setting it is reasonable.
The main con is just that you'll be converting all high-level graphs to low-level graphs, which are slower to transfer to the scheduler. Additionally, it appears that this may adversely affect set_index with the distributed scheduler, see #8451 (comment). If you're using set_index, this could be a significant problem; @rjzamora might be able to say more.
I guess all task graphs will have fusions that reduce opportunities for workers to share work?
Not particularly; the fusions that it makes should be pretty reasonable.
If you're using set_index, this could be a significant problem; @rjzamora might be able to say more.
Right - @madsbk discovered a while back (see #6051) that shuffling (set_index) performance can be significantly improved by modifying the priority of certain tasks. This optimization was eventually implemented in the form of HLG annotations. This seemed "nice" at the time, because we were no longer adding a shuffle-specific hack in dask-core code. However, the optimization completely depends on the ShuffleLayer not being materialized on the client.
The current "priority" solution is clearly a problem if your shuffle-based workflow happens to require low-level task fusion, for non-Blockwise layers. This is because Blockwise is the only Layer type where fusion at the HLG level is implemented. At the moment, any other form of fusion requires graph materialization, and it is hard to imagine a simple way to enable Blockwise fusion with other Layer types.
Note that I should be able to implement a to_parquet HLG layer soon. I suspect that breaking it into a Blockwise + Reduction (new), we should be able to utilize Blockwise fusion for the particular case motivating this issue.
@rjzamora what's Reduction? Naively reading the graph, I think it could be done easily with just Blockwise + BlockwiseDepDict to pass in the filenames to tasks (see #8310 (comment)). But Reduction sounds cool :)
@rjzamora what's Reduction? Naively reading the graph, I think it could be done easily with just Blockwise + BlockwiseDepDict to pass in the filenames to tasks (see #8310 (comment)). But Reduction sounds cool :)
I think it makes sense to add a general Reduction Layer (or maybe TreeReduction) to reduce a Blockwise Layer down to a single output task. This would be used in to_parquet to collect the parquet metadata from every write task, and produce a single _metadata file.
Activity
gjoseph92 commentedon Dec 2, 2021
@davidhao3300 thanks for raising this. You're totally right. As a workaround right now, I'd recommend:
@rjzamora I guess I'd thought with #7620 that the O side of I/O was Blockwise'd as well, but reading through
to_parquet, it's not:dask/dask/dataframe/io/parquet/core.py
Lines 738 to 770 in a5aecac
Looks to me like this would be pretty easy to convert to a
map_partitionsonce my changes in #8310 are merged (letting you passBlockwiseDeps as arguments tomap_partitions).More broadly, I'm starting to become concerned that #7620 was premature; going to open a separate issue about that (EDIT: it's #8447).
cc @rjzamora, @ian-r-rose.
davidhao3300 commentedon Dec 3, 2021
Thank you for the fast response, I confirm that setting optimization.fuse.active to True fuses to-parquet into the chain.
Are there any cons to enabling this globally? I guess all task graphs will have fusions that reduce opportunities for workers to share work?
gjoseph92 commentedon Dec 3, 2021
Great to confirm, thanks.
If you're not using
set_indexorgroupby.apply, I think setting it is reasonable.The main con is just that you'll be converting all high-level graphs to low-level graphs, which are slower to transfer to the scheduler. Additionally, it appears that this may adversely affect
set_indexwith the distributed scheduler, see #8451 (comment). If you're usingset_index, this could be a significant problem; @rjzamora might be able to say more.Not particularly; the fusions that it makes should be pretty reasonable.
rjzamora commentedon Dec 3, 2021
Right - @madsbk discovered a while back (see #6051) that shuffling (set_index) performance can be significantly improved by modifying the priority of certain tasks. This optimization was eventually implemented in the form of HLG annotations. This seemed "nice" at the time, because we were no longer adding a shuffle-specific hack in dask-core code. However, the optimization completely depends on the ShuffleLayer not being materialized on the client.
The current "priority" solution is clearly a problem if your shuffle-based workflow happens to require low-level task fusion, for non-Blockwise layers. This is because Blockwise is the only Layer type where fusion at the HLG level is implemented. At the moment, any other form of fusion requires graph materialization, and it is hard to imagine a simple way to enable Blockwise fusion with other Layer types.
rjzamora commentedon Dec 3, 2021
Note that I should be able to implement a to_parquet HLG layer soon. I suspect that breaking it into a
Blockwise+Reduction(new), we should be able to utilize Blockwise fusion for the particular case motivating this issue.gjoseph92 commentedon Dec 3, 2021
@rjzamora what's
Reduction? Naively reading the graph, I think it could be done easily with justBlockwise+BlockwiseDepDictto pass in the filenames to tasks (see #8310 (comment)). ButReductionsounds cool :)rjzamora commentedon Dec 3, 2021
I think it makes sense to add a general
ReductionLayer (or maybeTreeReduction) to reduce a Blockwise Layer down to a single output task. This would be used into_parquetto collect the parquet metadata from every write task, and produce a single_metadatafile.gjoseph92 commentedon Dec 3, 2021
TreeReductionwould be a great one! That's probably the most common pattern that's not high-level right now.rjzamora commentedon Dec 8, 2021
I took a first stab at this in #8468 - I'm hoping we can use the same reduction layer for the metadata stage in to_parquet
perf(builder): enable to_parquet fusion + disable _metadata aggregation
perf(builder): enable to_parquet fusion + disable _metadata aggregation
perf(builder): enable to_parquet fusion + disable _metadata aggregation