diff --git a/pom.xml b/pom.xml index aed5f26..8d28028 100644 --- a/pom.xml +++ b/pom.xml @@ -10,8 +10,11 @@ jar - 1.10 - 1.10 + UTF-8 + 21 + 21 + 21 + ${project.basedir}/target diff --git a/src/com/oltpbenchmark/CommandLineOptions.java b/src/com/oltpbenchmark/CommandLineOptions.java index 4f70fde..44b4743 100644 --- a/src/com/oltpbenchmark/CommandLineOptions.java +++ b/src/com/oltpbenchmark/CommandLineOptions.java @@ -67,6 +67,7 @@ public class CommandLineOptions { COMMAND_LINE_OPTS.addOption(null, "merge-json-results", true, "Merge results from various json output files"); COMMAND_LINE_OPTS.addOption(null, "dir", true, "Directory containing the csv files"); COMMAND_LINE_OPTS.addOption(null, "vv", false, "Output verbose execute results"); + COMMAND_LINE_OPTS.addOption(null, "vt", false, "Use Virtual threads"); } public CommandLineOptions() {} @@ -175,6 +176,10 @@ public Optional getInitialDelaySeconds() { return getIntOpt("initial-delay-secs"); } + public boolean getUseVirtualThreads() { + return argsLine.hasOption("vt"); + } + public boolean getIsCreateSqlProceduresSet() { return isBooleanOptionSet("create-sql-procedures"); } diff --git a/src/com/oltpbenchmark/DBWorkload.java b/src/com/oltpbenchmark/DBWorkload.java index 9fc5a06..cece60b 100644 --- a/src/com/oltpbenchmark/DBWorkload.java +++ b/src/com/oltpbenchmark/DBWorkload.java @@ -51,7 +51,7 @@ public class DBWorkload { private static int warmupTime = 0; private static final Map transactionTypes = new HashMap<>(); private static JsonMetricsHelper jsonMetricsHelper = new JsonMetricsHelper(); - + private static Boolean useVirtualThreads = false; /** * Returns true if asserts are enabled. This assumes that * we're always using the default system ClassLoader @@ -88,6 +88,9 @@ public static void main(String[] args) throws Exception { transactionTypes.put(5, "StockLevel"); numWarehouses = options.getWarehouses().orElse(numWarehouses); + if(options.getUseVirtualThreads()) { + useVirtualThreads = true; + } String configFile = options.getConfigFile().orElse("config/workload_all.xml"); ConfigFileOptions configOptions = new ConfigFileOptions(configFile); @@ -482,7 +485,7 @@ private static Results runWorkload(List 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); r.startTime = start; r.endTime = end; diff --git a/src/com/oltpbenchmark/ThreadBench.java b/src/com/oltpbenchmark/ThreadBench.java index fa8b87c..7da407a 100644 --- a/src/com/oltpbenchmark/ThreadBench.java +++ b/src/com/oltpbenchmark/ThreadBench.java @@ -46,12 +46,14 @@ public class ThreadBench implements Thread.UncaughtExceptionHandler { private final List workStates; final ArrayList samples = new ArrayList<>(); private int intervalMonitor = 0; + private boolean useVirtualThreads = false; - public ThreadBench(List workers, List workConfs) { + public ThreadBench(List workers, List workConfs, boolean useVirtualThreads) { this.workers = workers; this.workConfs = workConfs; this.workerThreads = new ArrayList<>(workers.size()); this.workStates = new ArrayList<>(); + this.useVirtualThreads = useVirtualThreads; } public static final class TimeBucketIterable implements Iterable { @@ -162,13 +164,25 @@ public void remove() { } private void createWorkerThreads() { - for (Worker worker : workers) { - worker.initializeState(); - Thread thread = new Thread(worker); - thread.setUncaughtExceptionHandler(this); - thread.start(); - this.workerThreads.add(thread); - } + if(useVirtualThreads) { + LOG.info("creating virtual threads as workers..."); + } + else { + LOG.info("creating real threads as workers..."); + } + for (Worker worker : workers) { + worker.initializeState(); + Thread thread; + if(useVirtualThreads) { + thread = Thread.ofVirtual().unstarted(worker); + } + else{ + thread = new Thread(worker); + } + thread.setUncaughtExceptionHandler(this); + thread.start(); + this.workerThreads.add(thread); + } } private void interruptWorkers() { @@ -276,8 +290,8 @@ public void run() { } } // CLASS - public static Results runRateLimitedBenchmark(List workers, List workConfs, int intervalMonitoring) { - ThreadBench bench = new ThreadBench(workers, workConfs); + public static Results runRateLimitedBenchmark(List workers, List workConfs, int intervalMonitoring, boolean useVirtualThreads) { + ThreadBench bench = new ThreadBench(workers, workConfs, useVirtualThreads); bench.intervalMonitor = intervalMonitoring; return bench.runRateLimitedMultiPhase(); }