FastThreadLocalCheckBenchmark Class — netty Architecture
Architecture documentation for the FastThreadLocalCheckBenchmark class in FastThreadLocalCheckBenchmark.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD e7b3ad36_fa43_0236_b340_e70e8b4b6a79["FastThreadLocalCheckBenchmark"] 5f78a57e_362c_33ee_8743_51f248a052d1["FastThreadLocalCheckBenchmark.java"] e7b3ad36_fa43_0236_b340_e70e8b4b6a79 -->|defined in| 5f78a57e_362c_33ee_8743_51f248a052d1 a48c40a4_1e40_4e7c_d122_fada001f195a["FastThreadLocalCheckBenchmark()"] e7b3ad36_fa43_0236_b340_e70e8b4b6a79 -->|method| a48c40a4_1e40_4e7c_d122_fada001f195a 6a4231b5_eb93_98d7_9078_a12fb73ccbb9["setup()"] e7b3ad36_fa43_0236_b340_e70e8b4b6a79 -->|method| 6a4231b5_eb93_98d7_9078_a12fb73ccbb9 ec35518f_856e_991d_97df_0150517e6b0a["isFastThreadLocalThread()"] e7b3ad36_fa43_0236_b340_e70e8b4b6a79 -->|method| ec35518f_856e_991d_97df_0150517e6b0a edfe07a7_04e8_91d2_785d_9e4f3c599138["tearDown()"] e7b3ad36_fa43_0236_b340_e70e8b4b6a79 -->|method| edfe07a7_04e8_91d2_785d_9e4f3c599138
Relationship Graph
Source Code
microbench/src/main/java/io/netty/microbench/concurrent/FastThreadLocalCheckBenchmark.java lines 35–124
@Measurement(iterations = 10)
@Warmup(iterations = 10)
@BenchmarkMode(Mode.AverageTime)
@State(Scope.Thread)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public class FastThreadLocalCheckBenchmark extends AbstractMicrobenchmark {
@Param({ "8", "16", "32", "64", "128", "256"})
public int eventLoops;
private Thread[] eventLoopThreads;
private CountDownLatch eventLoopControl;
public FastThreadLocalCheckBenchmark() {
super(true, true);
}
@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.
}
}
@Benchmark
public boolean isFastThreadLocalThread() {
return FastThreadLocalThread.currentThreadHasFastThreadLocal();
}
@TearDown
public void tearDown() {
eventLoopControl.countDown();
Defined In
Source
Frequently Asked Questions
What is the FastThreadLocalCheckBenchmark class?
FastThreadLocalCheckBenchmark is a class in the netty codebase, defined in microbench/src/main/java/io/netty/microbench/concurrent/FastThreadLocalCheckBenchmark.java.
Where is FastThreadLocalCheckBenchmark defined?
FastThreadLocalCheckBenchmark is defined in microbench/src/main/java/io/netty/microbench/concurrent/FastThreadLocalCheckBenchmark.java at line 35.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free