Skip to content

[tune] Prefix global object registry with job ID to avoid conflicts in multi tenancy - #33095

Merged
krfricke merged 7 commits into
ray-project:masterfrom
krfricke:tune/registry-conflict-job-id
Mar 7, 2023
Merged

[tune] Prefix global object registry with job ID to avoid conflicts in multi tenancy#33095
krfricke merged 7 commits into
ray-project:masterfrom
krfricke:tune/registry-conflict-job-id

Conversation

@krfricke

@krfricke krfricke commented Mar 7, 2023

Copy link
Copy Markdown
Contributor

Why are these changes needed?

In #32560, we documented a workaround for the multi tenancy issues in Ray Tune, e.g. described in #30091.

This PR fixes the root issue by prefixing the global registry with the core worker job ID, which is unique per driver process. This will avoid conflicts between parallel running tune trials.

To prove that it works, we modify the fix from #32560 to not require a workaround anymore.

To avoid cluttering the global key-value store with stale objects, we also de-register objects from the global KV store after finishing a Ray Tune run.

Related issue number

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

Kai Fricke added 5 commits February 16, 2023 15:40
Signed-off-by: Kai Fricke <kai@anyscale.com>
Signed-off-by: Kai Fricke <kai@anyscale.com>
Signed-off-by: Kai Fricke <kai@anyscale.com>
Signed-off-by: Kai Fricke <kai@anyscale.com>
Signed-off-by: Kai Fricke <coding@kaifricke.com>
@krfricke
krfricke marked this pull request as ready for review March 7, 2023 05:19
Comment thread python/ray/tune/registry.py Outdated
def _register_atexit(self):
if not self._atexit_handler_registered:
atexit.register(_unregister_all)
self._atexit_handler_registered = True

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess we're assuming this is only ever used on the driver. Is that true?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's a good point. rllib registers envs/trainers on import. So if a remote process triggers an import, this may be triggered. I've added a check to only register this handler on the driver, which should be safe.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Guarding this on the driver only sounds good to me.

@ericl

ericl commented Mar 7, 2023

Copy link
Copy Markdown
Contributor

I wonder if we should rethink this whole registry thing. Would it be possible to replace it with a named actor pinned to the head node, which would automatically get gc'ed with the job end?

@ericl ericl added the @author-action-required The PR author is responsible for the next step. Remove tag to send back to the reviewer. label Mar 7, 2023
Signed-off-by: Kai Fricke <kai@anyscale.com>
@krfricke

krfricke commented Mar 7, 2023

Copy link
Copy Markdown
Contributor Author

We discuss some alternatives in this doc, including the detached actor.

My main concern at the moment is the fault tolerance, i.e. recreating the actor if it fails. My feeling (maybe wrongly so) is that the global kv store has better availability guarantees - is that accurate?

Since we have the registry already, I think this PR is very non-invasive to the current logic. If it's fine with you, I'd like to go ahead with the changes in the PR and track the detached actor refactor as a P2 improvement.

@krfricke krfricke removed the @author-action-required The PR author is responsible for the next step. Remove tag to send back to the reviewer. label Mar 7, 2023
return

if ray._private.worker.global_worker.mode != ray.SCRIPT_MODE:
# Only cleanup on the driver

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think it's acceptable to not care about Ray client here. The garbage we may collect should be small in any case, and we didn't do any cleanup previously at all.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That seems ok, though wouldn't this also work in client mode automatically, as the Tune driver is usually run on the driver in client mode too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The default behavior is to wrap the whole tune run/tuner object in a remote task/actor, which would then be WORKER_MODE

return

if ray._private.worker.global_worker.mode != ray.SCRIPT_MODE:
# Only cleanup on the driver

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That seems ok, though wouldn't this also work in client mode automatically, as the Tune driver is usually run on the driver in client mode too?

@ericl ericl added the @author-action-required The PR author is responsible for the next step. Remove tag to send back to the reviewer. label Mar 7, 2023
self._atexit_handler_registered = False

