Skip to content

Commit

Permalink
Use a global bounded threadpool when using persistent workers
Browse files Browse the repository at this point in the history
Using one per worker request causes the OS to run out of threads see upstream bug
  • Loading branch information
sfc-gh-mgalindo committed Jun 24, 2024
1 parent 86e3129 commit 3dd547a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 8 additions & 4 deletions aspect/tools/src/com/google/idea/blaze/aspect/PackageParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -113,8 +114,9 @@ private static void runPersistentWorker(PackageParser parser) throws IOException
}

public static void main(String[] args) throws Exception {
ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
PackageParserOptions options = parseArgs(args);
PackageParser parser = new PackageParser(PackageParserIoProvider.INSTANCE);
PackageParser parser = new PackageParser(PackageParserIoProvider.INSTANCE, executorService);

try {
if (isWorkerMode(args)) {
Expand Down Expand Up @@ -150,9 +152,12 @@ private static String[] parseParamFileIfUsed(String[] args) {

private final PackageParserIoProvider ioProvider;

private final ExecutorService executorService;

@VisibleForTesting
PackageParser(PackageParserIoProvider ioProvider) {
PackageParser(PackageParserIoProvider ioProvider, ExecutorService executorService) {
this.ioProvider = ioProvider;
this.executorService = executorService;
}

@VisibleForTesting
Expand Down Expand Up @@ -180,8 +185,7 @@ Map<ArtifactLocation, String> parsePackageStrings(List<ArtifactLocation> sources
throws Exception {

ListeningExecutorService executorService =
MoreExecutors.listeningDecorator(
Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()));
MoreExecutors.listeningDecorator(this.executorService);

Map<ArtifactLocation, ListenableFuture<String>> futures = Maps.newHashMap();
for (final ArtifactLocation source : sources) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -107,13 +109,15 @@ public void writeProto(MessageLite message, Path file) throws IOException {
.setIsSource(false)
.build();

private ExecutorService executorService;
private MockPackageParserIoProvider mockIoProvider;
private PackageParser parser;

@Before
public void setUp() {
executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
mockIoProvider = new MockPackageParserIoProvider();
parser = new PackageParser(mockIoProvider);
parser = new PackageParser(mockIoProvider, executorService);
}

private Map<ArtifactLocation, String> parsePackageStrings() throws Exception {
Expand Down

0 comments on commit 3dd547a

Please sign in to comment.