ByteBufAllocatorBenchmark Class — netty Architecture
Architecture documentation for the ByteBufAllocatorBenchmark class in ByteBufAllocatorBenchmark.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD b790eb42_4bb8_2c60_030a_589908a419ad["ByteBufAllocatorBenchmark"] c4726455_b736_4dc6_fc76_6386d68ed250["ByteBufAllocatorBenchmark.java"] b790eb42_4bb8_2c60_030a_589908a419ad -->|defined in| c4726455_b736_4dc6_fc76_6386d68ed250 dee07766_8a73_7f50_0bd7_3e8aa75c5c54["nextIndex()"] b790eb42_4bb8_2c60_030a_589908a419ad -->|method| dee07766_8a73_7f50_0bd7_3e8aa75c5c54 d0f766c8_5fff_431e_8ee2_f5dabc063115["releaseBuffers()"] b790eb42_4bb8_2c60_030a_589908a419ad -->|method| d0f766c8_5fff_431e_8ee2_f5dabc063115 e5aa195c_cc70_a7aa_4698_bb9f0ca29fc7["unpooledHeapAllocAndFree()"] b790eb42_4bb8_2c60_030a_589908a419ad -->|method| e5aa195c_cc70_a7aa_4698_bb9f0ca29fc7 c04b51f3_c0f4_8915_e0fc_1a3f72c57f9d["unpooledDirectAllocAndFree()"] b790eb42_4bb8_2c60_030a_589908a419ad -->|method| c04b51f3_c0f4_8915_e0fc_1a3f72c57f9d 8a1b156b_a8d3_1d65_2c0b_3830334df130["pooledHeapAllocAndFree()"] b790eb42_4bb8_2c60_030a_589908a419ad -->|method| 8a1b156b_a8d3_1d65_2c0b_3830334df130 09111248_611d_bdc0_1317_176db01f50ce["pooledDirectAllocAndFree()"] b790eb42_4bb8_2c60_030a_589908a419ad -->|method| 09111248_611d_bdc0_1317_176db01f50ce 6dc4cf83_d4ff_36e8_ad92_e1a651ede9db["defaultPooledHeapAllocAndFree()"] b790eb42_4bb8_2c60_030a_589908a419ad -->|method| 6dc4cf83_d4ff_36e8_ad92_e1a651ede9db 00a78ca8_4fad_daaf_ec78_ade735637ba7["defaultPooledDirectAllocAndFree()"] b790eb42_4bb8_2c60_030a_589908a419ad -->|method| 00a78ca8_4fad_daaf_ec78_ade735637ba7 c420938a_4e1f_9db1_8f1e_cdeefaec34b1["adaptiveHeapAllocAndFree()"] b790eb42_4bb8_2c60_030a_589908a419ad -->|method| c420938a_4e1f_9db1_8f1e_cdeefaec34b1 4dd2df73_f898_8055_225e_14e28f8b9d3a["adaptiveDirectAllocAndFree()"] b790eb42_4bb8_2c60_030a_589908a419ad -->|method| 4dd2df73_f898_8055_225e_14e28f8b9d3a
Relationship Graph
Source Code
microbench/src/main/java/io/netty/microbench/buffer/ByteBufAllocatorBenchmark.java lines 37–181
@State(Scope.Benchmark)
public class ByteBufAllocatorBenchmark extends AbstractMicrobenchmark {
private static final ByteBufAllocator unpooledAllocator = new UnpooledByteBufAllocator(true);
private static final ByteBufAllocator pooledAllocator =
new PooledByteBufAllocator(true, 4, 4, 8192, 11, 0, 0, 0, true, 0);
private static final ByteBufAllocator adaptiveAllocator = new AdaptiveByteBufAllocator();
private static final int MAX_LIVE_BUFFERS = 8192;
private static final ByteBuf[] unpooledHeapBuffers = new ByteBuf[MAX_LIVE_BUFFERS];
private static final ByteBuf[] unpooledDirectBuffers = new ByteBuf[MAX_LIVE_BUFFERS];
private static final ByteBuf[] pooledHeapBuffers = new ByteBuf[MAX_LIVE_BUFFERS];
private static final ByteBuf[] pooledDirectBuffers = new ByteBuf[MAX_LIVE_BUFFERS];
private static final ByteBuf[] defaultPooledHeapBuffers = new ByteBuf[MAX_LIVE_BUFFERS];
private static final ByteBuf[] defaultPooledDirectBuffers = new ByteBuf[MAX_LIVE_BUFFERS];
private static final ByteBuf[] adaptiveHeapBuffers = new ByteBuf[MAX_LIVE_BUFFERS];
private static final ByteBuf[] adaptiveDirectBuffers = new ByteBuf[MAX_LIVE_BUFFERS];
@Param({
"00000",
"00256",
"01024",
"04096",
"16384",
"65536",
})
public int size;
private static final short[] NEXT_INDEXES = new short[128 * 1024];
private static final int NEXT_INDEX_MASK = NEXT_INDEXES.length - 1;
private int nextIndex;
static {
Random r = new Random();
r.setSeed(42);
for (int i = 0; i < NEXT_INDEXES.length; i++) {
NEXT_INDEXES[i] = (short) r.nextInt(MAX_LIVE_BUFFERS);
}
}
private int nextIndex() {
this.nextIndex = (nextIndex + 1) & NEXT_INDEX_MASK;
return NEXT_INDEXES[nextIndex];
}
@TearDown
public void releaseBuffers() {
List<ByteBuf[]> bufferLists = Arrays.asList(
unpooledHeapBuffers,
unpooledDirectBuffers,
pooledHeapBuffers,
pooledDirectBuffers,
defaultPooledHeapBuffers,
defaultPooledDirectBuffers,
adaptiveHeapBuffers,
adaptiveDirectBuffers);
for (ByteBuf[] bufs : bufferLists) {
for (ByteBuf buf : bufs) {
if (buf != null && buf.refCnt() > 0) {
buf.release();
}
}
Arrays.fill(bufs, null);
}
}
@Benchmark
public void unpooledHeapAllocAndFree() {
int idx = nextIndex();
ByteBuf oldBuf = unpooledHeapBuffers[idx];
if (oldBuf != null) {
oldBuf.release();
}
unpooledHeapBuffers[idx] = unpooledAllocator.heapBuffer(size);
}
@Benchmark
public void unpooledDirectAllocAndFree() {
int idx = nextIndex();
ByteBuf oldBuf = unpooledDirectBuffers[idx];
if (oldBuf != null) {
oldBuf.release();
Source
Frequently Asked Questions
What is the ByteBufAllocatorBenchmark class?
ByteBufAllocatorBenchmark is a class in the netty codebase, defined in microbench/src/main/java/io/netty/microbench/buffer/ByteBufAllocatorBenchmark.java.
Where is ByteBufAllocatorBenchmark defined?
ByteBufAllocatorBenchmark is defined in microbench/src/main/java/io/netty/microbench/buffer/ByteBufAllocatorBenchmark.java at line 37.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free