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

Revert "Fix co-assignment for binary operations" #6985

Merged
merged 1 commit into from
Sep 2, 2022
Merged
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
36 changes: 21 additions & 15 deletions distributed/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,14 @@ class TaskGroup:
#: The result types of this TaskGroup
types: set[str]

#: The worker most recently assigned a task from this group, or None when the group
#: is not identified to be root-like by `SchedulerState.decide_worker`.
last_worker: WorkerState | None

#: If `last_worker` is not None, the number of times that worker should be assigned
#: subsequent tasks until a new worker is chosen.
last_worker_tasks_left: int

prefix: TaskPrefix | None
start: float
stop: float
Expand All @@ -865,6 +873,8 @@ def __init__(self, name: str):
self.start = 0.0
self.stop = 0.0
self.all_durations = defaultdict(float)
self.last_worker = None
self.last_worker_tasks_left = 0

def add_duration(self, action: str, start: float, stop: float) -> None:
duration = stop - start
Expand Down Expand Up @@ -1302,8 +1312,6 @@ class SchedulerState:
"extensions",
"host_info",
"idle",
"last_root_worker",
"last_root_worker_tasks_left",
"n_tasks",
"queued",
"resources",
Expand Down Expand Up @@ -1375,8 +1383,6 @@ def __init__(
self.total_nthreads = 0
self.total_occupancy = 0.0
self.unknown_durations: dict[str, set[TaskState]] = {}
self.last_root_worker: WorkerState | None = None
self.last_root_worker_tasks_left: int = 0
self.queued = queued
self.unrunnable = unrunnable
self.validate = validate
Expand Down Expand Up @@ -1824,24 +1830,24 @@ def decide_worker_rootish_queuing_disabled(
if not pool:
return None

lws = self.last_root_worker
tg = ts.group
lws = tg.last_worker
if not (
lws
and self.last_root_worker_tasks_left
and self.workers.get(lws.address) is lws
lws and tg.last_worker_tasks_left and self.workers.get(lws.address) is lws
):
# Last-used worker is full or unknown; pick a new worker for the next few tasks
ws = self.last_root_worker = min(
pool, key=lambda ws: len(ws.processing) / ws.nthreads
)
# TODO better batching metric (`len(tg)` is not necessarily the total number of root tasks!)
self.last_root_worker_tasks_left = math.floor(
(len(ts.group) / self.total_nthreads) * ws.nthreads
ws = min(pool, key=partial(self.worker_objective, ts))
tg.last_worker_tasks_left = math.floor(
(len(tg) / self.total_nthreads) * ws.nthreads
)
else:
ws = lws

self.last_root_worker_tasks_left -= 1
# Record `last_worker`, or clear it on the final task
tg.last_worker = (
ws if tg.states["released"] + tg.states["waiting"] > 1 else None
)
tg.last_worker_tasks_left -= 1
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference, what it looked like before #6985:

ws = tg.last_worker
if not (ws and tg.last_worker_tasks_left and ws.address in self.workers):
# Last-used worker is full or unknown; pick a new worker for the next few tasks
ws = min(
(self.idle or self.workers).values(),
key=partial(self.worker_objective, ts),
)
assert ws
tg.last_worker_tasks_left = math.floor(
(len(tg) / self.total_nthreads) * ws.nthreads
)
# Record `last_worker`, or clear it on the final task
tg.last_worker = (
ws if tg.states["released"] + tg.states["waiting"] > 1 else None
)
tg.last_worker_tasks_left -= 1
return ws

Note there's still a slight change here—previously we'd schedule onto any worker if none were idle, now we only schedule onto running workers.


if self.validate and ws is not None:
assert self.workers.get(ws.address) is ws
Expand Down
15 changes: 0 additions & 15 deletions distributed/tests/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,21 +250,6 @@ def random(**kwargs):
test_decide_worker_coschedule_order_neighbors_()


@pytest.mark.parametrize("ngroups", [1, 2, 3, 5])
@gen_cluster(
client=True,
nthreads=[("", 1), ("", 1)],
)
async def test_decide_worker_coschedule_order_binary_op(c, s, a, b, ngroups):
roots = [[delayed(i, name=f"x-{n}-{i}") for i in range(8)] for n in range(ngroups)]
zs = [sum(rs) for rs in zip(*roots)]

await c.gather(c.compute(zs))

assert not a.transfer_incoming_log, [l["keys"] for l in a.transfer_incoming_log]
assert not b.transfer_incoming_log, [l["keys"] for l in b.transfer_incoming_log]


@pytest.mark.slow
@gen_cluster(
nthreads=[("", 2)] * 4,
Expand Down