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

[6.5.0] Add flag experimental_throttle_remote_action_building #20861

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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