cuba-platform / cuba

CUBA Platform is a high level framework for enterprise applications development
https://www.cuba-platform.com
Apache License 2.0
1.34k stars 219 forks source link

We should be allowed to configure Background Worker's queue capacity #3239

Open dhannydw opened 3 years ago

dhannydw commented 3 years ago

Environment

Description of the enhancement

BackgroundWorker configuration should allow configuration of queueCapacity. This is due to the way ThreadPoolExecutor works, which will only create new thread beyond corePoolSize if the queue is full. Therefore, we should be allowed to tune the ThreadPoolExecutor by also adjusting queueCapacity, in addition to corePoolSize (cuba.backgroundWorker.minBackgroundThreadsCount) and maxPoolSize (webConfig.getMaxActiveBackgroundTasksCount()). Otherwise, maxPoolSize is pretty much useless with unlimited LinkedBlockingQueue.

Expected behavior

We should be able to specify a property in application.properties to control the backgroundworker's queue capacity. This way, one can tune the ThreadPoolExecutor to increase number of Thread up to maxPoolSize when the queue is full. Note that in general, we want to keep corePoolSize low when the load is low, but can increase when the load is high. But this is not how the corePoolSize and maxPoolSize work.

Actual behavior

We cannot control backgroundworker's queue capacity, and the current implementation uses new LinkedBlockingQueue<>() to create Integer.MAX_VALUE queue capacity. Therefore, the maximum active Thread is always at 4 (default cuba.backgroundWorker.minBackgroundThreadsCount), and never increases because the queue capacity is very large.

alexbudarov commented 3 years ago

Hi, Please take a look at this closed issue: https://github.com/cuba-platform/cuba/issues/3097#issuecomment-749602199 and this: https://github.com/cuba-platform/cuba/issues/3183

So you need to: