Skip to content

Commit

Permalink
Add flag experimental_throttle_remote_action_building
Browse files Browse the repository at this point in the history
to allow users temporarily disable remote action building throttle.

Workaround for #20478.

Closes #20558.

PiperOrigin-RevId: 597445193
Change-Id: Ib2c7133adf86139b35156d94e39cbf9e17906439
  • Loading branch information
coeuvre authored and keertk committed Jan 11, 2024
1 parent 8dd0998 commit 4dc51a6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -514,13 +514,29 @@ private ToolSignature getToolSignature(Spawn spawn, SpawnExecutionContext contex
: null;
}

private void maybeAcquireRemoteActionBuildingSemaphore(ProfilerTask task)
throws InterruptedException {
if (!remoteOptions.throttleRemoteActionBuilding) {
return;
}

try (var c = Profiler.instance().profile(task, "acquiring semaphore")) {
remoteActionBuildingSemaphore.acquire();
}
}

private void maybeReleaseRemoteActionBuildingSemaphore() {
if (!remoteOptions.throttleRemoteActionBuilding) {
return;
}

remoteActionBuildingSemaphore.release();
}

/** Creates a new {@link RemoteAction} instance from spawn. */
public RemoteAction buildRemoteAction(Spawn spawn, SpawnExecutionContext context)
throws IOException, ExecException, ForbiddenActionInputException, InterruptedException {
try (SilentCloseable c =
Profiler.instance().profile(ProfilerTask.REMOTE_SETUP, "acquiring semaphore")) {
remoteActionBuildingSemaphore.acquire();
}
maybeAcquireRemoteActionBuildingSemaphore(ProfilerTask.REMOTE_SETUP);
try {
ToolSignature toolSignature = getToolSignature(spawn, context);
final MerkleTree merkleTree = buildInputMerkleTree(spawn, context, toolSignature);
Expand Down Expand Up @@ -573,7 +589,7 @@ public RemoteAction buildRemoteAction(Spawn spawn, SpawnExecutionContext context
actionKey,
remoteOptions.remoteDiscardMerkleTrees);
} finally {
remoteActionBuildingSemaphore.release();
maybeReleaseRemoteActionBuildingSemaphore();
}
}

Expand Down Expand Up @@ -1463,10 +1479,7 @@ public void uploadInputsIfNotPresent(RemoteAction action, boolean force)
// concurrency. This prevents memory exhaustion. We assume that
// ensureInputsPresent() provides enough parallelism to saturate the
// network connection.
try (SilentCloseable c =
Profiler.instance().profile(ProfilerTask.UPLOAD_TIME, "acquiring semaphore")) {
remoteActionBuildingSemaphore.acquire();
}
maybeAcquireRemoteActionBuildingSemaphore(ProfilerTask.UPLOAD_TIME);
try {
MerkleTree merkleTree = action.getMerkleTree();
if (merkleTree == null) {
Expand All @@ -1486,7 +1499,7 @@ public void uploadInputsIfNotPresent(RemoteAction action, boolean force)
additionalInputs,
force);
} finally {
remoteActionBuildingSemaphore.release();
maybeReleaseRemoteActionBuildingSemaphore();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.devtools.common.options.Converter;
import com.google.devtools.common.options.Converters;
import com.google.devtools.common.options.Converters.AssignmentConverter;
import com.google.devtools.common.options.Converters.BooleanConverter;
import com.google.devtools.common.options.EnumConverter;
import com.google.devtools.common.options.Option;
import com.google.devtools.common.options.OptionDocumentationCategory;
Expand Down Expand Up @@ -732,6 +733,19 @@ public RemoteOutputsStrategyConverter() {
+ " seconds.")
public Duration remoteFailureWindowInterval;

@Option(
name = "experimental_throttle_remote_action_building",
defaultValue = "true",
converter = BooleanConverter.class,
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
metadataTags = OptionMetadataTag.EXPERIMENTAL,
effectTags = {OptionEffectTag.EXECUTION},
help =
"Whether to throttle the building of remote action to avoid OOM. Defaults to true.\n\n"
+ "This is a temporary flag to allow users switch off the behaviour. Once Bazel is"
+ " smart enough about the RAM/CPU usages, this flag will be removed.")
public boolean throttleRemoteActionBuilding;

// The below options are not configurable by users, only tests.
// This is part of the effort to reduce the overall number of flags.

Expand Down

0 comments on commit 4dc51a6

Please sign in to comment.