@@ -162,7 +162,9 @@ public abstract class SeekableStreamSupervisor<PartitionIdType, SequenceOffsetTy
162
162
163
163
private static final long MAX_RUN_FREQUENCY_MILLIS = 1000 ;
164
164
private static final int MAX_INITIALIZATION_RETRIES = 20 ;
165
- private static final int DEFAULT_CORE_POOL_SIZE = 1 ;
165
+ private static final int MIN_CORE_POOL_SIZE = 2 ;
166
+ private static final int TASKS_PER_THREAD_FACTOR = 4 ;
167
+ private static final int KEEPALIVE_TIME_SECONDS = 2 ;
166
168
167
169
private static final EmittingLogger log = new EmittingLogger (SeekableStreamSupervisor .class );
168
170
@@ -941,8 +943,19 @@ public SeekableStreamSupervisor(
941
943
spec .isSuspended ()
942
944
);
943
945
946
+ int workerThreads ;
944
947
if (autoScalerConfig != null && autoScalerConfig .getEnableTaskAutoScaler ()) {
945
948
log .info ("Running Task autoscaler for supervisor[%s] for datasource[%s]" , supervisorId , dataSource );
949
+ workerThreads = (this .tuningConfig .getWorkerThreads () != null
950
+ ? this .tuningConfig .getWorkerThreads () / TASKS_PER_THREAD_FACTOR
951
+ : autoScalerConfig .getTaskCountMax () / TASKS_PER_THREAD_FACTOR );
952
+ } else {
953
+ workerThreads = (this .tuningConfig .getWorkerThreads () != null
954
+ ? this .tuningConfig .getWorkerThreads () / TASKS_PER_THREAD_FACTOR
955
+ : this .ioConfig .getTaskCount () / TASKS_PER_THREAD_FACTOR );
956
+ }
957
+ if (workerThreads < MIN_CORE_POOL_SIZE ) {
958
+ workerThreads = MIN_CORE_POOL_SIZE ;
946
959
}
947
960
948
961
IdleConfig specIdleConfig = spec .getIoConfig ().getIdleConfig ();
@@ -962,14 +975,16 @@ public SeekableStreamSupervisor(
962
975
);
963
976
}
964
977
965
- this .workerExec = MoreExecutors .listeningDecorator (
966
- new ScheduledThreadPoolExecutor (
967
- DEFAULT_CORE_POOL_SIZE ,
968
- Execs .makeThreadFactory (StringUtils .encodeForFormat (supervisorTag ) + "-Worker-%d" )
969
- )
978
+ ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor (
979
+ workerThreads ,
980
+ Execs .makeThreadFactory (StringUtils .encodeForFormat (supervisorTag ) + "-Worker-%d" )
970
981
);
982
+ executor .setKeepAliveTime (KEEPALIVE_TIME_SECONDS , TimeUnit .SECONDS );
971
983
972
- log .info ("Created worker pool for supervisor[%s] for dataSource[%s]" , this .supervisorId , this .dataSource );
984
+ this .workerExec = MoreExecutors .listeningDecorator (executor );
985
+ log .info (
986
+ "Created worker pool with [%d] threads for supervisor[%s] for dataSource[%s]" ,
987
+ workerThreads , this .supervisorId , this .dataSource );
973
988
974
989
this .taskInfoProvider = new TaskInfoProvider ()
975
990
{
0 commit comments