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
Let PoolThreadCache work even if allocation and deallocation Thread a… #3833
Conversation
@trustin please review. @nmittler @ejona86 @louiscryan this should also be interesting for grpc :) |
} | ||
maxUnusedCached = size / 2; | ||
this.size = powerOfTwo(size); | ||
queue = new MpscArrayQueue<Entry<T>>(this.size); |
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.
What happens when Unsafe
is unavailable?
How about making the new classes package-private and adding the factory methods to |
@trustin good point let me address both comments |
@trustin addressed comments... please check |
} | ||
maxUnusedCached = size / 2; | ||
this.size = powerOfTwo(size); | ||
queue = PlatformDependent.newFixedMpscQueue(this.size); |
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.
Not really a gain, but maybe this is shorter:
queue = PlatformDependent.newFixedMpscQueue(this.size = powerOfTwo(size));
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.
just leave it as it is :)
LGTM. Please consider to take care of #3835 :-) |
@normanmaurer Sure! |
@netkins build |
…re different Motivation: PoolThreadCache did only cache allocations if the allocation and deallocation Thread were the same. This is not optimal as often people write from differen thread then the actual EventLoop thread. Modification: - Add MpscArrayQueue which was forked from jctools and lightly modified. - Use MpscArrayQueue for caches and always add buffer back to the cache that belongs to the allocation thread. Result: ThreadPoolCache is now also usable and so gives performance improvements when allocation and deallocation thread are different. Performance when using same thread for allocation and deallocation is noticable worse then before.
7aa472e
to
02cc322
Compare
业务线程alloc, 结果被在netty4中 却被IO线程release掉的, 这导致pooledBuf前边那层基于threadLocal的cache出了些问题(就是业务线程alloc时不断的cache不命中, 因为release时归还到别的线程的cache中了) netty/netty#3833 norman的改法是: pooledBuf中绑定cache, 谁alloc的就rlease给谁, 这就又导致release时可能引起多个线程的竞争条件(比如可能存在这样的场景:线程1线程2都要release到线程3的cache中), norman用一个MPSC队列解决的这个竞争(MPSC就是多生产者单消费者), 这个队列倒是很有意思, 感兴趣参考jctools https://github.com/JCTools/JCTools
…re different
Motivation:
PoolThreadCache did only cache allocations if the allocation and deallocation Thread were the same. This is not optimal as often people write from differen thread then the actual EventLoop thread.
Modification:
Result:
ThreadPoolCache is now also usable and so gives performance improvements when allocation and deallocation thread are different.
Performance when using same thread for allocation and deallocation is noticable worse then before.