Skip to content

fix: allow to burst threads by default #2262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ default boolean checkCRDAndValidateLocalModel() {
return false;
}

int DEFAULT_RECONCILIATION_THREADS_NUMBER = 200;
int DEFAULT_RECONCILIATION_THREADS_NUMBER = Integer.MAX_VALUE;
int MIN_DEFAULT_RECONCILIATION_THREADS_NUMBER = 10;

/**
Expand Down Expand Up @@ -190,6 +190,21 @@ default Metrics getMetrics() {
return Metrics.NOOP;
}

/**
* Use to provide custom executor service.<br/>
* By default, a {@link java.util.concurrent.ThreadPoolExecutor} is used, that honors the values
* of concurrentReconciliationThreads and minConcurrentReconciliationThreads. When a controller
* starts, all the resources are reconciled, therefore there is a natural and expected burst on
* startup. According to this there are multiple options, using the ThreadPoolExecutor. Either:
* <ul>
* <li>Use a very high upper bound thread limit with
* {@link java.util.concurrent.SynchronousQueue}. This is the default approach.</li>
* <li>Use fixed number of threads with infinite queue, lik
* {@link java.util.concurrent.LinkedBlockingDeque}.</li>
* <li>In addition to that, could be further fine tuned using the
* {@link java.util.concurrent.ArrayBlockingQueue}.</li>
* </ul>
*/
default ExecutorService getExecutorService() {
return newThreadPoolExecutor(minConcurrentReconciliationThreads(),
concurrentReconciliationThreads());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@
import java.time.Duration;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand All @@ -37,9 +29,8 @@ public class ExecutorServiceManager {
public static ExecutorService newThreadPoolExecutor(int minThreads, int maxThreads) {
minThreads = Utils.ensureValid(minThreads, "minimum number of threads", MIN_THREAD_NUMBER);
maxThreads = Utils.ensureValid(maxThreads, "maximum number of threads", minThreads + 1);

return new ThreadPoolExecutor(minThreads, maxThreads, 1, TimeUnit.MINUTES,
new LinkedBlockingDeque<>());
new SynchronousQueue<>());
}

/**
Expand Down