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

Avoid expensive occupancy calculation when unused #7257

Merged
merged 1 commit into from
Nov 4, 2022
Merged
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
15 changes: 8 additions & 7 deletions distributed/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3026,9 +3026,7 @@ def check_idle_saturated(self, ws: WorkerState, occ: float = -1.0):
if occ < 0:
occ = ws.occupancy

nc: int = ws.nthreads
p: int = len(ws.processing)
avg: float = self.total_occupancy / self.total_nthreads
p = len(ws.processing)

idle = self.idle
saturated = self.saturated
Expand All @@ -3043,9 +3041,10 @@ def check_idle_saturated(self, ws: WorkerState, occ: float = -1.0):
else:
idle.pop(ws.address, None)

nc = ws.nthreads
if p > nc:
pending: float = occ * (p - nc) / (p * nc)
if 0.4 < pending > 1.9 * avg:
pending = occ * (p - nc) / (p * nc)
if 0.4 < pending > 1.9 * (self.total_occupancy / self.total_nthreads):
saturated.add(ws)
return

Expand All @@ -3055,8 +3054,10 @@ def is_unoccupied(
self, ws: WorkerState, occupancy: float, nprocessing: int
) -> bool:
nthreads = ws.nthreads
avg_occ_per_thread = self.total_occupancy / self.total_nthreads
return nprocessing < nthreads or occupancy < nthreads * avg_occ_per_thread / 2
return (
nprocessing < nthreads
or occupancy < nthreads * (self.total_occupancy / self.total_nthreads) / 2
)

def get_comm_cost(self, ts: TaskState, ws: WorkerState) -> float:
"""
Expand Down