Skip to content

[Discussion] Cluster-aware graph logic #9522

Open

Description

@ian-r-rose

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:

  1. 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.
  2. 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:

  1. 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.
  2. 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:

  1. 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.
  2. 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.
  3. 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

  1. added
    discussion
    on Sep 28, 2022
  2. rjzamora commented on Sep 30, 2022

    @rjzamora
    Member

    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:

    1. We would need to allow the client to (optionally) check if there is an active distributed cluster, and to use that information to encode worker preferences in the Layer-materialization logic.
    2. We would need a simple mechanism to annotate individual tasks with preferred workers, and we would need to add the scheduling logic to use the worker preference when assigning tasks.

    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+ Blockwise layers, followed by a groupby aggregation:

    Screen Shot 2022-09-30 at 9 44 14 AM

    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_every could be chosen so that the aggregation could be perfectly balanced between the two workers:

    Screen Shot 2022-09-30 at 9 44 46 AM

    At graph-materialization time, a layer will be materialized within a method like Layer.subgraph(keys: Set, color: str | dict | None = None). Within the subgraph logic, the cluster-aware aggregation layer could (optionally) assign a worker color (or perhaps even a specific worker address) to each task it materializes (prioritizing the color specified in the function signature if it isn't None):

    Screen Shot 2022-09-30 at 9 45 11 AM

    Since each layer will also be responsible for specifying which keys it wants from dependency layers (only after it has been materialized by a subgraph call), 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:

    Screen Shot 2022-09-30 at 9 45 35 AM

    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.

  3. added
    needs attention
    on Oct 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    corediscussionneeds attention

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions