From 7506b2a5710922d51bb7948564c5f67c7b82b05b Mon Sep 17 00:00:00 2001 From: Aleti Vasanth Reddy Date: Tue, 13 Feb 2024 14:15:07 +0530 Subject: [PATCH 1/5] added virtual threads --- src/com/oltpbenchmark/ThreadBench.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/com/oltpbenchmark/ThreadBench.java b/src/com/oltpbenchmark/ThreadBench.java index fa8b87c..9619e3c 100644 --- a/src/com/oltpbenchmark/ThreadBench.java +++ b/src/com/oltpbenchmark/ThreadBench.java @@ -164,8 +164,9 @@ public void remove() { private void createWorkerThreads() { for (Worker worker : workers) { worker.initializeState(); - Thread thread = new Thread(worker); + Thread thread = Thread.ofVirtual().unstarted(worker); thread.setUncaughtExceptionHandler(this); + // LOG.info("starting a new virtual thread!"); thread.start(); this.workerThreads.add(thread); } From cb761fd57c507dee28e620caa33790493fa0d080 Mon Sep 17 00:00:00 2001 From: Aleti Vasanth Reddy Date: Fri, 16 Feb 2024 12:19:00 +0530 Subject: [PATCH 2/5] moving to java 21 --- config/workload_all.xml | 2 +- pom.xml | 7 +++++-- src/com/oltpbenchmark/CommandLineOptions.java | 5 +++++ src/com/oltpbenchmark/DBWorkload.java | 7 +++++-- src/com/oltpbenchmark/ThreadBench.java | 18 ++++++++++++++---- 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/config/workload_all.xml b/config/workload_all.xml index 062b801..8c4f350 100644 --- a/config/workload_all.xml +++ b/config/workload_all.xml @@ -44,7 +44,7 @@ - 1800 + 4 10000 diff --git a/src/com/oltpbenchmark/CommandLineOptions.java b/src/com/oltpbenchmark/CommandLineOptions.java index 4f70fde..c6ea034 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("vt", "virtual-threads", true, "Use Virtual threads"); } public CommandLineOptions() {} @@ -175,6 +176,10 @@ public Optional getInitialDelaySeconds() { return getIntOpt("initial-delay-secs"); } + public boolean getUseVirtualThreads() { + return isBooleanOptionSet("vt") || isBooleanOptionSet("virtual-threads"); + } + 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 9619e3c..a602a09 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 { @@ -164,7 +166,15 @@ public void remove() { private void createWorkerThreads() { for (Worker worker : workers) { worker.initializeState(); - Thread thread = Thread.ofVirtual().unstarted(worker); + Thread thread; + if(useVirtualThreads) { + thread = Thread.ofVirtual().unstarted(worker); + LOG.info("starting a virtual thread!"); + } + else{ + LOG.info("starting a phyiscal thread!"); + thread = new Thread(worker); + } thread.setUncaughtExceptionHandler(this); // LOG.info("starting a new virtual thread!"); thread.start(); @@ -277,8 +287,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(); } From ecca5fec9f6bd9a894d589de1d47c9068bc278a9 Mon Sep 17 00:00:00 2001 From: Aleti Vasanth Reddy Date: Fri, 16 Feb 2024 12:24:04 +0530 Subject: [PATCH 3/5] switch to java 21 --- config/workload_all.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/workload_all.xml b/config/workload_all.xml index 8c4f350..062b801 100644 --- a/config/workload_all.xml +++ b/config/workload_all.xml @@ -44,7 +44,7 @@ - 4 + 1800 10000