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 8df253a commit ea4ae0c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
12 changes: 9 additions & 3 deletions src/main/java/com/oltpbenchmark/DBWorkload.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,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 @@ -459,7 +464,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 @@ -493,6 +498,7 @@ private static Options buildOptions(XMLConfiguration pluginConfig) {
options.addOption("d", "directory", true, "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 @@ -631,7 +637,7 @@ private static void runLoader(BenchmarkModule bench) throws SQLException, Interr
bench.loadDatabase();
}

private static Results runWorkload(List<BenchmarkModule> benchList, int intervalMonitor) throws IOException {
private static Results runWorkload(List<BenchmarkModule> benchList, int intervalMonitor, Boolean useVirtualThreads) throws IOException {
List<Worker<?>> workers = new ArrayList<>();
List<WorkloadConfiguration> workConfs = new ArrayList<>();
for (BenchmarkModule bench : benchList) {
Expand All @@ -643,7 +649,7 @@ private static Results runWorkload(List<BenchmarkModule> benchList, int interval
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
17 changes: 13 additions & 4 deletions src/main/java/com/oltpbenchmark/ThreadBench.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,36 @@ 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) {
List<WorkloadConfiguration> workConfs, 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);
List<WorkloadConfiguration> workConfs, 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 ea4ae0c

Please sign in to comment.