Repository navigation
Description
Historically, Dask has been execution-model agnostic when constructing graphs. This has had some notable advantages, since it means that dask task graphs/collections can be executed using any of a number of different schedulers. So the same graph can be computed using local schedulers, the distributed scheduler, and even third-party schedulers like Ray. It also enforces a certain amount of separation-of-concerns so that dask/dask and dask/distributed can be developed in a semi-independent fashion.
There is, however, some downside to this cluster-agnostic approach. Often there are specific tuning parameters and configuration options that significantly affect the performance of computations. Choosing good values for these parameters typically requires fairly advanced knowledge of Dask, its optimizations, and distributed systems in general. As developers, we would like to remove the onus from users to possess this information, but often cannot do that without knowledge of the cluster that they will be running it on.
One example of this that I ran into recently was with groupby/aggregations and the split_every parameter. It defaults to 8, but there are some easy-to-hit cases where that winds up being a very bad choice. And making a better choice requires knowing, at a minimum, the number of workers you will likely be using. This doesn't seem like an unreasonable ask for the task graph, but it's not easily available today.
Some tuning parameters which might benefit from having more context about the cluster:
chunks(array creation and rechunking)split_every(array reductions)merge_chunks(array reshaping)split_every,split_out(dataframe reductions)npartitions,broadcast(dataframe merges)divisions,npartitions,partition_size(dataframe creation and repartitioning)split_every(bag reductions)dataframe.parquet.metadata-task-size-remote(parquet metadata processing)
There are some caveats to the above assertion that dask task graphs are cluster-unaware:
- The default cluster implementation depends on whether there is an active
distributed.Client. This usually does the right thing, but can cause problems if the graph is constructed before the client starts. - p2p shuffling does some out-of-task-graph work on the workers.
These are both interesting antecedents for reasoning about the execution environment, but it's not clear to me how reproducible they are in other contexts. From my perspective, I'd like to have something like the following:
- A repeatable pattern for learning about a cluster during graph construction. Today, the default shuffle implementation goes through the dask config system, but I might want something a bit more formalized and thread-safe. It should also be able to be run on the scheduler: if we are delaying graph construction until an expression reaches the scheduler, we should be able to take advantage of more detailed information.
- Possibly have an abstract HLG/HLE for repartitioning and rechunking. In particular, knowing some things about the number of workers and how much memory they have would help to avoid having too much or too little work-per-worker.
Some questions I don't have good answers to:
- Even if we do have cluster information available during graph construction, can we write down good defaults for some of the tuning parameters? In some cases, maybe yes, in other cases, maybe no.
- Is it possible all of the above is wildly overthinking things? Could a half-dozen blocks like the following do everything I want?
try: import distributed info = distributed.get_default_client().scheduler_info() # Set some defaults based on the info. except ImportError, ValueError: # Set some default defaults.
- Is any of the above doable in the absence of HLG refactoring (cf discussion in [Discussion] HighLevelGraph Development Roadmap #9159 and linked issues)? If the answer is no, I still think this is a valuable thing to think about when designing and implementing their replacement.
Activity
rjzamora commentedon Sep 30, 2022
I think it makes a lot of sense to (optionally) allow the client/scheduler to use cluster information to choose how to build the graph. While working on #9216, I realized that the new HLG/Layer design could easily be used to label each individual task with a preferred worker. The only changes outside of HLG design would be:
Layer-materialization logic.With these two features in place, it would be relatively simple for appropriate worker preferences to be assigned as an HLG is materialized. For example, consider a simple HLG comprising 1+
Blockwiselayers, followed by agroupbyaggregation:If feature (1) was available in Dask, the aggregation layer could use information about the expected worker set to specify graph-materialization parameters, like
split_every. For example, if there are two workers in the detected cluster,split_everycould be chosen so that the aggregation could be perfectly balanced between the two workers:At graph-materialization time, a layer will be materialized within a method like
Layer.subgraph(keys: Set, color: str | dict | None = None). Within thesubgraphlogic, the cluster-aware aggregation layer could (optionally) assign a worker color (or perhaps even a specific worker address) to each task it materializes (prioritizing thecolorspecified in the function signature if it isn'tNone):Since each layer will also be responsible for specifying which keys it wants from dependency layers (only after it has been materialized by a
subgraphcall), the returned key-dependency information can be organized by dependency color. This way, the preferred worker dependencies can propagate through the entire graph as it is materialized:The final result is that (1) we are making better decisions about graph topology, and (2) are making it easier for the scheduler to properly co-locate distinct tasks on the same worker. If done properly, I suppose this design could even make successful HLG-level fusion less critical.