-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Add runtime_context to get some runtime fields in worker #4065
Conversation
Test PASSed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the use case that you have in mind for this? Are you planning on adding more context beyond the driver ID?
There are some alternatives, e.g., discussed in #3805 of simply exposing the current task, and then the driver ID could be accessed through the task.
python/ray/runtime_context.py
Outdated
|
||
class RuntimeContext(object): | ||
"""A class used for getting runtime context. | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the docstring is a single line, the """
should be on the previous line.
python/ray/runtime_context.py
Outdated
|
||
@property | ||
def current_driver_id(self): | ||
"""Get current driver id for this worker or driver. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change the wording, and formatting to
"""Get current driver ID for this worker or driver.
Returns:
If called by a driver, this returns the driver ID. If called in
a task, return the driver ID of the associated driver.
"""
@robertnishihara The purpose of this PR is to expose standard APIs for some useful runtime info, e.g., current task, driver id, redis address, etc. Previously, users need to get these data from worker's internal fields or methods, which is likely to break as the code changes. So I'd like to propose exposing some standard APIs for them. E.g.,
What do you think? |
Test PASSed. |
60f4e44
to
74c59d2
Compare
Test FAILed. |
Test PASSed. |
Test FAILed. |
python/ray/__init__.py
Outdated
@@ -122,6 +123,7 @@ | |||
"remote", | |||
"shutdown", | |||
"wait", | |||
"runtime_context", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you keep these items in alphabetical order?
Co-Authored-By: jovany-wang <kingchin1218@126.com>
Co-Authored-By: jovany-wang <kingchin1218@126.com>
Co-Authored-By: jovany-wang <kingchin1218@126.com>
ac964fd
to
cd01d46
Compare
I have refined this PR, feel free to review it again. |
Test FAILed. |
Test FAILed. |
test/runtest.py
Outdated
@@ -2842,3 +2842,18 @@ def f(): | |||
return 1 | |||
|
|||
assert ray.get(f.remote()) == 1 | |||
|
|||
|
|||
def test_runtime_context(shutdown_only): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can change runtest.py/test_specific_driver_id
to use runtime context, then we don't need to add this test.
Test FAILed. |
Test FAILed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a fine approach to take. I prefer ray._get_runtime_context()
since presumably this will change a bunch in the future (e.g., we will add new fields, change the name of some fields, etc).
Almost all users shouldn't need to think about the runtime context, right? Certainly the current driver ID doesn't matter for most users. So I think it makes sense for this to be somewhat less exposed.
Sounds good. Agreed that this should be less exposed. |
Test FAILed. |
Test FAILed. |
Test FAILed. |
What do these changes do?
Usage:
We add a
runtime_cotext
to keep some runtime fields.In this PR, we add an attribution
current_driver_id
which is used in many situations as we needed.In the future, we can add other attrs to this like
current_actor_id
,was_current_actor_reconstructed
ant etc.Related issue number
N/A