Skip to content

Commit

Permalink
Send log-event if worker is restarted because of memory pressure (#8617)
Browse files Browse the repository at this point in the history
  • Loading branch information
phofl committed Apr 15, 2024
1 parent cd9951b commit 0f2290b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 6 additions & 0 deletions distributed/tests/test_nanny.py
Expand Up @@ -660,6 +660,12 @@ async def test_restart_memory(c, s, n):
while not s.workers:
await asyncio.sleep(0.1)

msgs = s.get_events("worker-restart-memory")
assert len(msgs)
msg = msgs[0][1]
assert isinstance(msg, dict)
assert {"worker", "pid", "rss"}.issubset(set(msg))


class BlockClose(WorkerPlugin):
def __init__(self, close_happened):
Expand Down
11 changes: 9 additions & 2 deletions distributed/worker_memory.py
Expand Up @@ -417,12 +417,19 @@ def memory_monitor(self, nanny: Nanny) -> None:
return

if self._last_terminated_pid != process.pid:
nanny_logger.warning(
msg = (
f"Worker {nanny.worker_address} (pid={process.pid}) exceeded "
f"{self.memory_terminate_fraction * 100:.0f}% memory budget. "
"Restarting...",
f"Restarting..."
)
nanny_logger.warning(msg)
self._last_terminated_pid = process.pid
event = {
"worker": nanny.worker_address,
"pid": process.pid,
"rss": memory,
}
nanny.log_event("worker-restart-memory", event)
process.terminate()
else:
# We already sent SIGTERM to the worker, but the process is still alive
Expand Down

0 comments on commit 0f2290b

Please sign in to comment.