incubator-streampark
incubator-streampark copied to clipboard
[improve] Thread pool usage improvement
Search before asking
- [X] I had searched in the feature and found no similar feature requirement.
Description
the current way to create a thread pool
private final ExecutorService executorService = new ThreadPoolExecutor(
Runtime.getRuntime().availableProcessors() * 5,
Runtime.getRuntime().availableProcessors() * 10,
60L,
TimeUnit.SECONDS,
new LinkedBlockingQueue<>(1024),
ThreadUtils.threadFactory("streampark-cluster-executor"),
new ThreadPoolExecutor.AbortPolicy()
);
suggestions below
maxPoolSize:
corePoolSize + (corePoolSize >> 1)
LinkedBlockingQueue capacity: 4096
RejectedExecutionHandler:
public class RunsOldestTaskPolicy implements RejectedExecutionHandler {
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
if (executor.isShutdown()) {
return;
}
BlockingQueue<Runnable> workQueue = executor.getQueue();
Runnable firstWork = workQueue.poll();
boolean newTaskAdd = workQueue.offer(r);
if (firstWork != null) {
firstWork.run();
}
if (!newTaskAdd) {
executor.execute(r);
}
}
}
Usage Scenario
No response
Related issues
No response
Are you willing to submit a PR?
- [ ] Yes I am willing to submit a PR!
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
thanks your feedback. Can you improve this issue?