Home / Class/ Workload Class — netty Architecture

Workload Class — netty Architecture

Architecture documentation for the Workload class in AllocationPatternSimulator.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  205b6069_4dbe_3fcd_334a_3a81de7610c1["Workload"]
  c9fb080e_e943_3d97_be1a_c8039258e2c5["AllocationPatternSimulator.java"]
  205b6069_4dbe_3fcd_334a_3a81de7610c1 -->|defined in| c9fb080e_e943_3d97_be1a_c8039258e2c5
  74f5b87f_4178_e388_8bee_4b0ac247cbd6["Workload()"]
  205b6069_4dbe_3fcd_334a_3a81de7610c1 -->|method| 74f5b87f_4178_e388_8bee_4b0ac247cbd6
  ef01c0dd_bbff_64e8_22c1_97f0b0b02b87["Thread()"]
  205b6069_4dbe_3fcd_334a_3a81de7610c1 -->|method| ef01c0dd_bbff_64e8_22c1_97f0b0b02b87
  06934b47_b83d_1faa_16c1_8d69d2ca2fd8["run()"]
  205b6069_4dbe_3fcd_334a_3a81de7610c1 -->|method| 06934b47_b83d_1faa_16c1_8d69d2ca2fd8

Relationship Graph

Source Code

microbench/src/main/java/io/netty/buffer/AllocationPatternSimulator.java lines 606–662

    private final class Workload implements Runnable {
        private final CountDownLatch startLatch;
        private final ByteBufAllocator allocator;
        private final SplittableRandom rng;
        private final AtomicBoolean stopCondition;
        private final int avgLiveBuffers;

        private Workload(CountDownLatch startLatch,
                         ByteBufAllocator allocator,
                         SplittableRandom rng,
                         AtomicBoolean stopCondition,
                         int avgLiveBuffers) {
            this.startLatch = startLatch;
            this.allocator = allocator;
            this.rng = rng;
            this.stopCondition = stopCondition;
            this.avgLiveBuffers = avgLiveBuffers;
        }

        Thread start(String name) {
            Thread thread = new Thread(this, name + '-' + THREAD_NAMES.compute(name, (n, c) -> c == null ? 1 : c + 1));
            thread.start();
            return thread;
        }

        @SuppressWarnings("BusyWait")
        @Override
        public void run() {
            try {
                startLatch.await();
                List<ByteBuf> buffers = new ArrayList<>();
                while (!stopCondition.get()) {
                    Thread.sleep(1);

                    int freqChoice = rng.nextInt(0, sumFrequency);
                    int choiceIndex = Arrays.binarySearch(cumulativeFrequency, freqChoice);
                    if (choiceIndex < 0) {
                        choiceIndex = -(choiceIndex + 1);
                    }
                    int chosenSize = size[choiceIndex];
                    ByteBuf buf = allocator.heapBuffer(chosenSize);
                    buffers.add(buf);
                    while (buffers.size() > rng.nextInt(0, avgLiveBuffers << 1)) {
                        int deallocChoice = rng.nextInt(0, buffers.size());
                        ByteBuf toDealloc = buffers.get(deallocChoice);
                        ByteBuf lastBuffer = buffers.remove(buffers.size() - 1);
                        if (toDealloc != lastBuffer) {
                            buffers.set(deallocChoice, lastBuffer);
                        }
                        toDealloc.release();
                    }
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free