Skip to content

Commit ea4ae0c

Browse files
committed
add the -vt/--virtual-threads option to use virtual threads
1 parent 8df253a commit ea4ae0c

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

Diff for: src/main/java/com/oltpbenchmark/DBWorkload.java

+9-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

@@ -493,6 +498,7 @@ private static Options buildOptions(XMLConfiguration pluginConfig) {
493498
options.addOption("d", "directory", true, "Base directory for the result files, default is current directory");
494499
options.addOption(null, "dialects-export", true, "Export benchmark SQL to a dialects file");
495500
options.addOption("jh", "json-histograms", true, "Export histograms to JSON file");
501+
options.addOption("vt", "virtual-threads", true, "Use virtual threads instead of real threads");
496502
return options;
497503
}
498504

@@ -631,7 +637,7 @@ private static void runLoader(BenchmarkModule bench) throws SQLException, Interr
631637
bench.loadDatabase();
632638
}
633639

634-
private static Results runWorkload(List<BenchmarkModule> benchList, int intervalMonitor) throws IOException {
640+
private static Results runWorkload(List<BenchmarkModule> benchList, int intervalMonitor, Boolean useVirtualThreads) throws IOException {
635641
List<Worker<?>> workers = new ArrayList<>();
636642
List<WorkloadConfiguration> workConfs = new ArrayList<>();
637643
for (BenchmarkModule bench : benchList) {
@@ -643,7 +649,7 @@ private static Results runWorkload(List<BenchmarkModule> benchList, int interval
643649
workConfs.add(bench.getWorkloadConfiguration());
644650

645651
}
646-
Results r = ThreadBench.runRateLimitedBenchmark(workers, workConfs, intervalMonitor);
652+
Results r = ThreadBench.runRateLimitedBenchmark(workers, workConfs, intervalMonitor, useVirtualThreads);
647653
LOG.info(SINGLE_LINE);
648654
LOG.info("Rate limited reqs/s: {}", r);
649655
return r;

Diff for: 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)