Skip to content

Commit

Permalink
add the -vt/--virtual-threads option to use virtual threads
Browse files Browse the repository at this point in the history
  • Loading branch information
eivanov89 committed Dec 15, 2023
1 parent 0cf30ee commit 0ad9d4d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
14 changes: 11 additions & 3 deletions src/main/java/com/oltpbenchmark/DBWorkload.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public static void main(String[] args) throws Exception {
intervalMonitor = Integer.parseInt(argsLine.getOptionValue("im"));
}

Boolean useVirtualThreads = false;
if (argsLine.hasOption("vt")) {
useVirtualThreads = Boolean.parseBoolean(argsLine.getOptionValue("vt"));
}

// -------------------------------------------------------------------
// GET PLUGIN LIST
// -------------------------------------------------------------------
Expand Down Expand Up @@ -518,7 +523,7 @@ public static void main(String[] args) throws Exception {
if (isBooleanOptionSet(argsLine, "execute")) {
// Bombs away!
try {
Results r = runWorkload(benchList, intervalMonitor);
Results r = runWorkload(benchList, intervalMonitor, useVirtualThreads);
writeOutputs(r, activeTXTypes, argsLine, xmlConfig);
writeHistograms(r);

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

Expand Down Expand Up @@ -733,7 +739,8 @@ private static void runLoader(BenchmarkModule bench)
bench.loadDatabase();
}

private static Results runWorkload(List<BenchmarkModule> benchList, int intervalMonitor)
private static Results runWorkload(
List<BenchmarkModule> benchList, int intervalMonitor, Boolean useVirtualThreads)
throws IOException {
List<Worker<?>> workers = new ArrayList<>();
List<WorkloadConfiguration> workConfs = new ArrayList<>();
Expand All @@ -748,7 +755,8 @@ private static Results runWorkload(List<BenchmarkModule> benchList, int interval
bench.getBenchmarkName().toUpperCase(), num_phases, (num_phases > 1 ? "s" : "")));
workConfs.add(bench.getWorkloadConfiguration());
}
Results r = ThreadBench.runRateLimitedBenchmark(workers, workConfs, intervalMonitor);
Results r =
ThreadBench.runRateLimitedBenchmark(workers, workConfs, intervalMonitor, useVirtualThreads);
LOG.info(SINGLE_LINE);
LOG.info("Rate limited reqs/s: {}", r);
return r;
Expand Down
19 changes: 15 additions & 4 deletions src/main/java/com/oltpbenchmark/ThreadBench.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,42 @@ public class ThreadBench implements Thread.UncaughtExceptionHandler {
private final List<WorkloadConfiguration> workConfs;
private final ArrayList<LatencyRecord.Sample> samples = new ArrayList<>();
private final int intervalMonitor;
private final Boolean useVirtualThreads;

private ThreadBench(
List<? extends Worker<? extends BenchmarkModule>> workers,
List<WorkloadConfiguration> workConfs,
int intervalMonitoring) {
int intervalMonitoring,
Boolean useVirtualThreads) {
this.workers = workers;
this.workConfs = workConfs;
this.workerThreads = new ArrayList<>(workers.size());
this.intervalMonitor = intervalMonitoring;
this.testState = new BenchmarkState(workers.size() + 1);
this.useVirtualThreads = useVirtualThreads;
}

public static Results runRateLimitedBenchmark(
List<Worker<? extends BenchmarkModule>> workers,
List<WorkloadConfiguration> workConfs,
int intervalMonitoring) {
ThreadBench bench = new ThreadBench(workers, workConfs, intervalMonitoring);
int intervalMonitoring,
Boolean useVirtualThreads) {
ThreadBench bench = new ThreadBench(workers, workConfs, intervalMonitoring, useVirtualThreads);
return bench.runRateLimitedMultiPhase();
}

private void createWorkerThreads() {

for (Worker<?> worker : workers) {
worker.initializeState();
Thread thread = new Thread(worker);

Thread thread;
if (useVirtualThreads) {
thread = Thread.ofVirtual().unstarted(worker);
} else {
thread = new Thread(worker);
}

thread.setUncaughtExceptionHandler(this);
thread.start();
this.workerThreads.add(thread);
Expand Down

0 comments on commit 0ad9d4d

Please sign in to comment.