Fine performance metrics: client context manager
- Dominant language
- Python
- Stars
- 1.7k
- Forks
- 778
- Avg merge
- 2h 50m
- Merged PRs (30d)
- 3
Description
- Part of #7665
- Blocked by #7666
- Soft-blocked by #7671
- Soft-blocked by #7672
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:
```python
@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.
Contributor guide
Assessment
This issue has not been assessed yet.