Skip to content

Commit b2cd7af

Browse files
AlessandroPatticopybara-github
authored andcommitted
Remove deprecated local resource flags
Follow up for #20398, kill deprecated flags. Closes #21684. PiperOrigin-RevId: 823202836 Change-Id: Ife47d09de29139f3f95dd3817de551b41ac0920b
1 parent 664e87b commit b2cd7af

File tree

7 files changed

+25
-95
lines changed

7 files changed

+25
-95
lines changed

site/en/docs/user-manual.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ by Bazel's scheduler, which tries to avoid running concurrent jobs
745745
that will use up more resources (RAM or CPU) than are available,
746746
based on some (very crude) estimates of the resource consumption
747747
of each job. The behavior of the scheduler can be controlled by
748-
the `--local_ram_resources` option.
748+
the `--local_resources` option.
749749

750750
#### `--progress_report_interval={{ "<var>" }}n{{ "</var>" }}` {:progress-report-interval}
751751

@@ -761,13 +761,13 @@ that progress is reported once every minute.
761761
When bazel is using cursor control, as specified by
762762
[`--curses`](#curses), progress is reported every second.
763763

764-
#### `--local_{ram,cpu}_resources {{ "<var>" }}resources or resource expression{{ "</var>" }}` {:#local-resources}
764+
#### `--local_resources {{ "<var>" }}resources or resource expression{{ "</var>" }}` {:#local-resources}
765765

766766
These options specify the amount of local resources (RAM in MB and number of CPU logical cores)
767767
that Bazel can take into consideration when scheduling build and test activities to run locally. They take
768-
an integer, or a keyword (HOST_RAM or HOST_CPUS) optionally followed by `[-|*`float`]`
769-
(for example, `--local_cpu_resources=2`, `--local_ram_resources=HOST_RAM*.5`,
770-
`--local_cpu_resources=HOST_CPUS-1`).
768+
an float, or a keyword (HOST_RAM or HOST_CPUS) optionally followed by `[-|*`float`]`
769+
(for example, `--local_resources=cpu=2`, `--local_resources=memory=HOST_RAM*.5`,
770+
`--local_resources=cpu=HOST_CPUS-1`).
771771
The flags are independent; one or both may be set. By default, Bazel estimates
772772
the amount of RAM and number of CPU cores directly from the local system's configuration.
773773

site/en/remote/dynamic.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ management option. It takes a value from 0 to 1, 0 turning off this feature.
139139
When set to a value above 0, Bazel adjusts the number of
140140
locally scheduled actions when many actions waiting to
141141
be scheduled. Setting it to 1 allows as many actions to be scheduled as there
142-
are CPUs available (as per `--local_cpu_resources`). Lower values set the number
142+
are CPUs available (as per `--local_resources`). Lower values set the number
143143
of actions scheduled to correspondingly fewer as higher numbers of actions are
144144
available to run. This may sound counter-intuitive, but with a good remote
145145
system, local execution does not help much when many actions are being run, and

src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import com.google.common.collect.ImmutableSet;
2525
import com.google.common.collect.Iterables;
2626
import com.google.common.collect.Sets;
27-
import com.google.common.collect.Streams;
2827
import com.google.common.eventbus.Subscribe;
2928
import com.google.common.flogger.GoogleLogger;
3029
import com.google.devtools.build.lib.actions.Action;
@@ -111,7 +110,6 @@
111110
import java.nio.charset.StandardCharsets;
112111
import java.time.Duration;
113112
import java.util.Collection;
114-
import java.util.Map;
115113
import java.util.Objects;
116114
import java.util.Set;
117115
import java.util.UUID;
@@ -947,26 +945,10 @@ private Builder createBuilder(
947945
@VisibleForTesting
948946
public static void configureResourceManager(ResourceManager resourceMgr, BuildRequest request) {
949947
ExecutionOptions options = request.getOptions(ExecutionOptions.class);
950-
ImmutableMap<String, Double> cpuRam =
951-
ImmutableMap.of(
952-
ResourceSet.CPU,
953-
// Replace with 1.0 * ResourceConverter.HOST_CPUS.get() after flag deprecation
954-
options.localCpuResources,
955-
ResourceSet.MEMORY,
956-
// Replace with 0.67 * ResourceConverter.HOST_RAM.get() after flag deprecation
957-
options.localRamResources);
958-
ImmutableMap<String, Double> resources =
959-
Streams.concat(
960-
options.localExtraResources.stream(),
961-
cpuRam.entrySet().stream(),
962-
options.localResources.stream())
963-
.collect(
964-
ImmutableMap.toImmutableMap(
965-
Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v2));
966-
967948
resourceMgr.setAvailableResources(
968949
ResourceSet.create(
969-
resources, options.usingLocalTestJobs() ? options.localTestJobs : Integer.MAX_VALUE));
950+
options.getLocalResources(),
951+
options.usingLocalTestJobs() ? options.localTestJobs : Integer.MAX_VALUE));
970952

971953
resourceMgr.initializeCpuLoadFunctionality(
972954
MachineLoadProvider.instance(),

src/main/java/com/google/devtools/build/lib/dynamic/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ java_library(
1919
"//src/main/java/com/google/devtools/build/lib:runtime",
2020
"//src/main/java/com/google/devtools/build/lib/actions",
2121
"//src/main/java/com/google/devtools/build/lib/actions:artifacts",
22+
"//src/main/java/com/google/devtools/build/lib/actions:localhost_capacity",
2223
"//src/main/java/com/google/devtools/build/lib/concurrent",
2324
"//src/main/java/com/google/devtools/build/lib/concurrent:thread_safety",
2425
"//src/main/java/com/google/devtools/build/lib/events",

src/main/java/com/google/devtools/build/lib/dynamic/DynamicExecutionModule.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.google.common.flogger.GoogleLogger;
2222
import com.google.common.util.concurrent.ThreadFactoryBuilder;
2323
import com.google.devtools.build.lib.actions.ActionExecutionContext;
24+
import com.google.devtools.build.lib.actions.ResourceSet;
2425
import com.google.devtools.build.lib.actions.Spawn;
2526
import com.google.devtools.build.lib.actions.SpawnStrategy;
2627
import com.google.devtools.build.lib.actions.Spawns;
@@ -151,7 +152,7 @@ public void registerSpawnStrategies(
151152
registerSpawnStrategies(
152153
registryBuilder,
153154
options,
154-
(int) execOptions.localCpuResources,
155+
execOptions.getLocalResources().get(ResourceSet.CPU).intValue(),
155156
env.getOptions().getOptions(BuildRequestOptions.class).jobs);
156157
}
157158

src/main/java/com/google/devtools/build/lib/exec/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ java_library(
9191
deps = [
9292
":regex_filter_assignment_converter",
9393
"//src/main/java/com/google/devtools/build/lib/actions",
94+
"//src/main/java/com/google/devtools/build/lib/actions:localhost_capacity",
9495
"//src/main/java/com/google/devtools/build/lib/analysis/config:per_label_options",
9596
"//src/main/java/com/google/devtools/build/lib/util",
9697
"//src/main/java/com/google/devtools/build/lib/util:cpu_resource_converter",

src/main/java/com/google/devtools/build/lib/exec/ExecutionOptions.java

Lines changed: 13 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
1313
// limitations under the License.
1414
package com.google.devtools.build.lib.exec;
1515

16+
import com.google.common.collect.ImmutableMap;
1617
import com.google.common.collect.Iterables;
1718
import com.google.devtools.build.lib.actions.ActionExecutionContext;
1819
import com.google.devtools.build.lib.actions.ActionExecutionContext.ShowSubcommands;
20+
import com.google.devtools.build.lib.actions.LocalHostCapacity;
21+
import com.google.devtools.build.lib.actions.ResourceSet;
1922
import com.google.devtools.build.lib.analysis.config.PerLabelOptions;
20-
import com.google.devtools.build.lib.util.CpuResourceConverter;
2123
import com.google.devtools.build.lib.util.OptionsUtils;
22-
import com.google.devtools.build.lib.util.RamResourceConverter;
2324
import com.google.devtools.build.lib.util.RegexFilter;
2425
import com.google.devtools.build.lib.util.ResourceConverter;
2526
import com.google.devtools.build.lib.vfs.PathFragment;
@@ -288,70 +289,6 @@ public boolean shouldMaterializeParamFiles() {
288289
+ " summary.")
289290
public TestSummaryFormat testSummary;
290291

291-
@Option(
292-
name = "local_cpu_resources",
293-
defaultValue = ResourceConverter.HOST_CPUS_KEYWORD,
294-
deprecationWarning =
295-
"--local_cpu_resources is deprecated, please use --local_resources=cpu= instead.",
296-
documentationCategory = OptionDocumentationCategory.BUILD_TIME_OPTIMIZATION,
297-
effectTags = {OptionEffectTag.HOST_MACHINE_RESOURCE_OPTIMIZATIONS},
298-
help =
299-
"Explicitly set the total number of local CPU cores available to Bazel to spend on build"
300-
+ " actions executed locally. Takes an integer, or \""
301-
+ ResourceConverter.HOST_CPUS_KEYWORD
302-
+ "\", optionally followed"
303-
+ " by [-|*]<float> (eg. "
304-
+ ResourceConverter.HOST_CPUS_KEYWORD
305-
+ "*.5"
306-
+ " to use half the available CPU cores). By default, (\""
307-
+ ResourceConverter.HOST_CPUS_KEYWORD
308-
+ "\"), Bazel will query system"
309-
+ " configuration to estimate the number of CPU cores available.",
310-
converter = CpuResourceConverter.class)
311-
public double localCpuResources;
312-
313-
@Option(
314-
name = "local_ram_resources",
315-
defaultValue = ResourceConverter.HOST_RAM_KEYWORD + "*.67",
316-
deprecationWarning =
317-
"--local_ram_resources is deprecated, please use --local_resources=memory= instead.",
318-
documentationCategory = OptionDocumentationCategory.BUILD_TIME_OPTIMIZATION,
319-
effectTags = {OptionEffectTag.HOST_MACHINE_RESOURCE_OPTIMIZATIONS},
320-
help =
321-
"Explicitly set the total amount of local host RAM (in MB) available to Bazel to spend on"
322-
+ " build actions executed locally. Takes an integer, or \""
323-
+ ResourceConverter.HOST_RAM_KEYWORD
324-
+ "\", optionally followed by [-|*]<float>"
325-
+ " (eg. "
326-
+ ResourceConverter.HOST_RAM_KEYWORD
327-
+ "*.5 to use half the available"
328-
+ " RAM). By default, (\""
329-
+ ResourceConverter.HOST_RAM_KEYWORD
330-
+ "*.67\"),"
331-
+ " Bazel will query system configuration to estimate the amount of RAM available"
332-
+ " and will use 67% of it.",
333-
converter = RamResourceConverter.class)
334-
public double localRamResources;
335-
336-
@Option(
337-
name = "local_extra_resources",
338-
defaultValue = "null",
339-
deprecationWarning =
340-
"--local_extra_resources is deprecated, please use --local_resources instead.",
341-
documentationCategory = OptionDocumentationCategory.BUILD_TIME_OPTIMIZATION,
342-
effectTags = {OptionEffectTag.HOST_MACHINE_RESOURCE_OPTIMIZATIONS},
343-
allowMultiple = true,
344-
help =
345-
"Set the number of extra resources available to Bazel. "
346-
+ "Takes in a string-float pair. Can be used multiple times to specify multiple "
347-
+ "types of extra resources. Bazel will limit concurrently running actions "
348-
+ "based on the available extra resources and the extra resources required. "
349-
+ "Tests can declare the amount of extra resources they need "
350-
+ "by using a tag of the \"resources:<resoucename>:<amount>\" format. "
351-
+ "Available CPU, RAM and resources cannot be set with this flag.",
352-
converter = Converters.StringToDoubleAssignmentConverter.class)
353-
public List<Map.Entry<String, Double>> localExtraResources;
354-
355292
@Option(
356293
name = "local_resources",
357294
defaultValue = "null",
@@ -372,11 +309,19 @@ public boolean shouldMaterializeParamFiles() {
372309
+ "types of resources. Bazel will limit concurrently running actions "
373310
+ "based on the available resources and the resources required. "
374311
+ "Tests can declare the amount of resources they need "
375-
+ "by using a tag of the \"resources:<resource name>:<amount>\" format. "
376-
+ "Overrides resources specified by --local_{cpu|ram|extra}_resources.",
312+
+ "by using a tag of the \"resources:<resource name>:<amount>\" format. ",
377313
converter = ResourceConverter.AssignmentConverter.class)
378314
public List<Map.Entry<String, Double>> localResources;
379315

316+
public ImmutableMap<String, Double> getLocalResources() {
317+
ImmutableMap.Builder<String, Double> resources = ImmutableMap.builder();
318+
return resources
319+
.put(ResourceSet.CPU, LocalHostCapacity.getLocalHostCapacity().getCpuUsage())
320+
.put(ResourceSet.MEMORY, .67 * LocalHostCapacity.getLocalHostCapacity().getMemoryMb())
321+
.putAll(localResources)
322+
.buildKeepingLast();
323+
}
324+
380325
@Option(
381326
name = "experimental_cpu_load_scheduling",
382327
defaultValue = "false",

0 commit comments

Comments
 (0)