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

Refactor ActorManager to store underlying remote actors in dict. #29953

Merged
merged 2 commits into from
Nov 3, 2022

Conversation

gjoliver
Copy link
Member

@gjoliver gjoliver commented Nov 2, 2022

Signed-off-by: Jun Gong jungong@anyscale.com

Why are these changes needed?

To upgrade things in a backward-compatible way, ActorManager needs to support remove_actor() API, which make it much easier to do if we stored the underlying actor handles in a dict.

Also fix a minor issue where None is a legit result for a remote call.

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 :(

Signed-off-by: Jun Gong <jungong@anyscale.com>

@DeveloperAPI
def clear(self):
"""Clean up managed actors."""
while self.__actors:
del self.__actors[0]
for actor in self.__actors.values():
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you unit-test clear? Can you del a value of a dict without deling the key? why not loop through all the keys and do del self.__actors[key]?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah it works. I added it to all the unit test cases.
you can't del keys while looping through a dict though.

>>> for k in a.keys(): del a[k]
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: dictionary changed size during iteration
>>> 

deletion is always tricky. you need to make sure you are not holding an iterator while deleting things.

Copy link
Contributor

Choose a reason for hiding this comment

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

wait, what? this works for me?

>>> a = {'a': 1, 'b': 2}
>>> for k in a.keys(): del a[k]

Copy link
Member Author

Choose a reason for hiding this comment

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

what?! let me double check.

actor_idx = remote_actor_indices[i]
for r in ready:
# Find the corresponding actor ID for this remote call.
actor_id = remote_actor_ids[remote_calls.index(r)]
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see index method implemented for RemoteCallResults class. How does this work? what's the run time of finding the index? Should RemoteCallResults() internally be a dict so that the look up is O(1)?

Copy link
Member Author

Choose a reason for hiding this comment

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

remote_calls is a List[ObjectRef]. index is an API for python ilst.
I think it's likely ok, we will never have millions of outstanding requests, so probably shouldn't complicate the API for performance reasons.
modern computer is pretty fast ... :)

Copy link
Contributor

Choose a reason for hiding this comment

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

got it. makes sense.

Copy link
Contributor

@kouroshHakha kouroshHakha left a comment

Choose a reason for hiding this comment

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

Good work 👍 . A few questions and nits?

Signed-off-by: Jun Gong <jungong@anyscale.com>
Copy link
Contributor

@kouroshHakha kouroshHakha left a comment

Choose a reason for hiding this comment

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

LGTM. merge once the tests pass.

@gjoliver gjoliver merged commit b84dac2 into ray-project:master Nov 3, 2022
WeichenXu123 pushed a commit to WeichenXu123/ray that referenced this pull request Dec 19, 2022
…-project#29953)

Signed-off-by: Jun Gong <jungong@anyscale.com>
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
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.

2 participants