Skip to content

Commit

Permalink
Use a dedicated thread pool for disk cache garbage collection.
Browse files Browse the repository at this point in the history
The ExecutorService created in RemoteModule#beforeCommand is intended to have command scope, so it won't be available during idle periods. (The current state doesn't work, either, because we pass it into the DiskCacheGarbageCollectorIdleTask before initializing it. Oops.)

PiperOrigin-RevId: 679497012
Change-Id: I8e791580c2db078c6d39cb760936b8fbcba4ed3d
  • Loading branch information
tjgq authored and copybara-github committed Sep 27, 2024
1 parent 14777e0 commit d48e391
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,7 @@ public void beforeCommand(CommandEnvironment env) throws AbruptExitException {

if (enableDiskCache) {
var gcIdleTask =
DiskCacheGarbageCollectorIdleTask.create(
remoteOptions, env.getWorkingDirectory(), executorService);
DiskCacheGarbageCollectorIdleTask.create(remoteOptions, env.getWorkingDirectory());
if (gcIdleTask != null) {
env.addIdleTask(gcIdleTask);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.google.common.annotations.VisibleForTesting;
import com.google.common.flogger.GoogleLogger;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.google.devtools.build.lib.remote.disk.DiskCacheGarbageCollector.CollectionPolicy;
import com.google.devtools.build.lib.remote.disk.DiskCacheGarbageCollector.CollectionStats;
import com.google.devtools.build.lib.remote.options.RemoteOptions;
Expand All @@ -26,6 +27,7 @@
import java.time.Duration;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.annotation.Nullable;

/** An {@link IdleTask} to run a {@link DiskCacheGarbageCollector}. */
Expand All @@ -35,6 +37,10 @@ public final class DiskCacheGarbageCollectorIdleTask implements IdleTask {
private final Duration delay;
private final DiskCacheGarbageCollector gc;

private static final ExecutorService executorService =
Executors.newCachedThreadPool(
new ThreadFactoryBuilder().setNameFormat("disk-cache-gc-%d").build());

private DiskCacheGarbageCollectorIdleTask(Duration delay, DiskCacheGarbageCollector gc) {
this.delay = delay;
this.gc = gc;
Expand All @@ -50,7 +56,7 @@ private DiskCacheGarbageCollectorIdleTask(Duration delay, DiskCacheGarbageCollec
*/
@Nullable
public static DiskCacheGarbageCollectorIdleTask create(
RemoteOptions remoteOptions, Path workingDirectory, ExecutorService executorService) {
RemoteOptions remoteOptions, Path workingDirectory) {
if (remoteOptions.diskCache == null || remoteOptions.diskCache.isEmpty()) {
return null;
}
Expand Down

0 comments on commit d48e391

Please sign in to comment.