Repository navigation
Description
Problem
I was chatting with some RAPIDS devs today (@kkraus14 @quasiben @randerzander @jakirkham @madsbk @pentschev and others ) and they were generally concerned about the scheduling overhead of dataframe merges/set_index operations (anything that uses shuffle). There is an effort to improve scheduling performance generally, but there is also an option to try to rethink how we handle shuffling in dataframes, and maybe other similar operations in the future as well (like array rechunking in extreme situations).
The currrent "tasks" based shuffling method uses O(n log(n)) tasks and log(n) full-dataset communications. This is fine for ~100 partitions, but becomes challenging once you get to 1000 partition datasets. We also have a separate solution around partd, which does things in O(n) tasks, by buffering small shards of the data and using disk as a global communication store. Partd as written doesn't work in a distributed fashion, but we might think about how to do some similar approach in a distributed fashion.
DHT
In principle, building some sort of distributed hash table (DHT) like thing out of Dask parts isn't hard (actors, pubsub, etc, are all good examples of similar systems that took a couple of days to build). What is hard is making it resilient. For this we might look to a mixture solution between some peer-to-peer system, and a centralized SchedulerPlugin. Here is a rough design.
We run tasks on each partition of the to-be-shuffled dataframe that split that partition into pieces, and put into some local splitting service. The first task on a machine probably creates the service (we use a local thread-based-lock to coordinate between multiple tasks on the same machine). That service splits things apart, stores them in local buffers, and periodically sends batches them to peers.
How does it learn what peers it should send things to? Probably it has to check in with the scheduler, which will still act as centralized control here, but won't track every individual piece of data. Maybe these things check in with the scheduler, the scheduler alerts everyone else about what is going on, and the things push data around in a way similar to a distributed hash table (DHT). (there is lots of prior art here and algorithms to steal).
Once all of those tasks are done we run some barrier task, and then there are a bunch of other tasks which pull output partitions from the DHT. There is some excess communication here because we aren't thinking about locality for the Dask-DHT nodes, but for now let's just allow that as an allowable cost (my apologies).
So great, we get by with 2*n tasks, and probably two full communications. Not great, but it's probably better than what we have now for large shuffle computations.
What can go wrong
So what happens if a worker goes down during execution? We haven't replicated data, and the task that created that chunk of data is gone, so we've lost some things. We can still recreate and rerun that task though, we just need to tell the scheduler to do so. So in order to get resilience, we register a SchedulerPlugin that calls some custom code whenever a worker goes down. We know which workers processed which tasks, so we rerun those tasks. The other DHT nodes will get some duplicate data unfortunately, so they'll probably have to track which tasks they've seen, and know to discard any message that comes from the same task twice.
Nice things
So we get a nice combination here of resilience provided by the centralized scheduler, as well as low overhead provided by decentralized execution.
If we can create this as a more general purpose DHT solution then I suspect that people will find other uses for it other than just dataframe all-to-all shuffling.
Activity
mrocklin commentedon May 2, 2020
For dataframes in particular, we would make another shuffle method around this (alongside
"disk"and"tasks") that we would only use with the distributed scheduler. It would be opt-in at first but if it performs well and robustly then it might take over as default in the future.kkraus14 commentedon May 2, 2020
@mrocklin thanks for taking the time to write this up. It's much appreciated. I've made sure to circulate this to all of the relevant individuals within NVIDIA to make sure people read this and chime in their thoughts and concerns.
mrocklin commentedon May 2, 2020
madsbk commentedon May 2, 2020
@mrocklin, the
O(n log(n))tasks andlog(n)full-dataset communications is when using stages right? Without staging, it isO(n**2)tasks and1full-dataset communications right?Also, can we avoid the barrier somehow? One of the lessons we learned when implementing dataframe merges using
explicts-commswas that the implicit barrier killed the overall performance and increased the memory usage significantly even thought the merge itself was much faster (@rjzamora please correct me if I am wrong).Something we also have to keep in mind when exploring approaches that uses external communication libraries.
mrocklin commentedon May 2, 2020
Correct, up to about n==32 I think. After that I think we start staging. (I could have the numbers wrong here. So when we get to partition counts like 1000 we end up with task counts in the 10000's to 100,000, but not 1,000,000
The all-to-all nature means, I think, that computation after the merge is unlikely to start until 90% of the merge computation is done no matter what we do. However, we can certainly do data movement during that time. I don't think that I've seen a solution that allows for shuffling as part of a streaming workflow.
I could be wrong here though. It sounds like you have real-world experience that says otherwise.
madsbk commentedon May 2, 2020
Right, the merge itself is a loose barrier. In
explicts-commswe have to do a barrier initially before the merge can begin, which makes it a big problem.mrocklin commentedon May 2, 2020
Right, in the approach proposed above there isn't an actuall
barrier()call in order to start. We have tasks that look like the following:(sorry for being very informal above. I hope that that gets the point across)
kkraus14 commentedon May 2, 2020
Trading off communication complexity for task graph complexity is not a good architecture decision from my perspective. We (NVIDIA) have been pushing on things hard as we have very high performance hardware, but many people don't have this hardware. I.E. on a cloud system where networking isn't nearly as high performance as these machines we're using for benchmarking, the communication overhead is almost always significantly higher than the task graph overhead, even when we get to thousands of input partitions.
If there wasn't the task graph performance challenges we have today, we wouldn't be having this conversation as to how to shuffle data more efficiently. We'd likely be bottlenecked by our communication layer / interconnect bandwidth, which is a good bottleneck to have.
mrocklin commentedon May 2, 2020
mrocklin commentedon May 30, 2020
cc @fjetter in case this interests you
fjetter commentedon Jun 2, 2020
Indeed, we (Blue Yonder) are currently bottlenecked by available memory and available network bandwidth but rarely by scheduler overhead. For this we created #6259.
We're usually only hit by scheduler overhead if the input data is partitioned to granularly which is when we repartition (and optimize/fuse) before we start shuffling.
@crepererum made a good point there about out-of-band communication of the payload data which may tie in quite well with this approach of using a DHT (if the complexity this introduces is something we'd consider feasible)
However, pragmatically speaking, I don't think we're actually trading in communication complexity but for most scenarios keep it as is or improve it. Currently we have one full communication per stage. The number of stages we need for the reshuffling scales with
log(N)but just to make it very clear, the number of stages is calculated usingceil(log(N) / log(max_branch)). To illustrate this I'll keep the constant at the default value (max_branch=32) which is probably true for most users and spell out the critical points:So only for relatively small dataframes with 32 partitions or less we do get away with only one data submission and this case is handled with it's dedicated code path by now (see here) which is something we could still allow in the future, if need be.
For everything else, a constant two is either as bad as before or a significant improvement.
madsbk commentedon May 12, 2021
For reference, the Dask-CUDA's implementation of shuffle has been re-implemented and doesn't use more memory than the regular shuffle anymore.
It is basically a shuffle service that performs the all-to-all communication in a single stage without the involvement of the scheduler. It works with both CUDA and regular Dataframes such as Pandas and cuDF.
In order to enable it, simply
import dask_cudaand setDASK_EXPLICIT_COMMS=Trueor set the"explicit-comms"key in the Dask configuration and Dask will automatically use the shuffle service.mrocklin commentedon May 12, 2021