-
Notifications
You must be signed in to change notification settings - Fork 4.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
Generalize memory and cpu tracking #19839
Generalize memory and cpu tracking #19839
Conversation
5c9ac6d
to
76f6134
Compare
76f6134
to
3cca2a7
Compare
Hiya, I'm handling the review but not too familiar with this area of the code yet, will spend some time looking at this and will get a review out by this week. |
@@ -37,19 +37,13 @@ | |||
public class ResourceSet implements ResourceSetOrBuilder { |
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.
Can we consolidate "memory"
and "cpu"
string usage as a static string defined here?
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.
Done
ImmutableMap<String, Double> cpuRam = | ||
ImmutableMap.of("cpu", options.localCpuResources, "memory", options.localRamResources); | ||
ImmutableMap<String, Double> resources = | ||
java.util.stream.Stream.concat(cpuRam.entrySet().stream(), options.localExtraResources.stream()) |
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.
Please import java.util.stream.Stream
above and use Stream.concat()
instead.
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.
Done
ImmutableMap<String, Double> cpuRam = | ||
ImmutableMap.of("cpu", options.localCpuResources, "memory", options.localRamResources); | ||
ImmutableMap<String, Double> resources = | ||
java.util.stream.Stream.concat(cpuRam.entrySet().stream(), options.localExtraResources.stream()) | ||
.collect( | ||
ImmutableMap.toImmutableMap( | ||
Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v2)); |
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.
IIUC, users will be able to override --local_{cpu,ram}_resources
here because there isn't a check to ensure that users don't specify --local_extra_resources={cpu,memory}=?
. Because localExtraResources.stream()
is concatenated after cpuRam.stream()
and are collected into a single map here, the former overrides the latter.
Since this map is now the source of truth (i.e. cpu and memory don't have separate fields in the ResourceSet
), Bazel won't ignore any "cpu"
or "memory"
keys in the map as it previously did.
Lets keep the previous behavior of still having the --local_{cpu,ram}_resources
flag (at least in this change). So you'd want to either flip the order of the concat, or filter out "cpu"
and "memory"
strings from localExtraResources
.
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.
Updated. I was a bit on the fence on what was best when I first made this change, because ideally I'd be nice to have one attribute to deal with all resources (see proposal in #19679). I do agree however that --local_extra_resources still carries that meaning of "resources other than some others". Might be worth adopting an incompatible flag to introduce --local_resources
, WDYT? Happy to do it as a follow up as well.
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 agree, let's follow up with a separate PR (feel free to send it to me directly). --local_resources
wouldn't need to be an incompatible flag; we can just have it override all of --local_{cpu,ram,extra}_resources
when specified, then we can mark the old flags for deprecation and remove them in the following major release.
+ cpuUsage | ||
+ "\n" | ||
+ Joiner.on("\n").withKeyValueSeparator(": ").join(extraResourceUsage.entrySet()) | ||
+ Joiner.on("\n").withKeyValueSeparator(": ").join(resources.entrySet()) |
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.
Can you preserve the behavior of this? I think it'd be better to show Memory and CPU at the top since they are the more typical resources, then the rest of the resources below.
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.
Done
// requested resource sets use pessimistic estimations. Note that this | ||
// ratio is used only during comparison - for tracking we will actually | ||
// mark whole requested amount as used. | ||
double requested = resource.getValue() * MIN_NECESSARY_RATIO.getOrDefault(key, 1.0); |
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 define 1.0
in a static constant above together with MIN_NECESSARY_RATIO
(e.g. DEFAULT_RATIO
)? That'll make it clearer what happens if it's not specified in the MIN_NECESSARY_RATIO
map.
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.
Done
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.
Thanks for your contribution! I'll get this imported internally ASAP.
@bazel-io flag |
Update: It's failing some internal tests that I'll have to spend some time fixing |
@bazel-io flag |
@brentleyjones @fmeum is this flagged for 7.0? Or 7.1? |
@keertk I would say 7.1.0 at this point. |
@bazel-io fork 7.1.0 |
@keertk @fmeum Looks like 7.0 was delayd again #18548 (comment), maybe there's still a chance for this to go in? |
@AlessandroPatti we're actually planning on getting the final RC out in a little bit, but we can try to include this. |
Remove special handling of cpu and memory, and instead track them as any other resource. This has a few advantages: - Significant code clean up, keep only the logic for generic resource around - Consistent resources type (double) for all resource Relates to bazelbuild#19679 Closes bazelbuild#19839. PiperOrigin-RevId: 585926931 Change-Id: Id0d6a14e9c151c3895f55d1808b6bd66eecf98b3
Remove special handling of cpu and memory, and instead track them as any other resource. This has a few advantages: - Significant code clean up, keep only the logic for generic resource around - Consistent resources type (double) for all resource Relates to #19679 Closes #19839. Commit ebe4d0d PiperOrigin-RevId: 585926931 Change-Id: Id0d6a14e9c151c3895f55d1808b6bd66eecf98b3 Co-authored-by: Alessandro Patti <ale812@yahoo.it>
The changes in this PR have been included in Bazel 7.0.0 RC5. Please test out the release candidate and report any issues as soon as possible. If you're using Bazelisk, you can point to the latest RC by setting USE_BAZEL_VERSION=last_rc. |
Follow up for #19839 (comment), introduce new flag that will replace all the others. Closes #20398. PiperOrigin-RevId: 596905096 Change-Id: Ic2c20dae40efa797953cde6934085f899acb9b52
Follow up for bazelbuild#19839 (comment), introduce new flag that will replace all the others. Closes bazelbuild#20398. PiperOrigin-RevId: 596905096 Change-Id: Ic2c20dae40efa797953cde6934085f899acb9b52
Follow up for #19839 (comment), introduce new flag that will replace all the others. Closes #20398. Commit ea75928 PiperOrigin-RevId: 596905096 Change-Id: Ic2c20dae40efa797953cde6934085f899acb9b52 Co-authored-by: Alessandro Patti <ale812@yahoo.it>
Remove special handling of cpu and memory, and instead track them as any other resource. This has a few advantages: - Significant code clean up, keep only the logic for generic resource around - Consistent resources type (double) for all resource Relates to bazelbuild#19679 Closes bazelbuild#19839. PiperOrigin-RevId: 585926931 Change-Id: Id0d6a14e9c151c3895f55d1808b6bd66eecf98b3
Follow up for bazelbuild#19839 (comment), introduce new flag that will replace all the others. Closes bazelbuild#20398. PiperOrigin-RevId: 596905096 Change-Id: Ic2c20dae40efa797953cde6934085f899acb9b52
Remove special handling of cpu and memory, and instead track them as any other resource. This has a few advantages: - Significant code clean up, keep only the logic for generic resource around - Consistent resources type (double) for all resource Relates to bazelbuild#19679 Closes bazelbuild#19839. PiperOrigin-RevId: 585926931 Change-Id: Id0d6a14e9c151c3895f55d1808b6bd66eecf98b3
Follow up for bazelbuild#19839 (comment), introduce new flag that will replace all the others. Closes bazelbuild#20398. PiperOrigin-RevId: 596905096 Change-Id: Ic2c20dae40efa797953cde6934085f899acb9b52
Remove special handling of cpu and memory, and instead track them as any other resource. This has a few advantages:
resources:memory:<n>
worksRelates to #19679