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

[core] [no-op] Cleanup utils folder bazel dependency #49938

Merged

Conversation

dentiny
Copy link
Contributor

@dentiny dentiny commented Jan 18, 2025

Motivation: @jjyao was helping debugging a boost dependency issue, and found for some of the util targets are built twice since they were included in two targets.

The best practice for using bazel is to define bazel targets for each translation unit (for C++), and only wrap a few translation units when (1) they're usually used together; (2) they have interdependency.

This PR split the giant util target into smaller targets, so next time we could , and should include a clear single target.
it includes some dependency cleanup and apply IWYU, overall a no-op change.

@dentiny dentiny added the go add ONLY when ready to merge, run all tests label Jan 18, 2025
@dentiny dentiny requested review from jjyao, rynewang and dayshah January 18, 2025 07:40
@dentiny dentiny requested a review from a team as a code owner January 18, 2025 07:40
Copy link
Contributor

@dayshah dayshah left a comment

Choose a reason for hiding this comment

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

nice lgtm, did you get get boost iostreams to work?

src/ray/util/filesystem.h Outdated Show resolved Hide resolved
@dentiny
Copy link
Contributor Author

dentiny commented Jan 18, 2025

nice lgtm, did you get get boost iostreams to work?

Yeah Jiajun helped me work out, the issue is we have two targets compiling pipe logger; one of them has the necessary dependency but the other one doesn't :(

