franz1981 edited a comment on issue #2832: ARTEMIS-2482 Large messages could 
leak native ByteBuffers
URL: https://github.com/apache/activemq-artemis/pull/2832#issuecomment-530284944
 
 
   @wy96f Yes and no :)
   They would leak (at first look, but let me take a better look), but they 
just contain wrappers to direct memory that cannot be released (is part of the 
pool and they have no cleaner). The impact should be way less then `IOUtil` 
that pool native `ByteBuffer`s holding exclusively native memory that won't be 
reused anymore...
   
   Ideally we shouldn't have *any* thread locals, but we use them for several 
stuff (including the NIO factories and page read/write): I'm planning to 
replaced them by using the Netty pool, because of the difference on how thread 
locals are used. 
   Our thread locals in Artemis just hold memory that cannot be reused if not 
by the same thread, while for Netty, thread locals are just a way to cache 
wrappers that has a very limited impact on GC, while the pool really allows to 
reuse memory where is most needed...
   
   Just to add more detail: consider that 
`PooledBytebufAllocator.PoolThreadLocalCache::initialValue` contains this 
comment, while creating a thread-local `PoolThreadCache`:
   ```
   @Override
           protected synchronized PoolThreadCache initialValue() {
               final PoolArena<byte[]> heapArena = leastUsedArena(heapArenas);
               final PoolArena<ByteBuffer> directArena = 
leastUsedArena(directArenas);
   
               Thread current = Thread.currentThread();
               if (useCacheForAllThreads || current instanceof 
FastThreadLocalThread) {
                   return new PoolThreadCache(
                           heapArena, directArena, tinyCacheSize, 
smallCacheSize, normalCacheSize,
                           DEFAULT_MAX_CACHED_BUFFER_CAPACITY, 
DEFAULT_CACHE_TRIM_INTERVAL);
               }
               // No caching so just use 0 as sizes.
               return new PoolThreadCache(heapArena, directArena, 0, 0, 0, 0, 
0);
           }
   ```
   So, if we are not very happy about the Netty caching on non-Netty threads, 
we can disable those caches on by setting 
`-Dio.netty.allocator.useCacheForAllThreads=false`

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to