Repository navigation
Conversation
|
cc @jakirkham |
|
@fjetter thank you very much for integrating and polishing my rough idea. It's really good to see it swimming upstream and also how small the actual code change it 👍 Please note that a similar optimization could be done for the tasks-based Also as a side note on shuffling: This can of course be improved / tuned further. Shuffling (both for the DF and for the Bag) are basically a (distributed) shuffle with two components
The PR implements (1) and (2) for DFs. (3) (or any further options) are out of scope here but interested parties might try it out. |
|
FWIW @fjetter Pandas serialization hasn't been particularly efficient historically ( dask/distributed#614 ). PR ( dask/distributed#3784 ) changed that in 2.17.0 as it now handles out-of-band serialization when pickling (if supported), which works on Pandas objects. I haven't looked into compression in that case, but suspect it may be happening as well. Maybe worth updating to the latest version and exploring workloads if you haven't already. Would be good to have an update on issue ( dask/distributed#614 ) with anything you find. 🙂 |
|
@jakirkham Yes, I am aware of your work and am very excited to test this. Unfortunately, we're still stuck on py3.6 for a while which makes it hard to test this at the moment since
Yes, distributed automatically compresses the frames if it yields favourable compression rates, see https://github.com/dask/distributed/blob/1fe50c24792d74643772268c188decd3c1ab76ee/distributed/protocol/compression.py#L160 This is what I effectively use here as well. Irrelevant of the performance of the serialization, I believe this PR makes a big difference, assuming the shuffled dataframe has a significant amount of payload data since this PR proposes to (de-)serialize and compress this payload data only once instead of doing it on every submission. Another note to the argument @crepererum mad above about the K, V split: I currently store the V in the dataframe itself which might not be the most performant solution but it is rather elegant since we don not need to touch much. That could be obviously refined at a later stage since even point 1 and 2 can probably be expressed more efficiently with a more specialized implementation. Yet another benefit of this approach I want to mention since it falls a bit through the cracks if not looked into closely. The Example In [2]: import pandas as pd
...: import dask.dataframe as dd
...: from dask.dataframe.shuffle import pack_payload
...:
...: df = pd.DataFrame({"A": [1, 1] * 2 + [2, 2] * 2 + [3, 3] * 2, "B": range(12)})
...: ddf = dd.from_pandas(df, npartitions=2)
In [3]: ddf.partitions[0].compute()
Out[3]:
A B
0 1 0
1 1 1
2 1 2
3 1 3
4 2 4
5 2 5
In [4]: pack_payload(ddf, "A").partitions[0].compute()
Out[4]:
A __dask_payload_bytes
0 1 b'\x03\x00\x00\x00\x00\x00\x00\x00)\x00\x00\x0...
1 2 b'\x03\x00\x00\x00\x00\x00\x00\x00)\x00\x00\x0... |
|
No worries. We are looking at the long tail as well ( dask/distributed#2495 ) 🙂 |
5501788 to
b9742b9
Compare
|
Should add there are similarities to this and @madsbk's PR ( dask/distributed#3624 ) to transmit serialized data. @mrocklin pointed out in that PR that we might benefit from having a |
|
The auto compression While I was not, yet, able to perform proper benchmarks, what I could observer already is that this general approach presented here will not work since the |
|
Closing this since obviously stale and I currently don't have time to update. The idea is still valid if somebody wants to pick this up |
For jobs which process a dataframes with a significant amount of payload columns, shuffle operations can be incredibly memory consuming. Especially due to the multi stage algorithm, multiple copies of the data are in fact intended. Due to the multi stage shuffle we also need to (de)serialize these columns many times. However, for the shuffle itself these columns are effectively dead weight.
This change proposes to serialize (and more importantly compress) the payload columns during the shuffle operation which allows for a significant reduction in memory usage. Not only is the memory usage reduced (less spill to disk), but this also reduces the amount of IO (disk or network depending on the shuffle mode) and the overhead of (de)serializing "garbage". We've seen significant speed ups in runtime when testing this; even with reduced cluster sizes (I don't have proper benchmarks prepared yet but can follow up with some, if desired).
This is not ready to merge since it still fails for multiple environments (especially older pandas versions; The py3.8 job is successful with the exception of a failed doctest) and I will address these build failures if we are willing to accept this contribution.
To compress and serialize the payload, I'm using the
distributed.protocolassuming that it is stable, fast, handles compression on the fly and allows for customization if desired (e.g. to use different serializers, arrow/parquet come to my mind but I haven't tested this lately). If there are other options for this format, I'm open for suggestions since atm this would obviously only work if distributed is installed.The code itself is a bit messier than I would like to. I needed to use the
DataFrameGroupy.applywhich has the obvious downsides of being slow. I would argue, however, that this slowdown is acceptable, weighing in the performance gains I expect from this change.On top of this, I observe funny/unstable behaviour of this function (It improves with more recent pandas versions but I consider it still unstable).
If somebody has a suggestion how to express this logic without using apply, I'd appreciate the input.
Thanks @crepererum for this cool idea
For completeness and transparency, we're building this currently into kartothek where we need to deal with fewer edge cases (see JDASoftwareGroup/kartothek#286 ) but we would obviously prefer this to be part of dask itself.