2016-05-19 11 views
0

次のテストではPooledByteBufAllocatorアリーナの番号が出力されます。実行すると、実際の割り当て/割り当て解除と一致しません。 実際の配分:50000の 実際の割り当て解除:50000 アクティブバッファ:0Netty 4 PooledByteBufAllocatorが割り当て/割り当て解除に関する不正な情報を返します

出力は、以下を示す: directActive 1 directAlloc 1 directDealloc 0 heapActive 0ます。HeapAlloc 0 heapDealloc 0

import io.netty.buffer.ByteBuf; 
import io.netty.buffer.PoolArenaMetric; 
import io.netty.buffer.PooledByteBufAllocator; 
import io.netty.util.ResourceLeakDetector; 
import io.netty.util.ResourceLeakDetector.Level; 

import org.junit.Test; 

public class NettyTest2 { 
    public static PooledByteBufAllocator alloc = new PooledByteBufAllocator(true); 

    @Test 
    public void test() throws InterruptedException { 
     ResourceLeakDetector.setLevel(Level.PARANOID); 

     for (int i = 0; i < 50000; i++) { 
      ByteBuf b = alloc.buffer(1000, 1000); 
      b.release(); 
     } 

     Thread.sleep(100); 

     //alloc.freeThreadLocalCache(); 

     showActiveDirectBuffers(); 
     showActiveHeapBuffers(); 
    } 

    void showActiveDirectBuffers() { 
     int directActive = 0, directAlloc = 0, directDealloc = 0; 
     for (PoolArenaMetric arena : alloc.directArenas()) { 
      directActive += arena.numActiveAllocations(); 
      directAlloc += arena.numAllocations(); 
      directDealloc += arena.numDeallocations(); 
     } 
     System.out.println("directActive " + directActive + " directAlloc " + directAlloc + " directDealloc " + directDealloc); 
    } 

    void showActiveHeapBuffers() { 
     int heapActive = 0, heapAlloc = 0, heapDealloc = 0; 
     for (PoolArenaMetric arena : alloc.heapArenas()) { 
      heapActive += arena.numActiveAllocations(); 
      heapAlloc += arena.numAllocations(); 
      heapDealloc += arena.numDeallocations(); 
     } 
     System.out.println("heapActive " + heapActive + " heapAlloc " + heapAlloc + " heapDealloc " + heapDealloc); 
    } 
} 

答えて

0

問題が接続されていますAllocatorsの内部キャッシュに転送します。 キャッシュが無効のアロケータは、実際の呼び出しと一致するalloc/dealloc番号を示します。 (それはhttps://github.com/netty/netty/issues/5275で提案されたように)以下の方法を使用して無効になったキャッシュを持つPooledBufferAllocatorを作成するには

PooledByteBufAllocator alloc = new PooledByteBufAllocator(true, 1, 1, 8192, 11, 0, 0, 0); 
関連する問題