Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
fix: scale number of threads to scale with number of cpus (#878)
Browse files Browse the repository at this point in the history
* fix: scale number of threads to scale with number of cpus

This is temporary solution until something better can be worked out.
Ideally we would separate the executor for gax and the transport provider. But there are some backwards compatibility concerns to workout first.

* use numCpus
  • Loading branch information
igorbernstein2 committed Feb 21, 2020
1 parent 327cd8d commit 0a5b940
Showing 1 changed file with 4 additions and 3 deletions.
Expand Up @@ -41,8 +41,6 @@
*/
@AutoValue
public abstract class InstantiatingExecutorProvider implements ExecutorProvider {
// The number of threads to use with the default executor.
private static final int DEFAULT_EXECUTOR_THREADS = 4;
// Thread factory to use to create our worker threads
private static final ThreadFactory DEFAULT_THREAD_FACTORY =
new ThreadFactory() {
Expand Down Expand Up @@ -79,8 +77,11 @@ public boolean shouldAutoClose() {
public abstract Builder toBuilder();

public static Builder newBuilder() {
int numCpus = Runtime.getRuntime().availableProcessors();
int numThreads = Math.max(4, numCpus);

return new AutoValue_InstantiatingExecutorProvider.Builder()
.setExecutorThreadCount(DEFAULT_EXECUTOR_THREADS)
.setExecutorThreadCount(numThreads)
.setThreadFactory(DEFAULT_THREAD_FACTORY);
}

Expand Down

0 comments on commit 0a5b940

Please sign in to comment.