Skip to content

Commit ab7c01f

Browse files
authored
improve: use fixed thread pool explicitly (#2265)
Signed-off-by: Attila Mészáros <[email protected]>
1 parent dc0b4ee commit ab7c01f

File tree

4 files changed

+29
-22
lines changed

4 files changed

+29
-22
lines changed

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

+21-11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.Optional;
55
import java.util.Set;
66
import java.util.concurrent.ExecutorService;
7+
import java.util.concurrent.Executors;
78
import java.util.function.Consumer;
89

910
import org.slf4j.Logger;
@@ -24,8 +25,6 @@
2425
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent;
2526
import io.javaoperatorsdk.operator.processing.dependent.workflow.ManagedWorkflowFactory;
2627

27-
import static io.javaoperatorsdk.operator.api.config.ExecutorServiceManager.newThreadPoolExecutor;
28-
2928
/** An interface from which to retrieve configuration information. */
3029
public interface ConfigurationService {
3130

@@ -127,14 +126,18 @@ default boolean checkCRDAndValidateLocalModel() {
127126
return false;
128127
}
129128

130-
int DEFAULT_RECONCILIATION_THREADS_NUMBER = 200;
129+
int DEFAULT_RECONCILIATION_THREADS_NUMBER = 50;
130+
/**
131+
* @deprecated Not used anymore in the default implementation
132+
*/
133+
@Deprecated(forRemoval = true)
131134
int MIN_DEFAULT_RECONCILIATION_THREADS_NUMBER = 10;
132135

133136
/**
134-
* The maximum number of threads the operator can spin out to dispatch reconciliation requests to
135-
* reconcilers
137+
* The number of threads the operator can spin out to dispatch reconciliation requests to
138+
* reconcilers with the default executors
136139
*
137-
* @return the maximum number of concurrent reconciliation threads
140+
* @return the number of concurrent reconciliation threads
138141
*/
139142
default int concurrentReconciliationThreads() {
140143
return DEFAULT_RECONCILIATION_THREADS_NUMBER;
@@ -143,17 +146,24 @@ default int concurrentReconciliationThreads() {
143146
/**
144147
* The minimum number of threads the operator starts in the thread pool for reconciliations.
145148
*
149+
* @deprecated not used anymore by default executor implementation
146150
* @return the minimum number of concurrent reconciliation threads
147151
*/
152+
@Deprecated(forRemoval = true)
148153
default int minConcurrentReconciliationThreads() {
149154
return MIN_DEFAULT_RECONCILIATION_THREADS_NUMBER;
150155
}
151156

152157
int DEFAULT_WORKFLOW_EXECUTOR_THREAD_NUMBER = DEFAULT_RECONCILIATION_THREADS_NUMBER;
158+
/**
159+
* @deprecated Not used anymore in the default implementation
160+
*/
161+
@Deprecated(forRemoval = true)
153162
int MIN_DEFAULT_WORKFLOW_EXECUTOR_THREAD_NUMBER = MIN_DEFAULT_RECONCILIATION_THREADS_NUMBER;
154163

155164
/**
156-
* Retrieves the maximum number of threads the operator can spin out to be used in the workflows.
165+
* Number of threads the operator can spin out to be used in the workflows with the default
166+
* executor.
157167
*
158168
* @return the maximum number of concurrent workflow threads
159169
*/
@@ -164,8 +174,10 @@ default int concurrentWorkflowExecutorThreads() {
164174
/**
165175
* The minimum number of threads the operator starts in the thread pool for workflows.
166176
*
177+
* @deprecated not used anymore by default executor implementation
167178
* @return the minimum number of concurrent workflow threads
168179
*/
180+
@Deprecated(forRemoval = true)
169181
default int minConcurrentWorkflowExecutorThreads() {
170182
return MIN_DEFAULT_WORKFLOW_EXECUTOR_THREAD_NUMBER;
171183
}
@@ -191,13 +203,11 @@ default Metrics getMetrics() {
191203
}
192204

193205
default ExecutorService getExecutorService() {
194-
return newThreadPoolExecutor(minConcurrentReconciliationThreads(),
195-
concurrentReconciliationThreads());
206+
return Executors.newFixedThreadPool(concurrentReconciliationThreads());
196207
}
197208

198209
default ExecutorService getWorkflowExecutorService() {
199-
return newThreadPoolExecutor(minConcurrentWorkflowExecutorThreads(),
200-
concurrentWorkflowExecutorThreads());
210+
return Executors.newFixedThreadPool(concurrentWorkflowExecutorThreads());
201211
}
202212

203213
default boolean closeClientOnStop() {

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java

+8
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,21 @@ public int concurrentWorkflowExecutorThreads() {
218218
original.concurrentWorkflowExecutorThreads());
219219
}
220220

221+
/**
222+
* @deprecated Not used anymore in the default implementation
223+
*/
224+
@Deprecated(forRemoval = true)
221225
@Override
222226
public int minConcurrentReconciliationThreads() {
223227
return minConcurrentReconciliationThreads != null ? minConcurrentReconciliationThreads
224228
: original.minConcurrentReconciliationThreads();
225229
}
226230

231+
/**
232+
* @deprecated Not used anymore in the default implementation
233+
*/
227234
@Override
235+
@Deprecated(forRemoval = true)
228236
public int minConcurrentWorkflowExecutorThreads() {
229237
return minConcurrentWorkflowExecutorThreads != null ? minConcurrentWorkflowExecutorThreads
230238
: original.minConcurrentWorkflowExecutorThreads();

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ExecutorServiceManager.java

-10
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import java.util.concurrent.ExecutorService;
99
import java.util.concurrent.Executors;
1010
import java.util.concurrent.Future;
11-
import java.util.concurrent.LinkedBlockingDeque;
12-
import java.util.concurrent.ThreadPoolExecutor;
1311
import java.util.concurrent.TimeUnit;
1412
import java.util.concurrent.TimeoutException;
1513
import java.util.function.Function;
@@ -35,14 +33,6 @@ public class ExecutorServiceManager {
3533
start(configurationService);
3634
}
3735

38-
public static ExecutorService newThreadPoolExecutor(int minThreads, int maxThreads) {
39-
minThreads = Utils.ensureValid(minThreads, "minimum number of threads", MIN_THREAD_NUMBER);
40-
maxThreads = Utils.ensureValid(maxThreads, "maximum number of threads", minThreads + 1);
41-
42-
return new ThreadPoolExecutor(minThreads, maxThreads, 1, TimeUnit.MINUTES,
43-
new LinkedBlockingDeque<>());
44-
}
45-
4636
/**
4737
* Uses cachingExecutorService from this manager. Use this only for tasks, that don't have dynamic
4838
* nature, in sense that won't grow with the number of inputs (thus kubernetes resources)

Diff for: operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventProcessorTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,6 @@ void executionOfReconciliationShouldNotStartIfProcessorStopped() throws Interrup
434434
new BaseConfigurationService(),
435435
o -> {
436436
o.withConcurrentReconciliationThreads(1);
437-
o.withMinConcurrentReconciliationThreads(1);
438437
});
439438
eventProcessor =
440439
spy(new EventProcessor(controllerConfiguration(null, rateLimiterMock, configurationService),

0 commit comments

Comments
 (0)