Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java 21 virtual threads #398

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading