Home / Function/ setup() — netty Function Reference

setup() — netty Function Reference

Architecture documentation for the setup() function in FastThreadLocalCheckBenchmark.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  6a4231b5_eb93_98d7_9078_a12fb73ccbb9["setup()"]
  e7b3ad36_fa43_0236_b340_e70e8b4b6a79["FastThreadLocalCheckBenchmark"]
  6a4231b5_eb93_98d7_9078_a12fb73ccbb9 -->|defined in| e7b3ad36_fa43_0236_b340_e70e8b4b6a79
  7ef6d655_01a1_776b_b76a_80d166b6d4b4["getId()"]
  6a4231b5_eb93_98d7_9078_a12fb73ccbb9 -->|calls| 7ef6d655_01a1_776b_b76a_80d166b6d4b4
  f7239007_116f_baf0_e178_5c18d0baaa2c["FastThreadLocalThread()"]
  6a4231b5_eb93_98d7_9078_a12fb73ccbb9 -->|calls| f7239007_116f_baf0_e178_5c18d0baaa2c
  fb846528_251b_6622_6b01_d49e3744608e["run()"]
  6a4231b5_eb93_98d7_9078_a12fb73ccbb9 -->|calls| fb846528_251b_6622_6b01_d49e3744608e
  style 6a4231b5_eb93_98d7_9078_a12fb73ccbb9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

microbench/src/main/java/io/netty/microbench/concurrent/FastThreadLocalCheckBenchmark.java lines 51–106

    @Setup
    public void setup() {
        if (Thread.currentThread() instanceof FastThreadLocalThread) {
            throw new IllegalStateException("This benchmark must not be run in a FastThreadLocalThread");
        }

        long benchmarkThreadId = Thread.currentThread().getId();
        // create an ordered array of thread IDs which cause the maximum number of branches
        // but still making it fairly predictable for the CPU.
        long[] eventLoopIds = new long[eventLoops];
        for (int i = 0; i < eventLoops; i++) {
            eventLoopIds[i] = benchmarkThreadId + i + 1;
        }

        eventLoopControl = new CountDownLatch(1);
        CountDownLatch eventLoopsRegistered = new CountDownLatch(eventLoops);
        eventLoopThreads = new Thread[eventLoops];

        class FastThreadLocalThread extends Thread {
            private final long id;

            FastThreadLocalThread(long id) {
                this.id = id;
            }

            @Override
            public long getId() {
                return id;
            }

            @Override
            public void run() {
                io.netty.util.concurrent.FastThreadLocalThread.runWithFastThreadLocal(() -> {
                    try {
                        eventLoopsRegistered.countDown();
                        eventLoopControl.await();
                    } catch (InterruptedException e) {
                        // ignore
                    }
                });
            }
        }

        int i = 0;
        for (long eventLoopId : eventLoopIds) {
            FastThreadLocalThread thread = new FastThreadLocalThread(eventLoopId);
            thread.start();
            eventLoopThreads[i++] = thread;
        }

        try {
            eventLoopsRegistered.await();
        } catch (InterruptedException e) {
            // wait till all event loops are registered.
        }
    }

Domain

Subdomains

Frequently Asked Questions

What does setup() do?
setup() is a function in the netty codebase, defined in microbench/src/main/java/io/netty/microbench/concurrent/FastThreadLocalCheckBenchmark.java.
Where is setup() defined?
setup() is defined in microbench/src/main/java/io/netty/microbench/concurrent/FastThreadLocalCheckBenchmark.java at line 51.
What does setup() call?
setup() calls 3 function(s): FastThreadLocalThread, getId, run.

Analyze Your Own Codebase

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

Try Supermodel Free