Allow users to set local RAM and CPU available to Blaze relative to host capacity.
Two new flags, --local_ram_resources and --local_cpu_resouces, which take a value or "HOST_{ram,cpus}" optionally followed by [-|*]<float>, will replace --ram_utilization_factor and --local_resouces in the future. Right now the flags exist in conjunction with each other, with --local_resources taking precedence, then --ram_utilization_factor, then --local_{ram,cpu}_resources.
RELNOTES:
Introduces --local_{ram,cpu}_resources, which will take the place of --local_resources.
PiperOrigin-RevId: 228523496
diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java b/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java
index e0aa91d..8247cbe 100644
--- a/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java
+++ b/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java
@@ -15,6 +15,7 @@
import static com.google.common.collect.ImmutableSet.toImmutableSet;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Predicate;
import com.google.common.base.Stopwatch;
import com.google.common.base.Suppliers;
@@ -614,16 +615,30 @@
prefetcher);
}
- private void configureResourceManager(BuildRequest request) {
+ @VisibleForTesting
+ public static void configureResourceManager(BuildRequest request) {
ResourceManager resourceMgr = ResourceManager.instance();
ExecutionOptions options = request.getOptions(ExecutionOptions.class);
ResourceSet resources;
if (options.availableResources != null) {
+ logger.warning(
+ "--local_resources will be deprecated. Please use --local_ram_resources "
+ + "and/or --local_cpu_resources.");
resources = options.availableResources;
resourceMgr.setRamUtilizationPercentage(100);
- } else {
- resources = LocalHostCapacity.getLocalHostCapacity();
+ } else if (options.ramUtilizationPercentage != 0) {
+ logger.warning(
+ "--ram_utilization_factor will soon be deprecated. Please use "
+ + "--local_ram_resources=HOST_RAM*<float>, where <float> is the percentage of "
+ + "available RAM you want to devote to Bazel.");
+ resources =
+ ResourceSet.createWithRamCpu(
+ LocalHostCapacity.getLocalHostCapacity().getMemoryMb(), options.localCpuResources);
resourceMgr.setRamUtilizationPercentage(options.ramUtilizationPercentage);
+ } else {
+ resources =
+ ResourceSet.createWithRamCpu(options.localRamResources, options.localCpuResources);
+ resourceMgr.setRamUtilizationPercentage(100);
}
resourceMgr.setUseLocalMemoryEstimate(options.localMemoryEstimate);