Skip to content

Commit 0ad9d4d

Browse files
committed
add the -vt/--virtual-threads option to use virtual threads
1 parent 0cf30ee commit 0ad9d4d

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

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

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

88+
Boolean useVirtualThreads = false;
89+
if (argsLine.hasOption("vt")) {
90+
useVirtualThreads = Boolean.parseBoolean(argsLine.getOptionValue("vt"));
91+
}
92+
8893
// -------------------------------------------------------------------
8994
// GET PLUGIN LIST
9095
// -------------------------------------------------------------------
@@ -518,7 +523,7 @@ public static void main(String[] args) throws Exception {
518523
if (isBooleanOptionSet(argsLine, "execute")) {
519524
// Bombs away!
520525
try {
521-
Results r = runWorkload(benchList, intervalMonitor);
526+
Results r = runWorkload(benchList, intervalMonitor, useVirtualThreads);
522527
writeOutputs(r, activeTXTypes, argsLine, xmlConfig);
523528
writeHistograms(r);
524529

@@ -567,6 +572,7 @@ private static Options buildOptions(XMLConfiguration pluginConfig) {
567572
"Base directory for the result files, default is current directory");
568573
options.addOption(null, "dialects-export", true, "Export benchmark SQL to a dialects file");
569574
options.addOption("jh", "json-histograms", true, "Export histograms to JSON file");
575+
options.addOption("vt", "virtual-threads", true, "Use virtual threads instead of real threads");
570576
return options;
571577
}
572578

@@ -733,7 +739,8 @@ private static void runLoader(BenchmarkModule bench)
733739
bench.loadDatabase();
734740
}
735741

736-
private static Results runWorkload(List<BenchmarkModule> benchList, int intervalMonitor)
742+
private static Results runWorkload(
743+
List<BenchmarkModule> benchList, int intervalMonitor, Boolean useVirtualThreads)
737744
throws IOException {
738745
List<Worker<?>> workers = new ArrayList<>();
739746
List<WorkloadConfiguration> workConfs = new ArrayList<>();
@@ -748,7 +755,8 @@ private static Results runWorkload(List<BenchmarkModule> benchList, int interval
748755
bench.getBenchmarkName().toUpperCase(), num_phases, (num_phases > 1 ? "s" : "")));
749756
workConfs.add(bench.getWorkloadConfiguration());
750757
}
751-
Results r = ThreadBench.runRateLimitedBenchmark(workers, workConfs, intervalMonitor);
758+
Results r =
759+
ThreadBench.runRateLimitedBenchmark(workers, workConfs, intervalMonitor, useVirtualThreads);
752760
LOG.info(SINGLE_LINE);
753761
LOG.info("Rate limited reqs/s: {}", r);
754762
return r;

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

+15-4
Original file line numberDiff line numberDiff line change
@@ -37,31 +37,42 @@ public class ThreadBench implements Thread.UncaughtExceptionHandler {
3737
private final List<WorkloadConfiguration> workConfs;
3838
private final ArrayList<LatencyRecord.Sample> samples = new ArrayList<>();
3939
private final int intervalMonitor;
40+
private final Boolean useVirtualThreads;
4041

4142
private ThreadBench(
4243
List<? extends Worker<? extends BenchmarkModule>> workers,
4344
List<WorkloadConfiguration> workConfs,
44-
int intervalMonitoring) {
45+
int intervalMonitoring,
46+
Boolean useVirtualThreads) {
4547
this.workers = workers;
4648
this.workConfs = workConfs;
4749
this.workerThreads = new ArrayList<>(workers.size());
4850
this.intervalMonitor = intervalMonitoring;
4951
this.testState = new BenchmarkState(workers.size() + 1);
52+
this.useVirtualThreads = useVirtualThreads;
5053
}
5154

5255
public static Results runRateLimitedBenchmark(
5356
List<Worker<? extends BenchmarkModule>> workers,
5457
List<WorkloadConfiguration> workConfs,
55-
int intervalMonitoring) {
56-
ThreadBench bench = new ThreadBench(workers, workConfs, intervalMonitoring);
58+
int intervalMonitoring,
59+
Boolean useVirtualThreads) {
60+
ThreadBench bench = new ThreadBench(workers, workConfs, intervalMonitoring, useVirtualThreads);
5761
return bench.runRateLimitedMultiPhase();
5862
}
5963

6064
private void createWorkerThreads() {
6165

6266
for (Worker<?> worker : workers) {
6367
worker.initializeState();
64-
Thread thread = new Thread(worker);
68+
69+
Thread thread;
70+
if (useVirtualThreads) {
71+
thread = Thread.ofVirtual().unstarted(worker);
72+
} else {
73+
thread = new Thread(worker);
74+
}
75+
6576
thread.setUncaughtExceptionHandler(this);
6677
thread.start();
6778
this.workerThreads.add(thread);

0 commit comments

Comments
 (0)