RandomSizeByteBufAllocationBenchmark Class — netty Architecture
Architecture documentation for the RandomSizeByteBufAllocationBenchmark class in RandomSizeByteBufAllocationBenchmark.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 8839dc57_30e1_9514_ff04_baa254ce09fc["RandomSizeByteBufAllocationBenchmark"] 52902e04_6ad3_f91f_d027_a9f90cc15e8f["RandomSizeByteBufAllocationBenchmark.java"] 8839dc57_30e1_9514_ff04_baa254ce09fc -->|defined in| 52902e04_6ad3_f91f_d027_a9f90cc15e8f ac43d053_55dd_7df8_1331_931e702fcb96["init()"] 8839dc57_30e1_9514_ff04_baa254ce09fc -->|method| ac43d053_55dd_7df8_1331_931e702fcb96 62a3538f_bbd9_5546_d30b_7d39e1fb54a0["nextSize()"] 8839dc57_30e1_9514_ff04_baa254ce09fc -->|method| 62a3538f_bbd9_5546_d30b_7d39e1fb54a0 6b274d37_3ef9_943a_4ef3_0d4cfd6cd5f8["allocateAndRelease()"] 8839dc57_30e1_9514_ff04_baa254ce09fc -->|method| 6b274d37_3ef9_943a_4ef3_0d4cfd6cd5f8
Relationship Graph
Source Code
microbench/src/main/java/io/netty/microbench/buffer/RandomSizeByteBufAllocationBenchmark.java lines 41–136
@State(Scope.Thread)
@Warmup(iterations = 10, time = 1)
@Measurement(iterations = 10, time = 1)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public class RandomSizeByteBufAllocationBenchmark extends AbstractMicrobenchmark {
private static final int SEED = 42;
// see adaptive allocator size classes
private static final int[] SIZE_CLASSES = {
32,
64,
128,
256,
512,
640, // 512 + 128
1024,
1152, // 1024 + 128
2048,
2304, // 2048 + 256
4096,
4352, // 4096 + 256
8192,
8704, // 8192 + 512
16384,
16896, // 16384 + 512
};
public enum AllocatorType {
JEMALLOC,
ADAPTIVE
}
@Param({ "ADAPTIVE" })
public AllocatorType allocatorType = AllocatorType.ADAPTIVE;
@Param({ "128", "128000" })
public int samples;
private ByteBufAllocator allocator;
private short[] sizeSamples;
private int sampleMask;
private int nextSampleIndex;
static {
ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.DISABLED);
}
@Setup
public void init() {
if (!(Thread.currentThread() instanceof FastThreadLocalThread)) {
throw new IllegalStateException("This benchmark must be run with FastThreadLocalThread: run it with: " +
"-Djmh.executor=CUSTOM -Djmh.executor.class=io.netty.microbench.util.AbstractMicrobenchmark$HarnessExecutor");
}
switch (allocatorType) {
case JEMALLOC:
allocator = new PooledByteBufAllocator(true);
break;
case ADAPTIVE:
allocator = new AdaptiveByteBufAllocator(true, true);
break;
default:
throw new IllegalArgumentException("Unknown allocator type: " + allocatorType);
}
samples = MathUtil.findNextPositivePowerOfTwo(samples);
sampleMask = samples - 1;
sizeSamples = new short[samples];
SplittableRandom rnd = new SplittableRandom(SEED);
// here we're not using random size [0, 16896] because if the size class is too large
// it has more chances to be picked!
for (int i = 0; i < samples; i++) {
// pick a random size class
int sizeClass = rnd.nextInt(SIZE_CLASSES.length);
// now pick a random size within the size class
short size =
(short) rnd.nextInt(sizeClass == 0? 0 : SIZE_CLASSES[sizeClass - 1] + 1, SIZE_CLASSES[sizeClass]);
if (size < 0) {
throw new IllegalArgumentException("Size sample out of range: " + size);
}
sizeSamples[i] = size;
}
}
Defined In
Source
Frequently Asked Questions
What is the RandomSizeByteBufAllocationBenchmark class?
RandomSizeByteBufAllocationBenchmark is a class in the netty codebase, defined in microbench/src/main/java/io/netty/microbench/buffer/RandomSizeByteBufAllocationBenchmark.java.
Where is RandomSizeByteBufAllocationBenchmark defined?
RandomSizeByteBufAllocationBenchmark is defined in microbench/src/main/java/io/netty/microbench/buffer/RandomSizeByteBufAllocationBenchmark.java at line 41.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free