[jps-cache] Use ProcessIOExecutorService for top level tasks

GitOrigin-RevId: 15fb60eb94fd2aaaa67bbf249c37b8567255d083
This commit is contained in:
Mikhail Mazurkevich
2019-12-04 08:04:11 +00:00
committed by intellij-monorepo-bot
parent 2d8140195f
commit 6f4b9e4b92
5 changed files with 27 additions and 33 deletions
@@ -14,7 +14,6 @@ import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.ExecutorService;
class JpsCacheLoader implements JpsOutputLoader<File> {
private static final Logger LOG = Logger.getInstance("com.intellij.jps.loader.JpsCacheLoader");
@@ -45,8 +44,7 @@ class JpsCacheLoader implements JpsOutputLoader<File> {
}
@Override
public LoaderStatus extract(@Nullable Object loadResults, @NotNull ExecutorService executorService,
@NotNull SegmentedProgressIndicatorManager extractIndicatorManager) {
public LoaderStatus extract(@Nullable Object loadResults, @NotNull SegmentedProgressIndicatorManager extractIndicatorManager) {
if (!(loadResults instanceof File)) return LoaderStatus.FAILED;
File zipFile = (File) loadResults;
@@ -86,7 +84,7 @@ class JpsCacheLoader implements JpsOutputLoader<File> {
}
@Override
public void apply(@NotNull ExecutorService executorService, @NotNull SegmentedProgressIndicatorManager indicatorManager) {
public void apply(@NotNull SegmentedProgressIndicatorManager indicatorManager) {
if (myTmpCacheFolder == null) {
LOG.warn("Nothing to apply, download results are empty");
return;
@@ -38,15 +38,15 @@ class JpsCompilationOutputLoader implements JpsOutputLoader<List<OutputLoadResul
private static final String PRODUCTION = "production";
private static final String TEST = "test";
private final JpsServerClient myClient;
private final Project myProject;
private final String myProjectPath;
private List<File> myOldModulesPaths;
private final ExecutorService myExecutorService;
private Map<File, String> myTmpFolderToModuleName;
JpsCompilationOutputLoader(JpsServerClient client, Project project) {
JpsCompilationOutputLoader(@NotNull JpsServerClient client, Project project, @NotNull ExecutorService executorService) {
myClient = client;
myProject = project;
myProjectPath = myProject.getBasePath();
myExecutorService = executorService;
myProjectPath = project.getBasePath();
}
@Override
@@ -77,8 +77,7 @@ class JpsCompilationOutputLoader implements JpsOutputLoader<List<OutputLoadResul
}
@Override
public LoaderStatus extract(@Nullable Object loadResults, @NotNull ExecutorService executorService,
@NotNull SegmentedProgressIndicatorManager extractIndicatorManager) {
public LoaderStatus extract(@Nullable Object loadResults, @NotNull SegmentedProgressIndicatorManager extractIndicatorManager) {
if (!(loadResults instanceof List)) return LoaderStatus.FAILED;
//noinspection unchecked
@@ -89,7 +88,7 @@ class JpsCompilationOutputLoader implements JpsOutputLoader<List<OutputLoadResul
long start = System.currentTimeMillis();
extractIndicatorManager.setText(this, "Extracting downloaded results...");
List<Future<?>> futureList = ContainerUtil.map(outputLoadResults, loadResult ->
executorService.submit(new UnzipOutputTask(result, loadResult, extractIndicatorManager)));
myExecutorService.submit(new UnzipOutputTask(result, loadResult, extractIndicatorManager)));
for (Future future : futureList) {
future.get();
}
@@ -116,7 +115,7 @@ class JpsCompilationOutputLoader implements JpsOutputLoader<List<OutputLoadResul
}
@Override
public void apply(@NotNull ExecutorService executorService, @NotNull SegmentedProgressIndicatorManager indicatorManager) {
public void apply(@NotNull SegmentedProgressIndicatorManager indicatorManager) {
long start = System.currentTimeMillis();
if (myOldModulesPaths != null) {
LOG.info("Removing old compilation outputs " + myOldModulesPaths.size() + " counts");
@@ -131,7 +130,7 @@ class JpsCompilationOutputLoader implements JpsOutputLoader<List<OutputLoadResul
indicatorManager.setText(this, "Applying changes...");
ContainerUtil.map(myTmpFolderToModuleName.entrySet(),
entry -> executorService.submit(() -> {
entry -> myExecutorService.submit(() -> {
String moduleName = entry.getValue();
File tmpModuleFolder = entry.getKey();
SegmentedProgressIndicatorManager.SubTaskProgressIndicator subTaskIndicator =
@@ -7,13 +7,12 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
import java.util.concurrent.ExecutorService;
interface JpsOutputLoader<T> {
T load(@NotNull JpsLoaderContext context);
LoaderStatus extract(@Nullable Object loadResults, @NotNull ExecutorService executorService, @NotNull SegmentedProgressIndicatorManager extractIndicatorManager);
LoaderStatus extract(@Nullable Object loadResults, @NotNull SegmentedProgressIndicatorManager extractIndicatorManager);
void rollback();
void apply(@NotNull ExecutorService executorService, @NotNull SegmentedProgressIndicatorManager indicatorManager);
void apply(@NotNull SegmentedProgressIndicatorManager indicatorManager);
default int calculateDownloads(@NotNull Map<String, Map<String, BuildTargetState>> commitSourcesState,
@Nullable Map<String, Map<String, BuildTargetState>> currentSourcesState) {
return 1;
@@ -2,7 +2,6 @@ package com.intellij.jps.cache.loader;
import com.intellij.compiler.CompilerWorkspaceConfiguration;
import com.intellij.compiler.server.BuildManager;
import com.intellij.execution.process.ProcessIOExecutorService;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.jps.cache.client.JpsServerClient;
import com.intellij.jps.cache.git.GitRepositoryUtil;
@@ -29,13 +28,13 @@ import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicBoolean;
import static com.intellij.execution.process.ProcessIOExecutorService.INSTANCE;
import static com.intellij.jps.cache.ui.JpsLoaderNotifications.NONE_NOTIFICATION_GROUP;
import static com.intellij.jps.cache.ui.JpsLoaderNotifications.STICKY_NOTIFICATION_GROUP;
@@ -45,7 +44,7 @@ public class JpsOutputLoaderManager {
private static final String PROGRESS_TITLE = "Updating Compiler Caches";
private static final double SEGMENT_SIZE = 0.33;
private final AtomicBoolean hasRunningTask;
private final ExecutorService ourThreadPool;
private final ExecutorService myExecutorService;
private final CompilerWorkspaceConfiguration myWorkspaceConfiguration;
private List<JpsOutputLoader<?>> myJpsOutputLoadersLoaders;
private final JpsMetadataLoader myMetadataLoader;
@@ -66,9 +65,9 @@ public class JpsOutputLoaderManager {
// Configure build manager
BuildManager buildManager = BuildManager.getInstance();
if (!buildManager.isGeneratePortableCachesEnabled()) buildManager.setGeneratePortableCachesEnabled(true);
ourThreadPool = AppExecutorUtil.createBoundedApplicationPoolExecutor("JpsCacheLoader Pool",
ProcessIOExecutorService.INSTANCE,
getThreadPoolSize());
myExecutorService = AppExecutorUtil.createBoundedApplicationPoolExecutor("JpsCacheLoader Pool",
INSTANCE,
getThreadPoolSize());
}
public void load(boolean isForceUpdate) {
@@ -92,7 +91,7 @@ public class JpsOutputLoaderManager {
}
public void notifyAboutNearestCache() {
ourThreadPool.execute(() -> {
INSTANCE.execute(() -> {
Pair<String, Integer> commitInfo = getNearestCommit(false);
if (commitInfo == null) return;
@@ -208,10 +207,7 @@ public class JpsOutputLoaderManager {
// Start loaders with own context
List<CompletableFuture<LoaderStatus>> completableFutures = ContainerUtil.map(loaders, loader ->
CompletableFuture.supplyAsync(() -> {
Object loadResults = loader.load(loaderContext);
return loader.extract(loadResults, ourThreadPool, extractIndicatorManager);
}, ourThreadPool));
CompletableFuture.supplyAsync(() -> loader.extract(loader.load(loaderContext), extractIndicatorManager), INSTANCE));
// Reduce loaders statuses into the one
CompletableFuture<LoaderStatus> initialFuture = completableFutures.get(0);
@@ -223,13 +219,13 @@ public class JpsOutputLoaderManager {
return initialFuture;
}
private CompletableFuture<Void> applyChanges(LoaderStatus loaderStatus, JpsOutputLoader loader, ProgressIndicator indicator,
SegmentedProgressIndicatorManager indicatorManager) {
private static CompletableFuture<Void> applyChanges(LoaderStatus loaderStatus, JpsOutputLoader<?> loader, ProgressIndicator indicator,
SegmentedProgressIndicatorManager indicatorManager) {
if (loaderStatus == LoaderStatus.FAILED) {
indicator.setText("Rolling back");
return CompletableFuture.runAsync(() -> loader.rollback(), ourThreadPool);
return CompletableFuture.runAsync(() -> loader.rollback(), INSTANCE);
}
return CompletableFuture.runAsync(() -> loader.apply(ourThreadPool, indicatorManager), ourThreadPool);
return CompletableFuture.runAsync(() -> loader.apply(indicatorManager), INSTANCE);
}
private void saveStateAndNotify(LoaderStatus loaderStatus, String commitId, long startTime) {
@@ -268,7 +264,7 @@ public class JpsOutputLoaderManager {
private List<JpsOutputLoader<?>> getLoaders(@NotNull Project project) {
if (myJpsOutputLoadersLoaders != null) return myJpsOutputLoadersLoaders;
myJpsOutputLoadersLoaders = Arrays.asList(new JpsCompilationOutputLoader(myServerClient, project),
myJpsOutputLoadersLoaders = Arrays.asList(new JpsCompilationOutputLoader(myServerClient, project, myExecutorService),
new JpsCacheLoader(myServerClient, project));
return myJpsOutputLoadersLoaders;
}
@@ -8,6 +8,7 @@ import com.intellij.jps.cache.model.AffectedModule;
import com.intellij.jps.cache.model.BuildTargetState;
import com.intellij.openapi.application.PluginPathManager;
import com.intellij.testFramework.fixtures.BasePlatformTestCase;
import com.intellij.util.ConcurrencyUtil;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
@@ -29,7 +30,8 @@ public class JpsCompilationOutputLoaderTest extends BasePlatformTestCase {
@Override
public void setUp() throws Exception {
super.setUp();
compilationOutputLoader = new JpsCompilationOutputLoader(JpsServerClient.getServerClient(), getProject());
compilationOutputLoader = new JpsCompilationOutputLoader(JpsServerClient.getServerClient(), getProject(),
ConcurrencyUtil.newSingleThreadExecutor("JpsCompilationOutputLoaderTest"));
myGson = new Gson();
myTokenType = new TypeToken<Map<String, Map<String, BuildTargetState>>>() {}.getType();
}