forked from dask/distributed
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cluster Dump SchedulerPlugin (dask#5983)
Add SchedulerPlugin to dump state on cluster close This also adds a new method to SchedulerPlugins that runs directly before closing time
- Loading branch information
Showing
6 changed files
with
73 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from typing import Any, Collection, Dict, Literal | ||
|
||
from distributed.cluster_dump import ( | ||
DEFAULT_CLUSTER_DUMP_EXCLUDE, | ||
DEFAULT_CLUSTER_DUMP_FORMAT, | ||
) | ||
from distributed.diagnostics.plugin import SchedulerPlugin | ||
from distributed.scheduler import Scheduler | ||
|
||
|
||
class ClusterDump(SchedulerPlugin): | ||
"""Dumps cluster state prior to Scheduler shutdown | ||
The Scheduler may shutdown in cases where it is in an error state, | ||
or when it has been unexpectedly idle for long periods of time. | ||
This plugin dumps the cluster state prior to Scheduler shutdown | ||
for debugging purposes. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
url: str, | ||
exclude: "Collection[str]" = DEFAULT_CLUSTER_DUMP_EXCLUDE, | ||
format_: Literal["msgpack", "yaml"] = DEFAULT_CLUSTER_DUMP_FORMAT, | ||
**storage_options: Dict[str, Any], | ||
): | ||
self.url = url | ||
self.exclude = exclude | ||
self.format = format_ | ||
self.storage_options = storage_options | ||
|
||
async def start(self, scheduler: Scheduler) -> None: | ||
self.scheduler = scheduler | ||
|
||
async def before_close(self) -> None: | ||
await self.scheduler.dump_cluster_state_to_url( | ||
self.url, self.exclude, self.format, **self.storage_options | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from distributed.cluster_dump import DumpArtefact | ||
from distributed.diagnostics.cluster_dump import ClusterDump | ||
from distributed.utils_test import gen_cluster, inc | ||
|
||
|
||
@gen_cluster(client=True) | ||
async def test_cluster_dump_plugin(c, s, *workers, tmp_path): | ||
dump_file = tmp_path / "cluster_dump.msgpack.gz" | ||
await c.register_scheduler_plugin(ClusterDump(str(dump_file)), name="cluster-dump") | ||
plugin = s.plugins["cluster-dump"] | ||
assert plugin.scheduler is s | ||
|
||
f1 = c.submit(inc, 1) | ||
f2 = c.submit(inc, f1) | ||
|
||
assert (await f2) == 3 | ||
await s.close(close_workers=True) | ||
|
||
dump = DumpArtefact.from_url(str(dump_file)) | ||
assert {f1.key, f2.key} == set(dump.scheduler_story(f1.key, f2.key).keys()) | ||
assert {f1.key, f2.key} == set(dump.worker_story(f1.key, f2.key).keys()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters