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

Add runtime_context to get some runtime fields in worker #4065

Merged
merged 13 commits into from
Feb 19, 2019

Conversation

jovany-wang
Copy link
Contributor

@jovany-wang jovany-wang commented Feb 15, 2019

What do these changes do?

Usage:

# in worker or driver
id = ray.get_runtime_context().current_driver_id

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

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/11997/
Test PASSed.

Copy link
Collaborator

@robertnishihara robertnishihara left a 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.


class RuntimeContext(object):
"""A class used for getting runtime context.
"""
Copy link
Collaborator

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.


@property
def current_driver_id(self):
"""Get current driver id for this worker or driver.
Copy link
Collaborator

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.
        """

@raulchen
Copy link
Contributor

@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.,

ray.runtime_context.current_task()
ray.runtime_context.current_driver_id()
ray.runtime_context.redis_address()

What do you think?

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/12024/
Test PASSed.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/12033/
Test FAILed.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/12032/
Test PASSed.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/12048/
Test FAILed.

@@ -122,6 +123,7 @@
"remote",
"shutdown",
"wait",
"runtime_context",
Copy link
Contributor

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?

Jovan and others added 6 commits February 18, 2019 11:07
Co-Authored-By: jovany-wang <kingchin1218@126.com>
Co-Authored-By: jovany-wang <kingchin1218@126.com>
Co-Authored-By: jovany-wang <kingchin1218@126.com>
@jovany-wang
Copy link
Contributor Author

jovany-wang commented Feb 18, 2019

I have refined this PR, feel free to review it again.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/12062/
Test FAILed.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/12064/
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):
Copy link
Contributor

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.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/12067/
Test FAILed.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/12071/
Test FAILed.

Copy link
Collaborator

@robertnishihara robertnishihara left a 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.

@raulchen
Copy link
Contributor

Sounds good. Agreed that this should be less exposed.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/12080/
Test FAILed.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/12083/
Test FAILed.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/12104/
Test FAILed.

@raulchen raulchen merged commit 794a093 into ray-project:master Feb 19, 2019
@jovany-wang jovany-wang deleted the runtime_context branch February 20, 2019 08:54
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.

4 participants