Skip to content

Commit

Permalink
switch to java 21 and add option 'vt' to use virtual threads (#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
eivanov89 committed Dec 4, 2023
1 parent 386a0e1 commit 0d098e6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>17</java.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<java.version>21</java.version>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<buildDirectory>${project.basedir}/target</buildDirectory>
<!--
Provids a way to limit which assembly package formats we produce.
Expand Down
11 changes: 8 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 @@ -631,7 +636,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 +648,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 0d098e6

Please sign in to comment.