use of io.netty.buffer.PooledByteBufAllocator in project incubator-pulsar by apache.
the class AllocatorStatsGenerator method generate.
public static AllocatorStats generate(String allocatorName) {
PooledByteBufAllocator allocator = null;
if ("default".equals(allocatorName)) {
allocator = PooledByteBufAllocator.DEFAULT;
} else if ("ml-cache".equals(allocatorName)) {
allocator = EntryCacheImpl.ALLOCATOR;
} else {
throw new IllegalArgumentException("Invalid allocator name : " + allocatorName);
}
AllocatorStats stats = new AllocatorStats();
stats.directArenas = allocator.metric().directArenas().stream().map(AllocatorStatsGenerator::newPoolArenaStats).collect(Collectors.toList());
stats.heapArenas = allocator.metric().heapArenas().stream().map(AllocatorStatsGenerator::newPoolArenaStats).collect(Collectors.toList());
stats.numDirectArenas = allocator.metric().numDirectArenas();
stats.numHeapArenas = allocator.metric().numHeapArenas();
stats.numThreadLocalCaches = allocator.metric().numThreadLocalCaches();
stats.normalCacheSize = allocator.metric().normalCacheSize();
stats.smallCacheSize = allocator.metric().smallCacheSize();
stats.tinyCacheSize = allocator.metric().tinyCacheSize();
return stats;
}
use of io.netty.buffer.PooledByteBufAllocator in project netty by netty.
the class AbstractSslEngineThroughputBenchmark method setup.
@Setup(Level.Iteration)
public final void setup() throws Exception {
ByteBufAllocator allocator = new PooledByteBufAllocator(true);
initEngines(allocator);
initHandshakeBuffers();
wrapDstBuffer = allocateBuffer(clientEngine.getSession().getPacketBufferSize() << 2);
wrapSrcBuffer = allocateBuffer(messageSize);
byte[] bytes = new byte[messageSize];
PlatformDependent.threadLocalRandom().nextBytes(bytes);
wrapSrcBuffer.put(bytes);
wrapSrcBuffer.flip();
// Complete the initial TLS handshake.
if (!doHandshake()) {
throw new IllegalStateException();
}
doSetup();
}
use of io.netty.buffer.PooledByteBufAllocator in project netty by netty.
the class PooledByteBufAllocatorAlignBenchmark method doSetup.
@Setup
public void doSetup() {
PooledByteBufAllocator pooledAllocator = new PooledByteBufAllocator(true, 4, 4, 8192, 11, 0, 0, 0, true, cacheAlign);
pooledDirectBuffer = pooledAllocator.directBuffer(size + 64);
sizeMask = size - 1;
if (cacheAlign == 0) {
long addr = pooledDirectBuffer.memoryAddress();
// make sure address is miss-aligned
if (addr % 64 == 0) {
alignOffset = 63;
}
int off = 0;
for (int c = 0; c < size; c++) {
off = (off + OFFSET_ADD) & sizeMask;
if ((addr + off + alignOffset) % BLOCK == 0) {
throw new IllegalStateException("Misaligned address is not really aligned");
}
}
} else {
alignOffset = 0;
int off = 0;
long addr = pooledDirectBuffer.memoryAddress();
for (int c = 0; c < size; c++) {
off = (off + OFFSET_ADD) & sizeMask;
if ((addr + off) % BLOCK != 0) {
throw new IllegalStateException("Aligned address is not really aligned");
}
}
}
bytes = new byte[BLOCK];
rand.nextBytes(bytes);
}
use of io.netty.buffer.PooledByteBufAllocator in project vert.x by eclipse.
the class VertxHandler method safeBuffer.
/**
* Copy and release the {@code buf} when necessary.
*
* <p> This methods assuming the has full ownership of the buffer.
*
* <p> This method assumes that pooled buffers are allocated by {@code PooledByteBufAllocator}
*
* <p> The returned buffer will not need to be released and can be wrapped by a {@link io.vertx.core.buffer.Buffer}.
*
* @param buf the buffer
* @return a safe buffer to use
*/
public static ByteBuf safeBuffer(ByteBuf buf) {
if (buf != Unpooled.EMPTY_BUFFER && (buf.alloc() instanceof PooledByteBufAllocator || buf instanceof CompositeByteBuf)) {
try {
if (buf.isReadable()) {
ByteBuf buffer = VertxByteBufAllocator.DEFAULT.heapBuffer(buf.readableBytes());
buffer.writeBytes(buf, buf.readerIndex(), buf.readableBytes());
return buffer;
} else {
return Unpooled.EMPTY_BUFFER;
}
} finally {
buf.release();
}
}
return buf;
}
use of io.netty.buffer.PooledByteBufAllocator in project spring-framework by spring-projects.
the class AbstractDataBufferAllocatingTests method verifyAllocations.
private void verifyAllocations() {
if (this.bufferFactory instanceof NettyDataBufferFactory) {
ByteBufAllocator allocator = ((NettyDataBufferFactory) this.bufferFactory).getByteBufAllocator();
if (allocator instanceof PooledByteBufAllocator) {
Instant start = Instant.now();
while (true) {
PooledByteBufAllocatorMetric metric = ((PooledByteBufAllocator) allocator).metric();
long total = getAllocations(metric.directArenas()) + getAllocations(metric.heapArenas());
if (total == 0) {
return;
}
if (Instant.now().isBefore(start.plus(Duration.ofSeconds(5)))) {
try {
Thread.sleep(50);
} catch (InterruptedException ex) {
// ignore
}
continue;
}
assertThat(total).as("ByteBuf Leak: " + total + " unreleased allocations").isEqualTo(0);
}
}
}
}
Aggregations