Skip to content

Commit

Permalink
Only create a single per-build instance of the remote cache / executor
Browse files Browse the repository at this point in the history
Fixes #3189.
Fixes #2823.

PiperOrigin-RevId: 159699146
  • Loading branch information
ulfjack authored and hlopko committed Jun 22, 2017
1 parent 3546bf6 commit 4356c44
Showing 1 changed file with 27 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ final class RemoteSpawnStrategy implements SpawnActionContext {
private final ChannelOptions channelOptions;
private final SpawnInputExpander spawnInputExpander = new SpawnInputExpander(/*strict=*/ false);

private final RemoteActionCache remoteCache;
private final GrpcRemoteExecutor workExecutor;

RemoteSpawnStrategy(
Map<String, String> clientEnv,
Path execRoot,
Expand All @@ -101,6 +104,30 @@ final class RemoteSpawnStrategy implements SpawnActionContext {
} else {
platform = null;
}
// Initialize remote cache and execution handlers. We use separate handlers for every
// action to enable server-side parallelism (need a different gRPC channel per action).
if (SimpleBlobStoreFactory.isRemoteCacheOptions(remoteOptions)) {
remoteCache = new SimpleBlobStoreActionCache(SimpleBlobStoreFactory.create(remoteOptions));
} else if (GrpcActionCache.isRemoteCacheOptions(remoteOptions)) {
remoteCache =
new GrpcActionCache(
RemoteUtils.createChannel(remoteOptions.remoteCache, channelOptions),
channelOptions,
remoteOptions);
} else {
remoteCache = null;
}
// Otherwise remoteCache remains null and remote caching/execution are disabled.

if (remoteCache != null && GrpcRemoteExecutor.isRemoteExecutionOptions(remoteOptions)) {
workExecutor =
new GrpcRemoteExecutor(
RemoteUtils.createChannel(remoteOptions.remoteExecutor, channelOptions),
channelOptions,
remoteOptions);
} else {
workExecutor = null;
}
}

private Action buildAction(
Expand Down Expand Up @@ -228,30 +255,6 @@ public void exec(Spawn spawn, ActionExecutionContext actionExecutionContext)
Executor executor = actionExecutionContext.getExecutor();
EventHandler eventHandler = executor.getEventHandler();

RemoteActionCache remoteCache = null;
GrpcRemoteExecutor workExecutor = null;
if (spawn.isRemotable()) {
// Initialize remote cache and execution handlers. We use separate handlers for every
// action to enable server-side parallelism (need a different gRPC channel per action).
if (SimpleBlobStoreFactory.isRemoteCacheOptions(remoteOptions)) {
remoteCache = new SimpleBlobStoreActionCache(SimpleBlobStoreFactory.create(remoteOptions));
} else if (GrpcActionCache.isRemoteCacheOptions(remoteOptions)) {
remoteCache =
new GrpcActionCache(
RemoteUtils.createChannel(remoteOptions.remoteCache, channelOptions),
channelOptions,
remoteOptions);
}
// Otherwise remoteCache remains null and remote caching/execution are disabled.

if (remoteCache != null && GrpcRemoteExecutor.isRemoteExecutionOptions(remoteOptions)) {
workExecutor =
new GrpcRemoteExecutor(
RemoteUtils.createChannel(remoteOptions.remoteExecutor, channelOptions),
channelOptions,
remoteOptions);
}
}
if (!spawn.isRemotable() || remoteCache == null) {
standaloneStrategy.exec(spawn, actionExecutionContext);
return;
Expand Down

0 comments on commit 4356c44

Please sign in to comment.