-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
[core] Use psutil.process_iter
to replace psutil.pids
#51123
[core] Use psutil.process_iter
to replace psutil.pids
#51123
Conversation
@@ -2289,3 +2287,19 @@ def start_ray_client_server( | |||
fate_share=fate_share, | |||
) | |||
return process_info | |||
|
|||
|
|||
def _is_raylet_process(cmdline: Optional[List[str]]) -> bool: |
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 about taking a proc object directly?
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 may prefer to use cmdline
to avoid passing the whole Process object into this function. This makes it easier for us to write mock data for unit tests if needed. Another reason is to avoid using proc.info["cmdline"]
in this function so that we can clearly determine that cmdline
is used in the loop above; and we can easily know why do we use psutil.process_iter(["cmdline"])
.
proc = psutil.Process(pid) | ||
proc_stats.append((get_rss(proc.memory_info()), pid, proc.cmdline())) | ||
proc_stats.append( | ||
(get_rss(proc.info["memory_info"]), proc.pid, proc.info["cmdline"]) |
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.
proc.pid
is set when Process
is constructed. No need to specify it in process_iter
.
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.
Looks fine. Is this covered by existing tests?
Yes
|
…t#51123) * Use `psutil.process_iter` to replace `psutil.pids`. * Use `proc.info["name"]` instead of `proc.name()`. * I'm not sure whether `proc.name()` uses the cache set by `process_iter`, but I'm certain that using info is correct since the official docs frequently use `proc.info[...]` with `process_iter`. * I asked a question on giampaolo/psutil#2518, but I'm not sure how long it will take to get an answer from the community. For now, I think we can merge it, and I'll update the use of psutil if the maintainers have any suggestions. --------- Signed-off-by: kaihsun <kaihsun@anyscale.com>
Why are these changes needed?
psutil.process_iter
to replacepsutil.pids
.proc.info["name"]
instead ofproc.name()
.proc.name()
uses the cache set byprocess_iter
, but I'm certain that using info is correct since the official docs frequently useproc.info[...]
withprocess_iter
.proc.info
is slower thanproc.name()
giampaolo/psutil#2518, but I'm not sure how long it will take to get an answer from the community. For now, I think we can merge it, and I'll update the use of psutil if the maintainers have any suggestions.Related issue number
Checks
git commit -s
) in this PR.scripts/format.sh
to lint the changes in this PR.method in Tune, I've added it in
doc/source/tune/api/
under thecorresponding
.rst
file.