Skip to content

Commit 2821563

Browse files
committed
feat: using dynamic ThreadPoolExecutor for reconcile and workflow executor services
1 parent 2247498 commit 2821563

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
import java.time.Duration;
44
import java.util.Optional;
55
import java.util.Set;
6-
import java.util.concurrent.ExecutorService;
7-
import java.util.concurrent.Executors;
6+
import java.util.concurrent.*;
87

98
import org.slf4j.Logger;
109
import org.slf4j.LoggerFactory;
@@ -75,7 +74,8 @@ default boolean checkCRDAndValidateLocalModel() {
7574
return false;
7675
}
7776

78-
int DEFAULT_RECONCILIATION_THREADS_NUMBER = 10;
77+
int DEFAULT_RECONCILIATION_THREADS_NUMBER = 200;
78+
int MIN_DEFAULT_RECONCILIATION_THREADS_NUMBER = 10;
7979

8080
/**
8181
* Retrieves the maximum number of threads the operator can spin out to dispatch reconciliation
@@ -87,12 +87,26 @@ default int concurrentReconciliationThreads() {
8787
return DEFAULT_RECONCILIATION_THREADS_NUMBER;
8888
}
8989

90+
default int minConcurrentReconciliationThreads() {
91+
return MIN_DEFAULT_RECONCILIATION_THREADS_NUMBER;
92+
}
93+
9094
int DEFAULT_WORKFLOW_EXECUTOR_THREAD_NUMBER = DEFAULT_RECONCILIATION_THREADS_NUMBER;
95+
int MIN_DEFAULT_WORKFLOW_EXECUTOR_THREAD_NUMBER = MIN_DEFAULT_RECONCILIATION_THREADS_NUMBER;
9196

97+
/**
98+
* Retrieves the maximum number of threads the operator can spin out to be used in the workflows.
99+
*
100+
* @return the maximum number of concurrent workflow threads
101+
*/
92102
default int concurrentWorkflowExecutorThreads() {
93103
return DEFAULT_WORKFLOW_EXECUTOR_THREAD_NUMBER;
94104
}
95105

106+
default int minConcurrentWorkflowExecutorThreads() {
107+
return MIN_DEFAULT_WORKFLOW_EXECUTOR_THREAD_NUMBER;
108+
}
109+
96110
/**
97111
* Used to clone custom resources. It is strongly suggested that implementors override this method
98112
* since the default implementation creates a new {@link Cloner} instance each time this method is
@@ -136,11 +150,15 @@ default Metrics getMetrics() {
136150
}
137151

138152
default ExecutorService getExecutorService() {
139-
return Executors.newFixedThreadPool(concurrentReconciliationThreads());
153+
return new ThreadPoolExecutor(minConcurrentReconciliationThreads(),
154+
concurrentReconciliationThreads(),
155+
1, TimeUnit.MINUTES, new LinkedBlockingDeque<>());
140156
}
141157

142158
default ExecutorService getWorkflowExecutorService() {
143-
return Executors.newFixedThreadPool(concurrentWorkflowExecutorThreads());
159+
return new ThreadPoolExecutor(minConcurrentWorkflowExecutorThreads(),
160+
concurrentWorkflowExecutorThreads(),
161+
1, TimeUnit.MINUTES, new LinkedBlockingDeque<>());
144162
}
145163

146164
default boolean closeClientOnStop() {

0 commit comments

Comments
 (0)