ByteBufAllocateAndGrowBenchmark Class — netty Architecture
Architecture documentation for the ByteBufAllocateAndGrowBenchmark class in ByteBufAllocateAndGrowBenchmark.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD fc3b0965_3296_b97f_be0e_37f95bff98b5["ByteBufAllocateAndGrowBenchmark"] d7307643_9e24_b21a_6fec_940adfa7d66b["ByteBufAllocateAndGrowBenchmark.java"] fc3b0965_3296_b97f_be0e_37f95bff98b5 -->|defined in| d7307643_9e24_b21a_6fec_940adfa7d66b 35b52d90_c269_ae0c_8b59_6cf224582d47["releaseBuffers()"] fc3b0965_3296_b97f_be0e_37f95bff98b5 -->|method| 35b52d90_c269_ae0c_8b59_6cf224582d47 af6e2cdc_c78e_15ef_a256_bad00644c759["pooledDirectAllocAndFree()"] fc3b0965_3296_b97f_be0e_37f95bff98b5 -->|method| af6e2cdc_c78e_15ef_a256_bad00644c759 6f6a8961_fab9_3259_48b7_ba057361aea0["adaptiveDirectAllocAndFree()"] fc3b0965_3296_b97f_be0e_37f95bff98b5 -->|method| 6f6a8961_fab9_3259_48b7_ba057361aea0 0682dd35_0259_0d96_91dc_bd05b7e40d1b["expandBuffer()"] fc3b0965_3296_b97f_be0e_37f95bff98b5 -->|method| 0682dd35_0259_0d96_91dc_bd05b7e40d1b
Relationship Graph
Source Code
microbench/src/main/java/io/netty/microbench/buffer/ByteBufAllocateAndGrowBenchmark.java lines 37–125
@State(Scope.Benchmark)
public class ByteBufAllocateAndGrowBenchmark extends AbstractMicrobenchmark {
private static final ByteBufAllocator pooledAllocator = PooledByteBufAllocator.DEFAULT;
private static final ByteBufAllocator adaptiveAllocator = new AdaptiveByteBufAllocator();
private static final int MAX_LIVE_BUFFERS = 2048;
private static final Random rand = new Random();
private static final ByteBuf[] pooledDirectBuffers = new ByteBuf[MAX_LIVE_BUFFERS];
private static final ByteBuf[] adaptiveDirectBuffers = new ByteBuf[MAX_LIVE_BUFFERS];
@Param({
"00256",
"01024",
"04096",
"16384",
"65536",
})
public int size;
@TearDown
public void releaseBuffers() {
List<ByteBuf[]> bufferLists = Arrays.asList(
pooledDirectBuffers,
adaptiveDirectBuffers);
for (ByteBuf[] bufs : bufferLists) {
for (ByteBuf buf : bufs) {
if (buf != null && buf.refCnt() > 0) {
buf.release();
}
}
Arrays.fill(bufs, null);
}
}
@Benchmark
public void pooledDirectAllocAndFree(BufStats stats) {
int idx = rand.nextInt(pooledDirectBuffers.length);
ByteBuf oldBuf = pooledDirectBuffers[idx];
if (oldBuf != null) {
oldBuf.release();
}
ByteBuf buf = pooledAllocator.directBuffer();
expandBuffer(buf, stats);
pooledDirectBuffers[idx] = buf;
}
@Benchmark
public void adaptiveDirectAllocAndFree(BufStats stats) {
int idx = rand.nextInt(adaptiveDirectBuffers.length);
ByteBuf oldBuf = adaptiveDirectBuffers[idx];
if (oldBuf != null) {
oldBuf.release();
}
ByteBuf buf = adaptiveAllocator.directBuffer();
expandBuffer(buf, stats);
adaptiveDirectBuffers[idx] = buf;
}
private void expandBuffer(ByteBuf buf, BufStats stats) {
stats.record(buf);
while (buf.capacity() < size) {
buf.capacity(2 * buf.capacity());
stats.record(buf);
}
}
@State(Scope.Thread)
@AuxCounters
public static class BufStats {
long bufCounts;
long bufSizeSum;
long bufFastCapSum;
void record(ByteBuf byteBuf) {
bufCounts++;
bufSizeSum += byteBuf.capacity();
bufFastCapSum += byteBuf.maxFastWritableBytes();
}
public double avgSize() {
Source
Frequently Asked Questions
What is the ByteBufAllocateAndGrowBenchmark class?
ByteBufAllocateAndGrowBenchmark is a class in the netty codebase, defined in microbench/src/main/java/io/netty/microbench/buffer/ByteBufAllocateAndGrowBenchmark.java.
Where is ByteBufAllocateAndGrowBenchmark defined?
ByteBufAllocateAndGrowBenchmark is defined in microbench/src/main/java/io/netty/microbench/buffer/ByteBufAllocateAndGrowBenchmark.java at line 37.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free