Search in sources :

Example 11 with PooledByteBufAllocator

use of io.netty.buffer.PooledByteBufAllocator in project pulsar by yahoo.

the class BookieClientsStatsGeneratorTest method testJvmDirectMemoryUsedMetric.

@Test
public void testJvmDirectMemoryUsedMetric() throws Exception {
    PooledByteBufAllocator allocator = new //
    PooledByteBufAllocator(// preferDirect
    true, // nHeapArenas,
    0, // nDirectArena
    1, // pageSize
    8192, // maxOrder
    11, // tinyCacheSize
    64, // smallCacheSize
    32, // normalCacheSize
    8);
    int allocateMemory = 17777216;
    long directMemory1 = JvmMetrics.getJvmDirectMemoryUsed();
    ByteBuf buf2 = allocator.directBuffer(allocateMemory, allocateMemory);
    long directMemory2 = JvmMetrics.getJvmDirectMemoryUsed();
    assertEquals(directMemory2, directMemory1 + allocateMemory);
    ByteBuf buf3 = allocator.directBuffer(allocateMemory, allocateMemory);
    long directMemory3 = JvmMetrics.getJvmDirectMemoryUsed();
    assertEquals(directMemory3, directMemory2 + allocateMemory);
    buf3.release();
    directMemory3 = JvmMetrics.getJvmDirectMemoryUsed();
    assertEquals(directMemory3, directMemory2);
    buf2.release();
    directMemory2 = JvmMetrics.getJvmDirectMemoryUsed();
    assertEquals(directMemory2, directMemory1);
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) PooledByteBufAllocator(io.netty.buffer.PooledByteBufAllocator) Test(org.testng.annotations.Test)

Example 12 with PooledByteBufAllocator

use of io.netty.buffer.PooledByteBufAllocator in project pulsar by yahoo.

the class ManagedLedgerCacheMetrics method generate.

@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.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;
}
Also used : PoolArenaMetric(io.netty.buffer.PoolArenaMetric) ManagedLedgerFactoryMXBean(org.apache.bookkeeper.mledger.ManagedLedgerFactoryMXBean) Metrics(com.yahoo.pulsar.broker.stats.Metrics) PoolChunkListMetric(io.netty.buffer.PoolChunkListMetric) PoolChunkMetric(io.netty.buffer.PoolChunkMetric) PooledByteBufAllocator(io.netty.buffer.PooledByteBufAllocator)

Aggregations

PooledByteBufAllocator (io.netty.buffer.PooledByteBufAllocator)12 ByteBuf (io.netty.buffer.ByteBuf)6 Setup (org.openjdk.jmh.annotations.Setup)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)2 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)2 Test (org.junit.Test)2 State (org.redisson.client.handler.State)2 Metrics (com.yahoo.pulsar.broker.stats.Metrics)1 AllocatorStats (com.yahoo.pulsar.common.stats.AllocatorStats)1 Metadata (io.grpc.Metadata)1 ServerCall (io.grpc.ServerCall)1 ServerCallHandler (io.grpc.ServerCallHandler)1 ServiceDescriptor (io.grpc.ServiceDescriptor)1 ByteBufOutputMarshaller (io.grpc.benchmarks.ByteBufOutputMarshaller)1 NettyChannelBuilder (io.grpc.netty.NettyChannelBuilder)1 NettyServerBuilder (io.grpc.netty.NettyServerBuilder)1 ByteBufAllocator (io.netty.buffer.ByteBufAllocator)1 PoolArenaMetric (io.netty.buffer.PoolArenaMetric)1 PoolChunkListMetric (io.netty.buffer.PoolChunkListMetric)1