Skip to content

Commit

Permalink
Try out limited fixed thread pool
Browse files Browse the repository at this point in the history
nbauernfeind committed Jan 29, 2024
1 parent e16865b commit a9c3e62
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -39,14 +39,14 @@
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class QueryCompiler {
/** A flag to externally disable parallel compilation. */
public static volatile int PARALLELISM_FACTOR = ForkJoinPool.getCommonPoolParallelism();
public static volatile int REQUESTS_PER_TASK = 0;
public static volatile boolean DISABLE_SHARED_COMPILER = false;
private static final ExecutorService COMPILER_EXECUTOR = Executors.newFixedThreadPool(4);

private static final Logger log = LoggerFactory.getLogger(QueryCompiler.class);
/**
@@ -848,16 +848,22 @@ private void maybeCreateClass(
0, requests.length);
} else {
int numTasks = (requests.length + requestsPerTask - 1) / requestsPerTask;
ForkJoinTask<?>[] tasks = new ForkJoinTask[numTasks];
final Future<?>[] tasks = new Future[numTasks];
for (int jobId = 0; jobId < numTasks; ++jobId) {
final int startInclusive = jobId * requestsPerTask;
final int endExclusive = Math.min(requests.length, (jobId + 1) * requestsPerTask);
tasks[jobId] = ForkJoinPool.commonPool().submit(() -> {
tasks[jobId] = COMPILER_EXECUTOR.submit(() -> {
maybeCreateClassHelper(compiler, fileManager, requests, rootPathAsString, tempDirAsString,
startInclusive, endExclusive);
});
}
Arrays.stream(tasks).forEach(ForkJoinTask::join);
for (int jobId = 0; jobId < numTasks; ++jobId) {
try {
tasks[jobId].get();
} catch (Exception err) {
throw new UncheckedDeephavenException("Exception waiting for compilation task", err);
}
}
}
log.error().append("Compiled in ").append(Double.toString((System.nanoTime() - startTm) / 1e9)).append("s.").endl();
} catch (final Throwable t) {

0 comments on commit a9c3e62

Please sign in to comment.