Skip to content

Commit d2f2da7

Browse files
committed
switch to java 21 and add option 'vt' to use virtual threads (#395)
1 parent f3e6bb8 commit d2f2da7

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
<properties>
1414
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15-
<java.version>17</java.version>
16-
<maven.compiler.source>17</maven.compiler.source>
17-
<maven.compiler.target>17</maven.compiler.target>
15+
<java.version>21</java.version>
16+
<maven.compiler.source>21</maven.compiler.source>
17+
<maven.compiler.target>21</maven.compiler.target>
1818
<buildDirectory>${project.basedir}/target</buildDirectory>
1919
<!--
2020
Provids a way to limit which assembly package formats we produce.

src/main/java/com/oltpbenchmark/DBWorkload.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ public static void main(String[] args) throws Exception {
8787
intervalMonitor = Integer.parseInt(argsLine.getOptionValue("im"));
8888
}
8989

90+
Boolean useVirtualThreads = false;
91+
if (argsLine.hasOption("vt")) {
92+
useVirtualThreads = Boolean.parseBoolean(argsLine.getOptionValue("vt"));
93+
}
94+
9095
// -------------------------------------------------------------------
9196
// GET PLUGIN LIST
9297
// -------------------------------------------------------------------
@@ -459,7 +464,7 @@ public static void main(String[] args) throws Exception {
459464
if (isBooleanOptionSet(argsLine, "execute")) {
460465
// Bombs away!
461466
try {
462-
Results r = runWorkload(benchList, intervalMonitor);
467+
Results r = runWorkload(benchList, intervalMonitor, useVirtualThreads);
463468
writeOutputs(r, activeTXTypes, argsLine, xmlConfig);
464469
writeHistograms(r);
465470

@@ -631,7 +636,7 @@ private static void runLoader(BenchmarkModule bench) throws SQLException, Interr
631636
bench.loadDatabase();
632637
}
633638

634-
private static Results runWorkload(List<BenchmarkModule> benchList, int intervalMonitor) throws IOException {
639+
private static Results runWorkload(List<BenchmarkModule> benchList, int intervalMonitor, Boolean useVirtualThreads) throws IOException {
635640
List<Worker<?>> workers = new ArrayList<>();
636641
List<WorkloadConfiguration> workConfs = new ArrayList<>();
637642
for (BenchmarkModule bench : benchList) {
@@ -643,7 +648,7 @@ private static Results runWorkload(List<BenchmarkModule> benchList, int interval
643648
workConfs.add(bench.getWorkloadConfiguration());
644649

645650
}
646-
Results r = ThreadBench.runRateLimitedBenchmark(workers, workConfs, intervalMonitor);
651+
Results r = ThreadBench.runRateLimitedBenchmark(workers, workConfs, intervalMonitor, useVirtualThreads);
647652
LOG.info(SINGLE_LINE);
648653
LOG.info("Rate limited reqs/s: {}", r);
649654
return r;

src/main/java/com/oltpbenchmark/ThreadBench.java

+13-4
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,36 @@ public class ThreadBench implements Thread.UncaughtExceptionHandler {
3838
private final List<WorkloadConfiguration> workConfs;
3939
private final ArrayList<LatencyRecord.Sample> samples = new ArrayList<>();
4040
private final int intervalMonitor;
41+
private final Boolean useVirtualThreads;
4142

4243
private ThreadBench(List<? extends Worker<? extends BenchmarkModule>> workers,
43-
List<WorkloadConfiguration> workConfs, int intervalMonitoring) {
44+
List<WorkloadConfiguration> workConfs, int intervalMonitoring, Boolean useVirtualThreads) {
4445
this.workers = workers;
4546
this.workConfs = workConfs;
4647
this.workerThreads = new ArrayList<>(workers.size());
4748
this.intervalMonitor = intervalMonitoring;
4849
this.testState = new BenchmarkState(workers.size() + 1);
50+
this.useVirtualThreads = useVirtualThreads;
4951
}
5052

5153
public static Results runRateLimitedBenchmark(List<Worker<? extends BenchmarkModule>> workers,
52-
List<WorkloadConfiguration> workConfs, int intervalMonitoring) {
53-
ThreadBench bench = new ThreadBench(workers, workConfs, intervalMonitoring);
54+
List<WorkloadConfiguration> workConfs, int intervalMonitoring, Boolean useVirtualThreads) {
55+
ThreadBench bench = new ThreadBench(workers, workConfs, intervalMonitoring, useVirtualThreads);
5456
return bench.runRateLimitedMultiPhase();
5557
}
5658

5759
private void createWorkerThreads() {
5860

5961
for (Worker<?> worker : workers) {
6062
worker.initializeState();
61-
Thread thread = new Thread(worker);
63+
64+
Thread thread;
65+
if (useVirtualThreads) {
66+
thread = Thread.ofVirtual().unstarted(worker);
67+
} else {
68+
thread = new Thread(worker);
69+
}
70+
6271
thread.setUncaughtExceptionHandler(this);
6372
thread.start();
6473
this.workerThreads.add(thread);

0 commit comments

Comments
 (0)