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

fix: scale number of threads to scale with number of cpus #878

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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