-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enhance: reuse thread pool for scheduled service #1389
Conversation
@Extension("reuse-scheduled") | ||
public class ReuseScheduledThreadPoolFactory implements SofaExecutorFactory { | ||
|
||
Map<String, Executor> uniqueMap = new ConcurrentHashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最好设置成私有的,另外也要考虑下如何回收这里的Executor。
* @author junyuan | ||
* @version ReuseScheduledThreadPoolFactory.java, v 0.1 2024-01-15 19:44 junyuan Exp $ | ||
*/ | ||
@Extension("reuse-scheduled") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
容易和 BoltServer 中的处理线程混淆,RPC 中有很多的其他异步线程,是否可以考虑一下,其他异步线程也做个 Extension 或者单独搞个类管理这种线程池。
|
||
@Override | ||
public Executor createExecutor(String namePrefix, ServerConfig serverConfig) { | ||
return uniqueMap.computeIfAbsent(namePrefix, key -> new ScheduledThreadPoolExecutor(1, new NamedThreadFactory(namePrefix, true))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
之前 coreSize 设置为 1,每个 Consumer 一个 Schedule 单一线程。 更换成共享一个 Schedule 线程池的话,如果还是使用单一线程的话,会不会存在性能问题和更新不及时的问题?
Motivation:
It might be exhausted when create new executor pool for some scheduled cases such as reconnection, where each consumer may has its own scheduled executor pool and its own thread. Amount of threads may grow to O(m) aligns with amount of consumers.
Modification:
add a reused schedule pool that may provide same pool with same unique key
Result: