forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding --experimental_skyframe_cpu_heavy_skykeys_thread_pool_size to …
…blaze. This flag allows the loading/analysis phase of Skyframe to use 2 independent thread pools: - 1 larger one for IO-bound tasks, and - 1 smaller one (size ~= numCores) for CPU-bound tasks This is currently not applied to the execution phase, since ActionExecutionFunction is both IO and CPU bound. PiperOrigin-RevId: 371763857
- Loading branch information
1 parent
e5a170f
commit 16c0408
Showing
28 changed files
with
646 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
src/main/java/com/google/devtools/build/lib/concurrent/DualExecutorQueueVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Copyright 2021 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
package com.google.devtools.build.lib.concurrent; | ||
|
||
import static java.util.concurrent.TimeUnit.SECONDS; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import com.google.common.base.Preconditions; | ||
import com.google.common.base.Throwables; | ||
import java.util.concurrent.ExecutorService; | ||
|
||
/** | ||
* An implementation of MultiThreadPoolsQuiescingExecutor that has 2 ExecutorServices, one with a | ||
* larger thread pool for IO/Network-bound tasks, and one with a smaller thread pool for CPU-bound | ||
* tasks. | ||
*/ | ||
public class DualExecutorQueueVisitor extends AbstractQueueVisitor | ||
implements MultiThreadPoolsQuiescingExecutor { | ||
private final ExecutorService regularPoolExecutorService; | ||
private final ExecutorService cpuHeavyPoolExecutorService; | ||
|
||
private DualExecutorQueueVisitor( | ||
ExecutorService regularPoolExecutorService, | ||
ExecutorService cpuHeavyPoolExecutorService, | ||
boolean shutdownOnCompletion, | ||
boolean failFastOnException, | ||
ErrorClassifier errorClassifier, | ||
boolean usingPriorityQueue) { | ||
super( | ||
regularPoolExecutorService, | ||
shutdownOnCompletion, | ||
failFastOnException, | ||
errorClassifier, | ||
usingPriorityQueue); | ||
this.regularPoolExecutorService = super.getExecutorService(); | ||
this.cpuHeavyPoolExecutorService = Preconditions.checkNotNull(cpuHeavyPoolExecutorService); | ||
} | ||
|
||
public static AbstractQueueVisitor createWithExecutorServices( | ||
ExecutorService executorService, | ||
ExecutorService cpuExecutorService, | ||
boolean failFastOnException, | ||
ErrorClassifier errorClassifier) { | ||
return new DualExecutorQueueVisitor( | ||
executorService, | ||
cpuExecutorService, | ||
/*shutdownOnCompletion=*/ true, | ||
failFastOnException, | ||
errorClassifier, | ||
/*usingPriorityQueue=*/ false); | ||
} | ||
|
||
@Override | ||
public final void execute(Runnable runnable, ThreadPoolType threadPoolType) { | ||
super.executeWithExecutorService(runnable, getExecutorServiceByThreadPoolType(threadPoolType)); | ||
} | ||
|
||
@VisibleForTesting | ||
ExecutorService getExecutorServiceByThreadPoolType(ThreadPoolType threadPoolType) { | ||
switch (threadPoolType) { | ||
case REGULAR: | ||
return regularPoolExecutorService; | ||
case CPU_HEAVY: | ||
return cpuHeavyPoolExecutorService; | ||
} | ||
throw new IllegalStateException("Invalid ThreadPoolType: " + threadPoolType); | ||
} | ||
|
||
@Override | ||
protected void shutdownExecutorService(Throwable catastrophe) { | ||
if (catastrophe != null) { | ||
Throwables.throwIfUnchecked(catastrophe); | ||
} | ||
internalShutdownExecutorService(regularPoolExecutorService); | ||
internalShutdownExecutorService(cpuHeavyPoolExecutorService); | ||
} | ||
|
||
private void internalShutdownExecutorService(ExecutorService executorService) { | ||
executorService.shutdown(); | ||
while (true) { | ||
try { | ||
executorService.awaitTermination(Integer.MAX_VALUE, SECONDS); | ||
break; | ||
} catch (InterruptedException e) { | ||
setInterrupted(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...main/java/com/google/devtools/build/lib/concurrent/MultiThreadPoolsQuiescingExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2021 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
package com.google.devtools.build.lib.concurrent; | ||
|
||
/** An Executor that can execute tasks in multiple independent thread pools. */ | ||
public interface MultiThreadPoolsQuiescingExecutor extends QuiescingExecutor { | ||
/** The types of thread pools to use. */ | ||
enum ThreadPoolType { | ||
// Suitable for CPU-heavy tasks. Ideally the number of threads is close to the machine's number | ||
// of cores. | ||
CPU_HEAVY, | ||
REGULAR | ||
} | ||
|
||
/** Execute the runnable, taking into consideration the preferred thread pool type. */ | ||
void execute(Runnable runnable, ThreadPoolType threadPoolType); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.