@property
def prefix(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
def prefix(self):
def job_id_prefix(self):

For clarity.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll leave it as prefix as it can be specified in the registry init to something other than the job id (mostly for compatibility, we can remove this later though).

@krfricke
krfricke merged commit 31a991f into ray-project:master Mar 7, 2023
@krfricke
krfricke deleted the tune/registry-conflict-job-id branch March 7, 2023 21:52
ProjectsByJackHe pushed a commit to ProjectsByJackHe/ray that referenced this pull request Mar 21, 2023
…n multi tenancy (ray-project#33095)

In ray-project#32560, we documented a workaround for the multi tenancy issues in Ray Tune, e.g. described in ray-project#30091.

This PR fixes the root issue by prefixing the global registry with the core worker job ID, which is unique per driver process. This will avoid conflicts between parallel running tune trials.

To prove that it works, we modify the fix from ray-project#32560 to not require a workaround anymore.

To avoid cluttering the global key-value store with stale objects, we also de-register objects from the global KV store after finishing a Ray Tune run.

Signed-off-by: Kai Fricke <kai@anyscale.com>
Signed-off-by: Kai Fricke <coding@kaifricke.com>
Signed-off-by: Jack He <jackhe2345@gmail.com>
edoakes pushed a commit to edoakes/ray that referenced this pull request Mar 22, 2023
…n multi tenancy (ray-project#33095)

In ray-project#32560, we documented a workaround for the multi tenancy issues in Ray Tune, e.g. described in ray-project#30091.

This PR fixes the root issue by prefixing the global registry with the core worker job ID, which is unique per driver process. This will avoid conflicts between parallel running tune trials.

To prove that it works, we modify the fix from ray-project#32560 to not require a workaround anymore.

To avoid cluttering the global key-value store with stale objects, we also de-register objects from the global KV store after finishing a Ray Tune run.

Signed-off-by: Kai Fricke <kai@anyscale.com>
Signed-off-by: Kai Fricke <coding@kaifricke.com>
Signed-off-by: Edward Oakes <ed.nmi.oakes@gmail.com>
peytondmurray pushed a commit to peytondmurray/ray that referenced this pull request Mar 22, 2023
…n multi tenancy (ray-project#33095)

In ray-project#32560, we documented a workaround for the multi tenancy issues in Ray Tune, e.g. described in ray-project#30091.

This PR fixes the root issue by prefixing the global registry with the core worker job ID, which is unique per driver process. This will avoid conflicts between parallel running tune trials.

To prove that it works, we modify the fix from ray-project#32560 to not require a workaround anymore.

To avoid cluttering the global key-value store with stale objects, we also de-register objects from the global KV store after finishing a Ray Tune run.

Signed-off-by: Kai Fricke <kai@anyscale.com>
Signed-off-by: Kai Fricke <coding@kaifricke.com>
elliottower pushed a commit to elliottower/ray that referenced this pull request Apr 22, 2023
…n multi tenancy (ray-project#33095)

In ray-project#32560, we documented a workaround for the multi tenancy issues in Ray Tune, e.g. described in ray-project#30091.

This PR fixes the root issue by prefixing the global registry with the core worker job ID, which is unique per driver process. This will avoid conflicts between parallel running tune trials.

To prove that it works, we modify the fix from ray-project#32560 to not require a workaround anymore.

To avoid cluttering the global key-value store with stale objects, we also de-register objects from the global KV store after finishing a Ray Tune run.

Signed-off-by: Kai Fricke <kai@anyscale.com>
Signed-off-by: Kai Fricke <coding@kaifricke.com>
Signed-off-by: elliottower <elliot@elliottower.com>
ProjectsByJackHe pushed a commit to ProjectsByJackHe/ray that referenced this pull request May 4, 2023
…n multi tenancy (ray-project#33095)

In ray-project#32560, we documented a workaround for the multi tenancy issues in Ray Tune, e.g. described in ray-project#30091.

This PR fixes the root issue by prefixing the global registry with the core worker job ID, which is unique per driver process. This will avoid conflicts between parallel running tune trials.

To prove that it works, we modify the fix from ray-project#32560 to not require a workaround anymore.

To avoid cluttering the global key-value store with stale objects, we also de-register objects from the global KV store after finishing a Ray Tune run.

Signed-off-by: Kai Fricke <kai@anyscale.com>
Signed-off-by: Kai Fricke <coding@kaifricke.com>
Signed-off-by: Jack He <jackhe2345@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

@author-action-required The PR author is responsible for the next step. Remove tag to send back to the reviewer.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants