io.netty.buffer.PoolArenaMetric Java Examples

The following examples show how to use io.netty.buffer.PoolArenaMetric. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NettyBufferPool.java    From Mycat2 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public long size() {

    List<PoolArenaMetric> list = allocator.getAlloc().directArenas();
    long chunkSizeBytes = allocator.getChunkSize();
    int chunkCount = 0;

    synchronized (this) {
        /**PoolArenas*/
        for (PoolArenaMetric pool : list) {
            List<PoolChunkListMetric> pcks = pool.chunkLists();
            /**针对PoolChunkList*/
            for (PoolChunkListMetric pck : pcks) {
                Iterator<PoolChunkMetric> it = pck.iterator();
                while (it.hasNext()) {
                    PoolChunkMetric p = it.next();
                    chunkCount++;
                }
            }
        }
    }

    return chunkCount * chunkSizeBytes;
}
 
Example #2
Source File: NettyInternalMetrics.java    From ambry with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
  PooledByteBufAllocatorMetric metric = PooledByteBufAllocator.DEFAULT.metric();
  numDirectArenas = metric.numDirectArenas();
  numHeapArenas = metric.numHeapArenas();
  numThreadLocalCaches = metric.numThreadLocalCaches();
  usedHeapMemory = metric.usedHeapMemory();
  usedDirectMemory = metric.usedDirectMemory();
  List<PoolArenaMetric> heapArenaMetrics = metric.heapArenas();
  List<PoolArenaMetric> directArenaMetrics = metric.directArenas();
  numHeapTotalAllocations = heapArenaMetrics.stream().mapToLong(PoolArenaMetric::numAllocations).sum();
  numHeapTotalDeallocations = heapArenaMetrics.stream().mapToLong(PoolArenaMetric::numDeallocations).sum();
  numHeapTotalActiveAllocations = heapArenaMetrics.stream().mapToLong(PoolArenaMetric::numActiveAllocations).sum();
  numDirectTotalAllocations = directArenaMetrics.stream().mapToLong(PoolArenaMetric::numAllocations).sum();
  numDirectTotalDeallocations = directArenaMetrics.stream().mapToLong(PoolArenaMetric::numDeallocations).sum();
  numDirectTotalActiveAllocations =
      directArenaMetrics.stream().mapToLong(PoolArenaMetric::numActiveAllocations).sum();
}
 
Example #3
Source File: NettyByteBufLeakHelper.java    From ambry with Apache License 2.0 6 votes vote down vote up
/**
 * Method to call at any method that is tagged {@link org.junit.Before} to collect some allocation stats.
 */
public void beforeTest() {
  if (cachedEnabled) {
    return;
  }
  PooledByteBufAllocatorMetric metric = PooledByteBufAllocator.DEFAULT.metric();
  List<PoolArenaMetric> heaps = metric.heapArenas();
  activeHeapAllocations = heaps.stream().mapToLong(PoolArenaMetric::numActiveAllocations).sum();
  heapAllocations = heaps.stream().mapToLong(PoolArenaMetric::numAllocations).sum();
  heapDeallocations = heaps.stream().mapToLong(PoolArenaMetric::numDeallocations).sum();

  List<PoolArenaMetric> directs = metric.directArenas();
  activeDirectAllocations = directs.stream().mapToLong(PoolArenaMetric::numActiveAllocations).sum();
  directAllocations = directs.stream().mapToLong(PoolArenaMetric::numAllocations).sum();
  directDeallocations = directs.stream().mapToLong(PoolArenaMetric::numDeallocations).sum();
}
 
Example #4
Source File: NettyByteBufLeakHelper.java    From ambry with Apache License 2.0 6 votes vote down vote up
/**
 * Method to call at any method that is tagged {@link org.junit.After} to verify there is no leak within this test case.
 */
public void afterTest() {
  if (cachedEnabled || disabled) {
    return;
  }

  PooledByteBufAllocatorMetric metric = PooledByteBufAllocator.DEFAULT.metric();
  List<PoolArenaMetric> heaps = metric.heapArenas();
  long currentActiveHeapAllocations = heaps.stream().mapToLong(PoolArenaMetric::numActiveAllocations).sum();
  long currentHeapAllocations = heaps.stream().mapToLong(PoolArenaMetric::numAllocations).sum();
  long currentHeapDeallocations = heaps.stream().mapToLong(PoolArenaMetric::numDeallocations).sum();

  List<PoolArenaMetric> directs = metric.directArenas();
  long currentActiveDirectAllocations = directs.stream().mapToLong(PoolArenaMetric::numActiveAllocations).sum();
  long currentDirectAllocations = directs.stream().mapToLong(PoolArenaMetric::numAllocations).sum();
  long currentDirectDeallocations = directs.stream().mapToLong(PoolArenaMetric::numDeallocations).sum();

  String message = String.format("DirectMemoryLeak: [allocation|deallocation] before test[%d|%d], after test[%d|%d]",
      directAllocations, directDeallocations, currentDirectAllocations, currentDirectDeallocations);
  Assert.assertEquals(message, activeDirectAllocations, currentActiveDirectAllocations);
  message = String.format("HeapMemoryLeak: [allocation|deallocation] before test[%d|%d], after test[%d|%d]",
      heapAllocations, heapDeallocations, currentHeapAllocations, currentHeapDeallocations);
  Assert.assertEquals(message, activeHeapAllocations, currentActiveHeapAllocations);
}
 
Example #5
Source File: MemoryLeakDetectionRule.java    From brpc-java with Apache License 2.0 5 votes vote down vote up
private static int getActiveDirectBuffers(PooledByteBufAllocator alloc) {
    int directActive = 0, directAlloc = 0, directDealloc = 0;
    for (PoolArenaMetric arena : alloc.metric().directArenas()) {
        directActive += arena.numActiveAllocations();
        directAlloc += arena.numAllocations();
        directDealloc += arena.numDeallocations();
    }
    log.info("direct memory usage, active: {}, alloc: {}, dealloc: {}", directActive, directAlloc, directDealloc);
    return directActive;
}
 
Example #6
Source File: MemoryLeakDetectionRule.java    From brpc-java with Apache License 2.0 5 votes vote down vote up
private static int getActiveHeapBuffers(PooledByteBufAllocator alloc) {
    int heapActive = 0, heapAlloc = 0, heapDealloc = 0;
    for (PoolArenaMetric arena : alloc.metric().heapArenas()) {
        heapActive += arena.numActiveAllocations();
        heapAlloc += arena.numAllocations();
        heapDealloc += arena.numDeallocations();
    }
    log.info("heap memory usage, active: {}, alloc: {}, dealloc: {}", heapActive, heapAlloc, heapDealloc);
    return heapActive;
}
 
Example #7
Source File: AllocatorStatsGenerator.java    From pulsar with Apache License 2.0 5 votes vote down vote up
private static PoolArenaStats newPoolArenaStats(PoolArenaMetric m) {
    PoolArenaStats stats = new PoolArenaStats();
    stats.numTinySubpages = m.numTinySubpages();
    stats.numSmallSubpages = m.numSmallSubpages();
    stats.numChunkLists = m.numChunkLists();

    stats.tinySubpages = m.tinySubpages().stream()
        .map(AllocatorStatsGenerator::newPoolSubpageStats)
        .collect(Collectors.toList());
    stats.smallSubpages = m.smallSubpages().stream()
        .map(AllocatorStatsGenerator::newPoolSubpageStats)
        .collect(Collectors.toList());
    stats.chunkLists = m.chunkLists().stream()
        .map(AllocatorStatsGenerator::newPoolChunkListStats)
        .collect(Collectors.toList());

    stats.numAllocations = m.numAllocations();
    stats.numTinyAllocations = m.numTinyAllocations();
    stats.numSmallAllocations = m.numSmallAllocations();
    stats.numNormalAllocations = m.numNormalAllocations();
    stats.numHugeAllocations = m.numHugeAllocations();
    stats.numDeallocations = m.numDeallocations();
    stats.numTinyDeallocations = m.numTinyDeallocations();
    stats.numSmallDeallocations = m.numSmallDeallocations();
    stats.numNormalDeallocations = m.numNormalDeallocations();
    stats.numHugeDeallocations = m.numHugeDeallocations();
    stats.numActiveAllocations = m.numActiveAllocations();
    stats.numActiveTinyAllocations = m.numActiveTinyAllocations();
    stats.numActiveSmallAllocations = m.numActiveSmallAllocations();
    stats.numActiveNormalAllocations = m.numActiveNormalAllocations();
    stats.numActiveHugeAllocations = m.numActiveHugeAllocations();
    return stats;
}
 
Example #8
Source File: JvmMetrics.java    From pulsar with Apache License 2.0 5 votes vote down vote up
public List<Metrics> generate() {

        Metrics m = createMetrics();

        Runtime r = Runtime.getRuntime();

        m.put("jvm_heap_used", r.totalMemory() - r.freeMemory());
        m.put("jvm_max_memory", r.maxMemory());
        m.put("jvm_total_memory", r.totalMemory());

        m.put("jvm_direct_memory_used", getJvmDirectMemoryUsed());
        m.put("jvm_max_direct_memory", io.netty.util.internal.PlatformDependent.maxDirectMemory());
        m.put("jvm_thread_cnt", getThreadCount());

        this.gcLogger.logMetrics(m);

        long totalAllocated = 0;
        long totalUsed = 0;

        for (PoolArenaMetric arena : PooledByteBufAllocator.DEFAULT.directArenas()) {
            this.gcLogger.logMetrics(m);
            for (PoolChunkListMetric list : arena.chunkLists()) {
                for (PoolChunkMetric chunk : list) {
                    int size = chunk.chunkSize();
                    int used = size - chunk.freeBytes();

                    totalAllocated += size;
                    totalUsed += used;
                }
            }
        }

        m.put(this.componentName + "_default_pool_allocated", totalAllocated);
        m.put(this.componentName + "_default_pool_used", totalUsed);

        this.gcLogger.logMetrics(m);

        return Lists.newArrayList(m);
    }
 
Example #9
Source File: AbstractDataBufferAllocatingTestCase.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private static long getAllocations(List<PoolArenaMetric> metrics) {
	return metrics.stream().mapToLong(PoolArenaMetric::numActiveAllocations).sum();
}
 
Example #10
Source File: AbstractDataBufferAllocatingTestCase.java    From java-technology-stack with MIT License 4 votes vote down vote up
private static long getAllocations(List<PoolArenaMetric> metrics) {
	return metrics.stream().mapToLong(PoolArenaMetric::numActiveAllocations).sum();
}
 
Example #11
Source File: ManagedLedgerCacheMetrics.java    From pulsar with Apache License 2.0 4 votes vote down vote up
@Override
public synchronized List<Metrics> generate() {

    // get the ML cache stats bean

    ManagedLedgerFactoryMXBean mlCacheStats = getManagedLedgerCacheStats();

    Metrics m = createMetrics();

    m.put("brk_ml_count", mlCacheStats.getNumberOfManagedLedgers());
    m.put("brk_ml_cache_used_size", mlCacheStats.getCacheUsedSize());
    m.put("brk_ml_cache_evictions", mlCacheStats.getNumberOfCacheEvictions());
    m.put("brk_ml_cache_hits_rate", mlCacheStats.getCacheHitsRate());
    m.put("brk_ml_cache_misses_rate", mlCacheStats.getCacheMissesRate());
    m.put("brk_ml_cache_hits_throughput", mlCacheStats.getCacheHitsThroughput());
    m.put("brk_ml_cache_misses_throughput", mlCacheStats.getCacheMissesThroughput());

    PooledByteBufAllocator allocator = EntryCacheImpl.ALLOCATOR;
    long activeAllocations = 0;
    long activeAllocationsTiny = 0;
    long activeAllocationsSmall = 0;
    long activeAllocationsNormal = 0;
    long activeAllocationsHuge = 0;
    long totalAllocated = 0;
    long totalUsed = 0;

    for (PoolArenaMetric arena : allocator.metric().directArenas()) {
        activeAllocations += arena.numActiveAllocations();
        activeAllocationsTiny += arena.numActiveTinyAllocations();
        activeAllocationsSmall += arena.numActiveSmallAllocations();
        activeAllocationsNormal += arena.numActiveNormalAllocations();
        activeAllocationsHuge += arena.numActiveHugeAllocations();

        for (PoolChunkListMetric list : arena.chunkLists()) {
            for (PoolChunkMetric chunk : list) {
                int size = chunk.chunkSize();
                int used = size - chunk.freeBytes();

                totalAllocated += size;
                totalUsed += used;
            }
        }
    }

    m.put("brk_ml_cache_pool_allocated", totalAllocated);
    m.put("brk_ml_cache_pool_used", totalUsed);
    m.put("brk_ml_cache_pool_active_allocations", activeAllocations);
    m.put("brk_ml_cache_pool_active_allocations_tiny", activeAllocationsTiny);
    m.put("brk_ml_cache_pool_active_allocations_small", activeAllocationsSmall);
    m.put("brk_ml_cache_pool_active_allocations_normal", activeAllocationsNormal);
    m.put("brk_ml_cache_pool_active_allocations_huge", activeAllocationsHuge);

    metrics.clear();
    metrics.add(m);
    return metrics;

}