Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set restrictions during barrier on scheduler #8732

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion distributed/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7867,7 +7867,9 @@ def get_metadata(self, keys: list[Key], default: Any = no_default) -> Any:
else:
raise

def set_restrictions(self, worker: dict[Key, Collection[str] | str | None]) -> None:
def set_restrictions(
self, worker: Mapping[Key, Collection[str] | str | None]
) -> None:
for key, restrictions in worker.items():
ts = self.tasks[key]
if isinstance(restrictions, str):
Expand Down
55 changes: 52 additions & 3 deletions distributed/shuffle/_scheduler_plugin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import asyncio
import contextlib
import itertools
import logging
Expand Down Expand Up @@ -95,11 +96,59 @@
self.scheduler,
stimulus_id=f"p2p-barrier-inconsistent-{time()}",
)

msg = {"op": "shuffle_inputs_done", "shuffle_id": id, "run_id": run_id}
await self.scheduler.broadcast(
msg=msg,
workers=list(shuffle.participating_workers),
broadcast_task = asyncio.create_task(
self.scheduler.broadcast(
msg=msg,
workers=list(shuffle.participating_workers),
)
)
barrier_task = self.scheduler.tasks[barrier_key(id)]
barrier_deps: set[TaskState] = barrier_task.dependents
from dask.optimization import SubgraphCallable

from distributed.shuffle._rechunk import rechunk_unpack
from distributed.shuffle._shuffle import shuffle_unpack

def _extract_part_id(run_spec: Any) -> Any:
if not isinstance(run_spec, tuple):
return False
# FIXME: This is extremely crude. The shuffle run / spec should
# likely expose a method that is performing this check and returns
# the ID if possible.
if run_spec[0] is rechunk_unpack or run_spec[0] is shuffle_unpack:
# Happy path, we're just having the unfused dependencies
if len(run_spec) == 4:
return run_spec[2]
return run_spec[1][1]

Check warning on line 124 in distributed/shuffle/_scheduler_plugin.py

View check run for this annotation

Codecov / codecov/patch

distributed/shuffle/_scheduler_plugin.py#L122-L124

Added lines #L122 - L124 were not covered by tests
elif isinstance(run_spec, SubgraphCallable):
for tspec in run_spec.dsk.values():
if partial_index := _extract_part_id(tspec):
return partial_index
return False

Check warning on line 129 in distributed/shuffle/_scheduler_plugin.py

View check run for this annotation

Codecov / codecov/patch

distributed/shuffle/_scheduler_plugin.py#L126-L129

Added lines #L126 - L129 were not covered by tests
else:
if any(ret := _extract_part_id(arg) for arg in run_spec):
return ret

Check warning on line 132 in distributed/shuffle/_scheduler_plugin.py

View check run for this annotation

Codecov / codecov/patch

distributed/shuffle/_scheduler_plugin.py#L132

Added line #L132 was not covered by tests
return False

restrictions = {}
for dep in barrier_deps:
# Ensure the broadcast can proceed as needed without blocking
# the event loop here
if not broadcast_task.done():
await asyncio.sleep(0)
if partial_index := _extract_part_id(dep.run_spec):
worker = shuffle.run_spec.worker_for[partial_index]
restrictions[dep.key] = {worker}

Check warning on line 143 in distributed/shuffle/_scheduler_plugin.py

View check run for this annotation

Codecov / codecov/patch

distributed/shuffle/_scheduler_plugin.py#L142-L143

Added lines #L142 - L143 were not covered by tests
else:
raise RuntimeError("Could not parse barrier dependents")

await broadcast_task

Check warning on line 147 in distributed/shuffle/_scheduler_plugin.py

View check run for this annotation

Codecov / codecov/patch

distributed/shuffle/_scheduler_plugin.py#L147

Added line #L147 was not covered by tests
# Set the restrictions after the barrier to not mess with concurrency
# control (the state before the barrier set restrictions was well tested
# and it is unclear if changing restrictions earlier would impact this)
self.scheduler.set_restrictions(restrictions)

Check warning on line 151 in distributed/shuffle/_scheduler_plugin.py

View check run for this annotation

Codecov / codecov/patch

distributed/shuffle/_scheduler_plugin.py#L151

Added line #L151 was not covered by tests

def restrict_task(
self, id: ShuffleId, run_id: int, key: Key, worker: str
Expand Down
Loading