Skip to content

Commit 791a463

Browse files
committed
Update the benchmarks and remove LoomSupport features
1 parent effe5f1 commit 791a463

6 files changed

Lines changed: 56 additions & 268 deletions

File tree

benchmarks/src/main/java/io/netty/loom/benchmark/GetCarrierThread.java

Lines changed: 0 additions & 62 deletions
This file was deleted.

benchmarks/src/main/java/io/netty/loom/benchmark/GetScheduler.java

Lines changed: 0 additions & 41 deletions
This file was deleted.

benchmarks/src/main/java/io/netty/loom/benchmark/NettySchedulerBenchmark.java

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.netty.loom.benchmark;
22

33
import io.netty.channel.nio.NioIoHandler;
4-
import io.netty.loom.LoomSupport;
54
import io.netty.loom.VirtualMultithreadIoEventLoopGroup;
65
import org.openjdk.jmh.annotations.Benchmark;
76
import org.openjdk.jmh.annotations.BenchmarkMode;
@@ -15,6 +14,7 @@
1514
import org.openjdk.jmh.annotations.State;
1615
import org.openjdk.jmh.annotations.TearDown;
1716
import org.openjdk.jmh.annotations.Warmup;
17+
import org.openjdk.jmh.infra.BenchmarkParams;
1818

