static void AssertPoolChunkListMetric(IPoolArenaMetric arenaMetric)
 {
     IReadOnlyList<IPoolChunkListMetric> lists = arenaMetric.ChunkLists;
     Assert.Equal(6, lists.Count);
     AssertPoolChunkListMetric(lists[0], 1, 25);
     AssertPoolChunkListMetric(lists[1], 1, 50);
     AssertPoolChunkListMetric(lists[2], 25, 75);
     AssertPoolChunkListMetric(lists[4], 75, 100);
     AssertPoolChunkListMetric(lists[5], 100, 100);
 }
 public void TinySubpageMetric()
 {
     var allocator = new PooledByteBufferAllocator(true, 1, 1, 8192, 11, 0, 0, 0);
     IByteBuffer buffer = allocator.HeapBuffer(1);
     try
     {
         IPoolArenaMetric metric = allocator.Metric.HeapArenas()[0];
         IPoolSubpageMetric subpageMetric = metric.TinySubpages[0];
         Assert.Equal(1, subpageMetric.MaxNumElements - subpageMetric.NumAvailable);
     }
     finally
     {
         buffer.Release();
     }
 }
示例#3
0
        public void AllocationCounter()
        {
            var allocator = new PooledByteBufferAllocator(
                true,  // preferDirect
                0,     // nHeapArena
                1,     // nDirectArena
                8192,  // pageSize
                11,    // maxOrder
                0,     // tinyCacheSize
                0,     // smallCacheSize
                0      // normalCacheSize
                );

            // create tiny buffer
            IByteBuffer b1 = allocator.Buffer(24);
            // create small buffer
            IByteBuffer b2 = allocator.Buffer(800);
            // create normal buffer
            IByteBuffer b3 = allocator.Buffer(8192 * 2);

            Assert.NotNull(b1);
            Assert.NotNull(b2);
            Assert.NotNull(b3);

            // then release buffer to deallocated memory while threadlocal cache has been disabled
            // allocations counter value must equals deallocations counter value
            Assert.True(b1.Release());
            Assert.True(b2.Release());
            Assert.True(b3.Release());

            Assert.True(allocator.DirectArenas().Count >= 1);
            IPoolArenaMetric metric = allocator.DirectArenas()[0];

            Assert.Equal(3, metric.NumDeallocations);
            Assert.Equal(3, metric.NumAllocations);

            Assert.Equal(1, metric.NumTinyDeallocations);
            Assert.Equal(1, metric.NumTinyAllocations);
            Assert.Equal(1, metric.NumSmallDeallocations);
            Assert.Equal(1, metric.NumSmallAllocations);
            Assert.Equal(1, metric.NumNormalDeallocations);
            Assert.Equal(1, metric.NumNormalAllocations);
        }