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

[Usage stats] Record Ray native library usage from a home temp folder #25842

Merged
merged 11 commits into from
Jun 24, 2022

Conversation

rkooo567
Copy link
Contributor

Why are these changes needed?

This PR records the historical Ray native library usage to the home temp folder. Note that library usage only includes Ray native libraries (rllib, tune, dataset, workflow, and train). NOTE: The library usage is always recorded to /tmp/ray, but they will only recorded when the cluster that enables the usage stats is running. Note that this can generate quite big amount of false positive (e.g., If I import rllib once, and start cluster for local development, they will all considered as a rllib cluster).

Related issue number

Checks

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

# We need a file lock in order to
# Set the short timeout to avoid too long delay in import.
with TempFileLock(str(self.lib_usage_file), timeout=2):
with self.lib_usage_file.open("a+") as f:
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't use a file lock, just touch separate files for each key.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this still can have some corruption (race condition) if there's more than one instance or driver running concurrently.

Copy link
Contributor

Choose a reason for hiding this comment

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

Touch a separate file (don't write anything, just create it), for each library. They can have separate file names.

Copy link
Contributor

Choose a reason for hiding this comment

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

Basically, mirror the kv put strategy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I see. That's a great idea. Let me follow up

Copy link
Contributor Author

@rkooo567 rkooo567 Jun 20, 2022

Choose a reason for hiding this comment

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

Addressed. It seems like Windows doesn't support atomic file creation, so I used Filelock there. For Linux, it seems like PathLib().touch() uses exclusive open, so it seems to be safe to just use touch(exist_ok=True)

@ericl ericl added @author-action-required The PR author is responsible for the next step. Remove tag to send back to the reviewer. 1.13.1-pick labels Jun 16, 2022
if lib_name not in libs:
f.seek(0, io.SEEK_END)
self._write(f, lib_name)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO add docstring

ray._private.utils.get_ray_temp_dir()
).read()
for library_usage in historical_lib_usages:
if library_usage not in result:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The overhead should be pretty small as there are only 5 libs

import tempfile
from pathlib import Path

if sys.platform == "win32":
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I realized the basic FileLock is Unix only

# We need a file lock in order to
# Set the short timeout to avoid too long delay in import.
with TempFileLock(str(self.lib_usage_file), timeout=2):
with self.lib_usage_file.open("a+") as f:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this still can have some corruption (race condition) if there's more than one instance or driver running concurrently.

@rkooo567
Copy link
Contributor Author

It will be ready by today!

@rkooo567 rkooo567 removed the @author-action-required The PR author is responsible for the next step. Remove tag to send back to the reviewer. label Jun 20, 2022
python/ray/_private/usage/usage_lib.py Outdated Show resolved Hide resolved
python/ray/_private/usage/usage_lib.py Outdated Show resolved Hide resolved
python/ray/util/ml_utils/filelock.py Outdated Show resolved Hide resolved
@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 Jun 21, 2022
@rkooo567
Copy link
Contributor Author

Working on fixing the weird test failure + Windows issue

@rkooo567 rkooo567 removed the @author-action-required The PR author is responsible for the next step. Remove tag to send back to the reviewer. label Jun 22, 2022
@ericl ericl merged commit c2e003a into ray-project:master Jun 24, 2022
@jjyao jjyao mentioned this pull request Feb 24, 2023
7 tasks
ericl pushed a commit that referenced this pull request Feb 25, 2023
#25842 is not needed since we will no longer accidentally create a new cluster while an existing one is running after #26678
edoakes pushed a commit to edoakes/ray that referenced this pull request Mar 22, 2023
ray-project#25842 is not needed since we will no longer accidentally create a new cluster while an existing one is running after ray-project#26678

Signed-off-by: Edward Oakes <[email protected]>
peytondmurray pushed a commit to peytondmurray/ray that referenced this pull request Mar 22, 2023
ray-project#25842 is not needed since we will no longer accidentally create a new cluster while an existing one is running after ray-project#26678
elliottower pushed a commit to elliottower/ray that referenced this pull request Apr 22, 2023
ray-project#25842 is not needed since we will no longer accidentally create a new cluster while an existing one is running after ray-project#26678

Signed-off-by: elliottower <[email protected]>
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.

3 participants