Search in sources :

Example 26 with PooledByteBufAllocator

use of io.netty.buffer.PooledByteBufAllocator in project x-pipe by ctripcorp.

the class NettyKeyedPoolClientFactoryTest method testMakeObjectWithFastThreadLocalCache.

@Test
public void testMakeObjectWithFastThreadLocalCache() throws Exception {
    PooledObject<NettyClient> pooledObject = factory.makeObject(endpoint);
    NettyClient client = pooledObject.getObject();
    OkCommand command = new OkCommand(objectPool.getKeyPool(endpoint), scheduled, CHECK_INTERVAL);
    command.execute().get();
    PooledByteBufAllocator allocator = (PooledByteBufAllocator) client.channel().alloc();
    AtomicReference<Object> freeSweepAllocationThreshold = new AtomicReference<>();
    CountDownLatch latch = new CountDownLatch(1);
    client.channel().eventLoop().execute(new Runnable() {

        @Override
        public void run() {
            try {
                Field field = FieldUtils.getDeclaredField(allocator.getClass(), "threadCache", true);
                Object threadCache = field.get(allocator);
                logger.info("[class]{}", threadCache.getClass());
                FastThreadLocal fastThreadLocal = (FastThreadLocal) threadCache;
                Object poolThreadCache = fastThreadLocal.get();
                logger.info("[class]{}", poolThreadCache.getClass());
                Field param = FieldUtils.getField(poolThreadCache.getClass(), "freeSweepAllocationThreshold", true);
                logger.info("[{}]", param.get(poolThreadCache));
                freeSweepAllocationThreshold.set(param.get(poolThreadCache));
            } catch (IllegalAccessException e) {
                logger.error("", e);
            }
            latch.countDown();
        }
    });
    latch.await();
    Assert.assertNotNull(freeSweepAllocationThreshold.get());
    Assert.assertNotEquals(0, freeSweepAllocationThreshold.get());
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) PooledByteBufAllocator(io.netty.buffer.PooledByteBufAllocator) NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) Field(java.lang.reflect.Field) PooledObject(org.apache.commons.pool2.PooledObject) FastThreadLocal(io.netty.util.concurrent.FastThreadLocal) AbstractRedisTest(com.ctrip.xpipe.redis.core.AbstractRedisTest)

Example 27 with PooledByteBufAllocator

use of io.netty.buffer.PooledByteBufAllocator in project duangframework by tcrct.

the class BootStrap method init.

private void init() {
    // loadLibrary();
    try {
        bossGroup = EventLoopGroupFactory.builderBossLoopGroup();
        workerGroup = EventLoopGroupFactory.builderWorkerLoopGroup();
        allocator = new PooledByteBufAllocator(PlatformDependent.directBufferPreferred());
    } catch (Exception e) {
        throw new EmptyNullException(e.getMessage(), e);
    }
}
Also used : EmptyNullException(com.duangframework.core.exceptions.EmptyNullException) EmptyNullException(com.duangframework.core.exceptions.EmptyNullException) PooledByteBufAllocator(io.netty.buffer.PooledByteBufAllocator)

Example 28 with PooledByteBufAllocator

use of io.netty.buffer.PooledByteBufAllocator in project redisson by redisson.

the class JsonJacksonMapValueCodecTest method shouldDeserializeTheStringCorrectly.

@Test
public void shouldDeserializeTheStringCorrectly() throws Exception {
    ByteBuf buf = new PooledByteBufAllocator(true).buffer();
    buf.writeBytes(new ObjectMapper().writeValueAsBytes("axk"));
    assertThat(stringCodec.getMapValueDecoder().decode(buf, new State(false))).isInstanceOf(String.class).isEqualTo("axk");
}
Also used : State(org.redisson.client.handler.State) ByteBuf(io.netty.buffer.ByteBuf) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PooledByteBufAllocator(io.netty.buffer.PooledByteBufAllocator) Test(org.junit.Test)

Example 29 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 30 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)60 Test (org.junit.Test)37 LocalAddress (io.netty.channel.local.LocalAddress)29 ByteBuf (io.netty.buffer.ByteBuf)28 HttpInitiator (org.jocean.http.client.HttpClient.HttpInitiator)25 Subscription (rx.Subscription)25 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)24 HttpTrade (org.jocean.http.server.HttpServerBuilder.HttpTrade)24 DisposableWrapper (org.jocean.idiom.DisposableWrapper)20 IOException (java.io.IOException)18 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)17 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)17 ConnectException (java.net.ConnectException)17 CertificateException (java.security.cert.CertificateException)17 SSLException (javax.net.ssl.SSLException)17 TransportException (org.jocean.http.TransportException)17 TestSubscriber (rx.observers.TestSubscriber)16 Channel (io.netty.channel.Channel)9 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)9 DefaultHttpRequest (io.netty.handler.codec.http.DefaultHttpRequest)8