Home / Class/ ByteBufAllocatorAllocPatternBenchmark Class — netty Architecture

ByteBufAllocatorAllocPatternBenchmark Class — netty Architecture

Architecture documentation for the ByteBufAllocatorAllocPatternBenchmark class in ByteBufAllocatorAllocPatternBenchmark.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  e4bd297f_3f76_67a0_e907_259f9a219484["ByteBufAllocatorAllocPatternBenchmark"]
  7d4fb9c8_3875_0393_13aa_871ca0c13647["ByteBufAllocatorAllocPatternBenchmark.java"]
  e4bd297f_3f76_67a0_e907_259f9a219484 -->|defined in| 7d4fb9c8_3875_0393_13aa_871ca0c13647
  08c39d59_9fc8_19d0_9a47_4c56e7a2655c["setupAllocatorAndPollute()"]
  e4bd297f_3f76_67a0_e907_259f9a219484 -->|method| 08c39d59_9fc8_19d0_9a47_4c56e7a2655c
  83b8f5ad_dc34_b057_6ee1_bb35f69b39e1["directAllocation()"]
  e4bd297f_3f76_67a0_e907_259f9a219484 -->|method| 83b8f5ad_dc34_b057_6ee1_bb35f69b39e1
  f3d1b2b3_f386_f527_48d5_e70dc0e65156["heapAllocation()"]
  e4bd297f_3f76_67a0_e907_259f9a219484 -->|method| f3d1b2b3_f386_f527_48d5_e70dc0e65156
  79187440_a514_4684_912d_c91809fa2cb8["ByteBufAllocatorAllocPatternBenchmark()"]
  e4bd297f_3f76_67a0_e907_259f9a219484 -->|method| 79187440_a514_4684_912d_c91809fa2cb8

Relationship Graph

Source Code

microbench/src/main/java/io/netty/microbench/buffer/ByteBufAllocatorAllocPatternBenchmark.java lines 45–629

@Warmup(iterations = 10, time = 1)
@Measurement(iterations = 10, time = 1)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Benchmark)
@BenchmarkMode(Mode.AverageTime)
@Threads(1)
public class ByteBufAllocatorAllocPatternBenchmark extends AbstractMicrobenchmark {

    public enum AllocatorType {
        ADAPTIVE(AdaptiveByteBufAllocator::new),
        POOLED(() -> PooledByteBufAllocator.DEFAULT);

        private final Supplier<ByteBufAllocator> factory;

        AllocatorType(Supplier<ByteBufAllocator> factory) {
            this.factory = factory;
        }

        private ByteBufAllocator create() {
            return factory.get();
        }
    }

    @Param({ "ADAPTIVE" })
    public AllocatorType allocatorType;

    @Param({ "0", "200000" })
    public int pollutionIterations;

    private ByteBufAllocator allocator;

    @State(Scope.Thread)
    public static class AllocationPatternState {
        private int[] releaseIndexes;
        private int[] sizes;
        private int nextReleaseIndex;
        private int nextSizeIndex;
        private ByteBuf[] buffers;
        private ByteBufAllocator allocator;

        @Setup
        public void setup(ByteBufAllocatorAllocPatternBenchmark benchmark) {
            this.allocator = benchmark.allocator;
            releaseIndexes = new int[MAX_LIVE_BUFFERS];
            sizes = new int[MathUtil.findNextPositivePowerOfTwo(FLATTEND_SIZE_ARRAY.length)];
            SplittableRandom rand = new SplittableRandom(SEED);
            // Pre-generate the to be released index.
            for (int i = 0; i < releaseIndexes.length; i++) {
                releaseIndexes[i] = rand.nextInt(releaseIndexes.length);
            }
            // Shuffle the `flattendSizeArray` to `sizes`.
            for (int i = 0; i < sizes.length; i++) {
                int sizeIndex = rand.nextInt(FLATTEND_SIZE_ARRAY.length);
                sizes[i] = FLATTEND_SIZE_ARRAY[sizeIndex];
            }
            nextReleaseIndex = 0;
            nextSizeIndex = 0;
            buffers = new ByteBuf[MAX_LIVE_BUFFERS];
        }

        private int getNextReleaseIndex() {
            int index = nextReleaseIndex;
            nextReleaseIndex = (nextReleaseIndex + 1) & (releaseIndexes.length - 1);
            return releaseIndexes[index];
        }

        private int getNextSizeIndex() {
            int index = nextSizeIndex;
            nextSizeIndex = (nextSizeIndex + 1) & (sizes.length - 1);
            return index;
        }

        @CompilerControl(CompilerControl.Mode.DONT_INLINE)
        private static void release(ByteBuf buf) {
            buf.release();
        }

        @CompilerControl(CompilerControl.Mode.DONT_INLINE)
        private static ByteBuf allocateHeap(ByteBufAllocator allocator, int size) {
            return allocator.heapBuffer(size);
        }

Frequently Asked Questions

What is the ByteBufAllocatorAllocPatternBenchmark class?
ByteBufAllocatorAllocPatternBenchmark is a class in the netty codebase, defined in microbench/src/main/java/io/netty/microbench/buffer/ByteBufAllocatorAllocPatternBenchmark.java.
Where is ByteBufAllocatorAllocPatternBenchmark defined?
ByteBufAllocatorAllocPatternBenchmark is defined in microbench/src/main/java/io/netty/microbench/buffer/ByteBufAllocatorAllocPatternBenchmark.java at line 45.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free