@@ -1015,7 +1015,7 @@ bool TaskManager::RetryTaskIfPossible(const TaskID &task_id,
// TODO(clarng): clean up and remove task_retry_delay_ms that is relied
// on by some tests.
int32_t delay_ms = task_failed_due_to_oom
? ExponentialBackoff::GetBackoffMs(
? ExponentialBackOff::GetBackoffMs(
Copy link
Collaborator

Choose a reason for hiding this comment

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

what's changed in this line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

upper case and lower case.

@@ -1,44 +1,213 @@
load("//bazel:ray.bzl", "ray_cc_library")

Copy link
Collaborator

Choose a reason for hiding this comment

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

@aslonnie is this file now follows bazel best practice? Need your expertise here :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not yet, the followup PR is:

  • Split the giant utils bazel target and depend what we use;
  • Split logging / filesystem dependency (should be an easy followup).

Copy link
Collaborator

Choose a reason for hiding this comment

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

overall seems fine. probably will be non-trivial to maintain this manually though.

it is the right thing to do to have fine-grained bazel build rules to have the best build performance. in the long run, we will need tools to auto maintain this build file based on static analysis of source files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in the long run, we will need tools to auto maintain this build file based on static analysis of source files.

I agree, in Nuro we have BUILD file auto-generation so I never need to hand-write bazel file;
I checked some open source tools like gazelle, but none of them seem to support C++; if you could help me with that I would be much grateful!

Comment on lines 56 to 65
uint64_t Next() {
auto ret = curr_value_;
curr_value_ = curr_value_ * multiplier_;
curr_value_ = std::min(curr_value_, max_value_);
return ret;
}

uint64_t Current() { return curr_value_; }

void Reset() { curr_value_ = initial_value_; }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we split unifying ExponentialBackoff to a separate PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines 3 to +6
ray_cc_library(
name = "util",
srcs = glob(
[
"*.cc",
],
exclude = [
"*_test.cc",
],
),
hdrs = glob([
"*.h",
]),
linkopts = select({
"@platforms//os:windows": [],
"//conditions:default": ["-lpthread"],
}),
name = "visibility",
hdrs = ["visibility.h"],
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

why are these single header libraries? are they actually just header-only libraries?

this will not even generate object files. I think there are also bazel rules that are cc_headers for headers.

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 understand, but it's common to have header-only targets.
For example, abseil one: https://github.com/abseil/abseil-cpp/blob/3735766b3bd68522c8f291675df3fddb4bc3c70d/absl/base/BUILD.bazel

deps = [
":thread_checker",
"//:aligned_alloc",
"//:sha256",
],
Copy link
Collaborator

Choose a reason for hiding this comment

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

where is this :thread_checker defined? I do not seem to find it in this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ray/src/ray/util/BUILD

Lines 216 to 221 in 8ba3ffa

ray_cc_library(
name = "thread_checker",
hdrs = ["thread_checker.h"],
srcs = ["thread_checker.cc"],
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well for missing dependency issue, we should trust the compiler and CI

Comment on lines +186 to +207
deps = [
":array",
":container_util",
":counter_map",
":event",
":event_label",
":exponential_backoff",
":function_traits",
":logging",
":macros",
":memory",
":process",
":random",
":sample",
":sequencer",
":string_utils",
":timestamp_utils",
":throttler",
":thread_utils",
":type_traits",
":visibility",
"//:sha256",
Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah.. this feels a bit wrong.. that a util library depends on so many other libs here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's written this way for target compatibility, otherwise I have to manually update a thousand files.

As I mentioned here, it's worth another PR to further cleanup the util target dependency.

@@ -1,44 +1,213 @@
load("//bazel:ray.bzl", "ray_cc_library")

Copy link
Collaborator

Choose a reason for hiding this comment

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

overall seems fine. probably will be non-trivial to maintain this manually though.

it is the right thing to do to have fine-grained bazel build rules to have the best build performance. in the long run, we will need tools to auto maintain this build file based on static analysis of source files.

@dentiny dentiny requested a review from aslonnie January 19, 2025 10:26
rynewang pushed a commit that referenced this pull request Jan 19, 2025
We have two exponential backoff class, one with `Off` in uppercase,
another one with `off` in lowercase, which is confusion; and I think it
doesn't make sense to have two classes serving strongly relavent
feature.

This PR is originally part of the refactor PR, suggested by @jjyao to
make a separate one.
Refactor PR for reference: #49938
Jiajun's comment:
#49938 (comment)

---------

Signed-off-by: dentiny <[email protected]>
jimmyxie-figma pushed a commit to jimmyxie-figma/ray that referenced this pull request Jan 20, 2025
We have two exponential backoff class, one with `Off` in uppercase,
another one with `off` in lowercase, which is confusion; and I think it
doesn't make sense to have two classes serving strongly relavent
feature.

This PR is originally part of the refactor PR, suggested by @jjyao to
make a separate one.
Refactor PR for reference: ray-project#49938
Jiajun's comment:
ray-project#49938 (comment)

---------

Signed-off-by: dentiny <[email protected]>
Signed-off-by: Jimmy Xie <[email protected]>
jimmyxie-figma pushed a commit to jimmyxie-figma/ray that referenced this pull request Jan 20, 2025
We have two exponential backoff class, one with `Off` in uppercase,
another one with `off` in lowercase, which is confusion; and I think it
doesn't make sense to have two classes serving strongly relavent
feature.

This PR is originally part of the refactor PR, suggested by @jjyao to
make a separate one.
Refactor PR for reference: ray-project#49938
Jiajun's comment:
ray-project#49938 (comment)

---------

Signed-off-by: dentiny <[email protected]>
Signed-off-by: Jimmy Xie <[email protected]>
Copy link
Collaborator

@jjyao jjyao left a comment

Choose a reason for hiding this comment

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

Thanks!

src/ray/util/tests/util_test.cc Outdated Show resolved Hide resolved
Signed-off-by: dentiny <[email protected]>
@jjyao jjyao merged commit ce40c98 into ray-project:master Jan 21, 2025
5 checks passed
anson627 pushed a commit to anson627/ray that referenced this pull request Jan 31, 2025
We have two exponential backoff class, one with `Off` in uppercase,
another one with `off` in lowercase, which is confusion; and I think it
doesn't make sense to have two classes serving strongly relavent
feature.

This PR is originally part of the refactor PR, suggested by @jjyao to
make a separate one.
Refactor PR for reference: ray-project#49938
Jiajun's comment:
ray-project#49938 (comment)

---------

Signed-off-by: dentiny <[email protected]>
Signed-off-by: Anson Qian <[email protected]>
anson627 pushed a commit to anson627/ray that referenced this pull request Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go add ONLY when ready to merge, run all tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants