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

Optionally capture more frames in computations #7656

Merged
merged 6 commits into from Apr 4, 2023

Conversation

gjoseph92
Copy link
Collaborator

Adds a distributed.diagnostics.computations.nframes parameter, controlling how many frames of client code are captured in Computations.

Sets the default value to 0, so by default, no code is captured. I can easily change this to 1 if we'd prefer. But 0 seemed like a reasonable default, since:

  1. Capturing the code is pretty quick, but has a non-zero time cost, especially if you're calling submit in a loop.
  2. This captured code isn't displayed to users anywhere right now. I doubt anyone besides Coiled is using this feature?
  3. Systems that want to turn on code-capture (like Coiled) can do so by modifying client-side dask config

Also changes Computation.code from holding strings to tuples of strings.

  • Tests added / passed
  • Passes pre-commit run --all-files

cc @ntabris

@gjoseph92 gjoseph92 requested a review from fjetter as a code owner March 15, 2023 19:12
@ntabris
Copy link
Contributor

ntabris commented Mar 15, 2023

@gjoseph92 is there already a pattern is dask-land for modifying client-side config? I'm not currently aware of a way to override the default but also not override if user sets this to non-default value? Would we say that if you're using Coiled, then distributed.diagnostics.computations.nframes is ignored and you should use (eg) coiled.analytics.computations.nframes instead?

@github-actions
Copy link
Contributor

github-actions bot commented Mar 15, 2023

Unit Test Results

See test report for an extended history of previous test failures. This is useful for diagnosing flaky tests.

       26 files  +       15         26 suites  +15   13h 28m 11s ⏱️ + 9h 20m 12s
  3 546 tests +         2    3 439 ✔️ +       21     106 💤  -      17  1  - 1 
44 858 runs  +27 714  42 620 ✔️ +26 401  2 237 💤 +1 315  1  - 1 

For more details on these failures, see this check.

Results for commit 77893e2. ± Comparison against base commit 37ce1a0.

♻️ This comment has been updated with latest results.

@fjetter
Copy link
Member

fjetter commented Mar 16, 2023

is there already a pattern is dask-land for modifying client-side config?

theoretically, you can set config values in import or when running certain functions using

dask.config.set({"value": 42})

There is no way to register default fallbacks for certain configuration values (yet)

@@ -5539,7 +5551,8 @@ async def __aenter__(self):
async def __aexit__(self, exc_type, exc_value, traceback, code=None):
client = get_client()
if code is None:
code = client._get_computation_code(self._stacklevel + 1)
frames = client._get_computation_code(self._stacklevel + 1, nframes=1)
code = frames[0] if frames else "<Code not available>"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic string here doesn't seem ideal, what about using None when we can't get code?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is inserted into the performance report; _get_computation_code would have returned "<Code not available>" before this PR, so I wanted to just keep the same behavior.

@ntabris
Copy link
Contributor

ntabris commented Mar 16, 2023

For Coiled I think it's important that we're able to set the default to something non-zero, since we want to collect code by default, while also letting user override. Is there a good way to do that? According to the config doc, dask defaults take precedence over project defaults.

@gjoseph92
Copy link
Collaborator Author

Yeah, I think the problem is that we can't distinguish "0 because it's the default" from "0 because the user is explicitly setting it to override Coiled setting it to something non-zero". We could make the default None in config, and convert None to 0 in code? (Not as ideal but easier to override.)

@gjoseph92
Copy link
Collaborator Author

I dislike this, but another option would be for the coiled package to set distributed.diagnostics.computations.nframes at import time. Then if you have a dask.config.set in your code (most likely after the import), it'll be overridden again.

@fjetter
Copy link
Member

fjetter commented Apr 3, 2023

An issue was raised that reports the slowness of this code collection in #7740 which would motivate disabling this by default.

There is a not-welll-hardly-at-all documented way for third parties to register defaults, IIUC coiled could set it's default here on import time ( and call config.refresh). If this does not work we should take care of this issue in another PR.
It is documented that this feature exists but not how it is done (FWIW the example mentions distributed but distributed is not using this, maybe it should for some things...)

@gjoseph92 can you rebase/merge main please?

@gjoseph92
Copy link
Collaborator Author

@fjetter merged main. Agreed that it seems we should merge this to turn the behavior off by default, then look into how Coiled will set the config in a separate PR.

It looks like distributed is using dask.config.update_defaults:

with open(fn) as f:
defaults = yaml.safe_load(f)
dask.config.update_defaults(defaults)

That sounds pretty much like what we're looking for for Coiled. It just automates what you suggested of adding to defaults, then refreshing the global config.

@fjetter
Copy link
Member

fjetter commented Apr 4, 2023

It looks like distributed is using dask.config.update_defaults:

That's interesting. There's always something new to discover...

@fjetter fjetter merged commit dac5923 into dask:main Apr 4, 2023
30 of 33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants