Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

normanmaurer
Copy link
Member

…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.

@normanmaurer normanmaurer self-assigned this May 27, 2015
@normanmaurer normanmaurer added this to the 4.0.29.Final milestone May 27, 2015
@normanmaurer
Copy link
Member Author

@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);
Copy link
Member

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?

@trustin
Copy link
Member

trustin commented May 27, 2015

How about making the new classes package-private and adding the factory methods to PlatformDependent?

@normanmaurer
Copy link
Member Author

@trustin good point let me address both comments

@normanmaurer
Copy link
Member Author

@trustin addressed comments... please check

}
maxUnusedCached = size / 2;
this.size = powerOfTwo(size);
queue = PlatformDependent.newFixedMpscQueue(this.size);
Copy link
Member

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));

Copy link
Member Author

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 :)

@trustin
Copy link
Member

trustin commented May 27, 2015

LGTM. Please consider to take care of #3835 :-)

@normanmaurer
Copy link
Member Author

@trustin can we handle #3835 after this is merged ?

@trustin
Copy link
Member

trustin commented May 27, 2015

@normanmaurer Sure!

@normanmaurer
Copy link
Member Author

@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.
@normanmaurer
Copy link
Member Author

Cherry-picked into 4.0 (f765053) , 4.1 (81fee66) and master (ee1219b)

@normanmaurer normanmaurer deleted the pool_cache_mpsc branch May 27, 2015 12:39
fengjiachun pushed a commit to fengjiachun/Jupiter that referenced this pull request Nov 2, 2015
业务线程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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants