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

Fine performance metrics: client context manager #7667

Open
crusaderky opened this issue Mar 17, 2023 · 1 comment
Open

Fine performance metrics: client context manager #7667

crusaderky opened this issue Mar 17, 2023 · 1 comment

Comments

@crusaderky
Copy link
Collaborator

crusaderky commented Mar 17, 2023

Add a trivial context manager in the client to measure a run end to end.
Rough POC below; the real thing would need to work with async clients and use RPC instead of run_on_scheduler:

@contextmanager
def get_run_metrics(self) -> Iterator[dict[tuple[str, ...], float]]:
    t0 = perf_counter()
    before = client.run_on_scheduler(lambda dask_scheduler: dask_scheduler.cumulative_worker_metrics)
    out = {}
    yield out
    after = client.run_on_scheduler(lambda dask_scheduler: dask_scheduler.cumulative_worker_metrics)
    t1 = perf_counter()
    for k, v in before.items:
        after[k] -= v
    out.update(after)
    observed_time =  (t1 - t0) * cluster_threads 
    execute_time = sum(
        v for k, v in after.items() 
        if isinstance(k, tuple) and k[0] == "execute" and k[-1] == "seconds"
    )
    out["execute", "n/a", "client", "seconds"] = max(0, observed_time - execute_time)


with c.get_run_metrics() as metrics:
    my_collection.compute()

The actual method name could use improvement.

Note that the above snippet allows measuring the time spent in client->scheduler comms - which can be very substantial.
It will be very large unless we also deliver #7671 and #7672.

@crusaderky
Copy link
Collaborator Author

The above design needs to be overhauled on top of the new span context manager

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant