-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
(feat) add FixedThreadsExecutorGroup #168 #170
Conversation
TODO:
|
添加一个 MpscSingleThreadExecutor,基于 jctools 的 Mpsc queue 实现多生产者单消费者模型的线程池 3 个 SingleThreadExecutor 分别对应
|
* (feat) refactor ThreadId and replicator * (feat) Adds javadoc
* (feat) add AdaptiveBufAllocator * (feat) pooled for ByteBufferCollector #158 * (feat) pooled for ByteBufferCollector #158 * (feat) pooled for ByteBufferCollector #158 * (feat) pooled for ByteBufferCollector #158 * (fix) rename method name * (fix) minor fix * (fix) add metric for recyclers (#164) * (fix) add metric for recyclers * (fix) add metric for ByteBufferCollector.capacity * (fix) code format * (fix) by review comment * feat/zero copy with replicator (#167) * (fix) zero copy with replicator * (fix) support zero copy and add benchmark * (fix) rename field * (fix) rm zero copy and unnecessary metric * (fix) by review comment * (feat) add unit test AdaptiveBufAllocatorTest * (feat) add unit test RecyclersTest * (feat) add unit test RecyclableByteBufferListTest * (feat) add unit test ByteBufferCollectorTest
These tests were written using Diffblue Cover.
新增了几个测试场景,主要是基于 MpscSingleThreadExecutor 使用了不同的 queue,从这个测试结果也可以看出 MpscSingleThreadExecutor 之所以快一些,使用 jctools 的 mpsc queue 也不是唯一的原因
|
除了 benchmark 里 "NEETY_EXECUTOR" -> "NETTY_EXECUTOR" 的错别字外,其他的还要细看 😂 |
我改下 😸 |
有一个很有趣的现象,在 benchmark 中,当我如下排列参赛选手的出场顺序时,他们的成绩会相应缩小 executors.put("mpsc_single_thread_executor ", MPSC_EXECUTOR);
executors.put("netty_default_event_executor ", NEETY_EXECUTOR);
executors.put("default_single_thread_executor ", DEFAULT);
而当把 warmup 的次数调大到 10,000,000 之后,他们的差距会进一步缩小:
所以我怀疑 warmup 也在 benchmark 中起到了影响的作用,尤其是在 warmup 次数不足时,越靠后的选手越是得利,尽管如此, |
👍非常关键的发现,我仔细检查了代码,怀疑主要原因应该是 producers 使用了 ThreadPoolExecutor 和 LinkedBlockingQueue,由于 producers 是全局共享的,运行次数很多,间接帮助 default_single_thread_executor 做了预热,所以把它放的越靠后性能越好,我重写了 benchmark 代码,借助 jmh,应该不会再有外界因素影响了 |
jmh 的测试结果 cnt=3
cnt=10
|
@fengjiachun 存在冲突 |
done |
Motivation:
注:暂不合并,看测试数据优化 append-entries 线程模型,试图减少上下文切换和锁竞争
Modification:
主要增加 FixedThreadsExecutorGroup 和 SingleThreadExecutor 类,并可兼容 AppendEntriesRequestProcessor 中原来使用的 DefaultEventExecutor
Result:
Fixes #168 #158