Repository navigation
Default to UnpooledByteBufAllocator - #157
Conversation
Introduce a new CacheClient builder. This is the safest default Netty by default will keep thread local Pools if the application uses several threads in order to save values on the case but it does not perform frequent operations (ByteBuffer allocations) pooling ByteBuffers will lead to a large usage of direct memory which won't be reclaimed, because by default Netty reclaims memory per thread and every N allocations.
cbf5c3a to
b818386
Compare
|
@eolivelli another alternative (which I think may be better) would be to use: and set |
|
Thanks @normanmaurer for your suggestion. I had in mind only "io.netty.allocator.useCacheForAllThreads" system property and this cannot be controlled at this level. I will change this patch in order to allow the user to pass a ByteBufAllocator and leave the default with UnpooledByteBufferAllocator, I can't let the user of CacheClient deal with every Netty configuration parameter and it won't be future proof. Originally I didn't want to expose Netty classes on public API but I feel it is the best option nowadays. Having the ability to use a shared ByteBufAllocator will help the integration with other Netty based libraries as well |
|
@eolivelli ok no worries... just wanted to show you some other option ;) |
|
@normanmaurer thanks. I like more this new changeset with a shareable ByteBufAllocator. |
| * @return the builder itself | ||
| */ | ||
| public Builder allocator(ByteBufAllocator allocator) { | ||
| this.allocator = allocator; |
There was a problem hiding this comment.
nit: you may want to do a null check
|
@normanmaurer I have addressed your comment about the null check |
Changes:
This is the safest default
Netty by default will keep thread local Pools
f the application uses many different threads while accessing the cache (like a WebApplication)
but it does not perform frequent operations (for us those operations will lead to ByteBuffer allocations)
pooling ByteBuffers will lead to a large usage of direct memory
which won't be reclaimed, because by default Netty reclaims memory
per thread and every N allocations
Many thanks to @normanmaurer who helped understanding the troubles that may be caused by using PooledByteBufAllocator under certain conditions.