1919
import java.util.concurrent.CountDownLatch;
2020
import java.util.concurrent.ExecutionException;
@@ -25,9 +25,6 @@
2525
@OutputTimeUnit(TimeUnit.MILLISECONDS)
2626
@Warmup(iterations = 3, time = 1)
2727
@Measurement(iterations = 5, time = 1)
28-
@Fork(value = 2, jvmArgs = {"--add-opens=java.base/java.lang=ALL-UNNAMED", "-XX:+UnlockExperimentalVMOptions",
29-
"-XX:-DoJVMTIVirtualThreadTransitions", "-Djdk.trackAllThreads=false",
30-
"-Djdk.virtualThreadScheduler.implClass=io.netty.loom.NettyScheduler"})
3128
@State(Scope.Thread)
3229
public class NettySchedulerBenchmark {
3330

@@ -39,13 +36,18 @@ public class NettySchedulerBenchmark {
3936
private ThreadFactory vtFactory;
4037

4138
@Setup
42-
public void setup() throws ExecutionException, InterruptedException {
43-
executorGroup = new VirtualMultithreadIoEventLoopGroup(1, NioIoHandler.newFactory());
44-
vtFactory = executorGroup.submit(executorGroup::vThreadFactory).get();
39+
public void setup(BenchmarkParams params) throws ExecutionException, InterruptedException {
40+
if (params.getBenchmark().contains("Netty")) {
41+
executorGroup = new VirtualMultithreadIoEventLoopGroup(1, NioIoHandler.newFactory());
42+
vtFactory = executorGroup.submit(executorGroup::vThreadFactory).get();
43+
}
4544
}
4645

4746
@Benchmark
48-
public void global() {
47+
@Fork(value = 2, jvmArgs = {"--add-opens=java.base/java.lang=ALL-UNNAMED", "-XX:+UnlockExperimentalVMOptions",
48+
"-XX:-DoJVMTIVirtualThreadTransitions", "-Djdk.trackAllThreads=false",
49+
"-Djdk.virtualThreadScheduler.implClass=io.netty.loom.NettyScheduler", "-Djdk.pollerMode=3"})
50+
public void scheduleToFjFromNetty() {
4951
CountDownLatch countDown = new CountDownLatch(tasks);
5052
vtFactory.newThread(() -> {
5153
for (int i = 0; i < tasks; i++) {
@@ -60,15 +62,49 @@ public void global() {
6062
}
6163

6264
@Benchmark
63-
public void inheritFromParent() {
65+
@Fork(value = 2, jvmArgs = {"--add-opens=java.base/java.lang=ALL-UNNAMED", "-XX:+UnlockExperimentalVMOptions",
66+
"-XX:-DoJVMTIVirtualThreadTransitions", "-Djdk.trackAllThreads=false"})
67+
public void scheduleToFjFromFjWithBuiltInScheduler() {
68+
CountDownLatch countDown = new CountDownLatch(tasks);
69+
Thread.startVirtualThread(() -> {
70+
for (int i = 0; i < tasks; i++) {
71+
Thread.startVirtualThread(countDown::countDown);
72+
}
73+
}).start();
74+
try {
75+
countDown.await();
76+
} catch (InterruptedException e) {
77+
throw new RuntimeException(e);
78+
}
79+
}
80+
81+
@Benchmark
82+
@Fork(value = 2, jvmArgs = {"--add-opens=java.base/java.lang=ALL-UNNAMED", "-XX:+UnlockExperimentalVMOptions",
83+
"-XX:-DoJVMTIVirtualThreadTransitions", "-Djdk.trackAllThreads=false",
84+
"-Djdk.virtualThreadScheduler.implClass=io.netty.loom.NettyScheduler", "-Djdk.pollerMode=3"})
85+
public void scheduleToFjFromFjWithCustomScheduler() {
86+
CountDownLatch countDown = new CountDownLatch(tasks);
87+
Thread.startVirtualThread(() -> {
88+
for (int i = 0; i < tasks; i++) {
89+
Thread.startVirtualThread(countDown::countDown);
90+
}
91+
}).start();
92+
try {
93+
countDown.await();
94+
} catch (InterruptedException e) {
95+
throw new RuntimeException(e);
96+
}
97+
}
98+
99+
@Benchmark
100+
@Fork(value = 2, jvmArgs = {"--add-opens=java.base/java.lang=ALL-UNNAMED", "-XX:+UnlockExperimentalVMOptions",
101+
"-XX:-DoJVMTIVirtualThreadTransitions", "-Djdk.trackAllThreads=false",
102+
"-Djdk.virtualThreadScheduler.implClass=io.netty.loom.NettyScheduler", "-Djdk.pollerMode=3"})
103+
public void scheduleToNettyFromNetty() {
64104
CountDownLatch countDown = new CountDownLatch(tasks);
65105
vtFactory.newThread(() -> {
66-
Thread.VirtualThreadScheduler parentScheduler = LoomSupport.getScheduler(Thread.currentThread());
67-
// Simulate the behavior of the previous version
68-
// get the scheduler from the parent thread before starting, instead of
69-
// pre-initializing the `vtFactory`.
70106
for (int i = 0; i < tasks; i++) {
71-
Thread.ofVirtual().scheduler(parentScheduler).start(countDown::countDown);
107+
vtFactory.newThread(countDown::countDown).start();
72108
}
73109
}).start();
74110
try {
@@ -80,6 +116,8 @@ public void inheritFromParent() {
80116

81117
@TearDown
82118
public void tearDown() {
83-
executorGroup.shutdownGracefully();
119+
if (executorGroup != null) {
120+
executorGroup.shutdownGracefully();
121+
}
84122
}
85123
}

benchmarks/src/main/java/io/netty/loom/benchmark/PollerBenchmark.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.openjdk.jmh.annotations.TearDown;
2727
import org.openjdk.jmh.annotations.Warmup;
2828

29-
import io.netty.loom.LoomSupport;
3029
import io.netty.util.internal.shaded.org.jctools.queues.MpscUnboundedArrayQueue;
3130

3231
/**
@@ -134,11 +133,11 @@ public void init() throws IOException, InterruptedException, BrokenBarrierExcept
134133
blockingReadTasks.add(task);
135134
LockSupport.unpark(carrierParked);
136135
};
137-
readThreadFactory = LoomSupport.setVirtualThreadFactoryScheduler(Thread.ofVirtual(), readScheduler).factory();
138-
writeThreadFactory = LoomSupport.setVirtualThreadFactoryScheduler(Thread.ofVirtual(), task -> {
136+
readThreadFactory = Thread.ofVirtual().scheduler(Thread.VirtualThreadScheduler.adapt(readScheduler)).factory();
137+
writeThreadFactory = Thread.ofVirtual().scheduler(Thread.VirtualThreadScheduler.adapt(task -> {
139138
blockingWriteTasks.add(task);
140139
LockSupport.unpark(carrierParked);
141-
}).factory();
140+
})).factory();
142141
clientIn = clientSocket.getInputStream();
143142
serverOut = serverSocket.getOutputStream();
144143
clientSocket.setTcpNoDelay(true);

core/src/main/java/io/netty/loom/LoomSupport.java

Lines changed: 0 additions & 122 deletions
This file was deleted.

core/src/test/java/io/netty/loom/LoomSupportTest.java

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)