diff --git a/requirements.txt b/requirements.txt index 71189b8..687bf9b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ mysql-connector-python==8.2.0 pandas==2.0.3 tqdm==4.65.0 +defusedxml==0.7.1 diff --git a/script/parse.py b/script/parse.py index e2727eb..a54e7ec 100644 --- a/script/parse.py +++ b/script/parse.py @@ -4,7 +4,7 @@ import csv import math import json -import xml.etree.ElementTree as ET +import defusedxml.ElementTree as ET from tqdm import tqdm import mysql.connector import argparse diff --git a/script/runbench.sh b/script/runbench.sh index 47286ae..14a0341 100755 --- a/script/runbench.sh +++ b/script/runbench.sh @@ -48,12 +48,12 @@ fi # Navigate to the project directory cd .. -./olxpbenchmark -b web3bench -c config/runthread1.xml --execute=true -o thread1 | tee log/thread1.log & -./olxpbenchmark -b web3bench -c config/runthread2.xml --execute=true -o thread2 | tee log/thread2.log & -./olxpbenchmark -b web3bench -c config/runR21.xml --execute=true -o R21 | tee log/R21.log & -./olxpbenchmark -b web3bench -c config/runR22.xml --execute=true -o R22 | tee log/R22.log & -./olxpbenchmark -b web3bench -c config/runR23.xml --execute=true -o R23 | tee log/R23.log & -./olxpbenchmark -b web3bench -c config/runR24.xml --execute=true -o R24 | tee log/R24.log & -./olxpbenchmark -b web3bench -c config/runR25.xml --execute=true -o R25 | tee log/R25.log +./olxpbenchmark -b web3bench --explain-analyze=true -c config/runthread1.xml --execute=true -o thread1 | tee log/thread1.log & +./olxpbenchmark -b web3bench --explain-analyze=true -c config/runthread2.xml --execute=true -o thread2 | tee log/thread2.log & +./olxpbenchmark -b web3bench --explain-analyze=true -c config/runR21.xml --execute=true -o R21 | tee log/R21.log & +./olxpbenchmark -b web3bench --explain-analyze=true -c config/runR22.xml --execute=true -o R22 | tee log/R22.log & +./olxpbenchmark -b web3bench --explain-analyze=true -c config/runR23.xml --execute=true -o R23 | tee log/R23.log & +./olxpbenchmark -b web3bench --explain-analyze=true -c config/runR24.xml --execute=true -o R24 | tee log/R24.log & +./olxpbenchmark -b web3bench --explain-analyze=true -c config/runR25.xml --execute=true -o R25 | tee log/R25.log wait diff --git a/src/com/olxpbenchmark/DBWorkload.java b/src/com/olxpbenchmark/DBWorkload.java index 0d1a229..8ee0265 100755 --- a/src/com/olxpbenchmark/DBWorkload.java +++ b/src/com/olxpbenchmark/DBWorkload.java @@ -127,51 +127,16 @@ public static void main(String[] args) throws Exception { } pluginConfig.setExpressionEngine(new XPathExpressionEngine()); Options options = new Options(); - options.addOption( - "b", - "bench", - true, + options.addOption("b", "bench", true, "[required] Benchmark class. Currently supported: " + pluginConfig.getList("/plugin//@name")); - options.addOption( - "c", - "config", - true, - "[required] Workload configuration file"); - options.addOption( - null, - "create", - true, - "Initialize the database for this benchmark"); - options.addOption( - null, - "clear", - true, - "Clear all records in the database for this benchmark"); - options.addOption( - null, - "load", - true, - "Load data using the benchmark's data loader"); - options.addOption( - null, - "execute", - true, - "Execute the benchmark workload"); - options.addOption( - null, - "runscript", - true, - "Run an SQL script"); - options.addOption( - null, - "upload", - true, - "Upload the result"); - options.addOption( - null, - "uploadHash", - true, - "git hash to be associated with the upload"); + options.addOption("c", "config", true, "[required] Workload configuration file"); + options.addOption(null, "create", true, "Initialize the database for this benchmark"); + options.addOption(null, "clear", true, "Clear all records in the database for this benchmark"); + options.addOption(null, "load", true, "Load data using the benchmark's data loader"); + options.addOption(null, "execute", true, "Execute the benchmark workload"); + options.addOption(null, "runscript", true, "Run an SQL script"); + options.addOption(null, "upload", true, "Upload the result"); + options.addOption(null, "uploadHash", true, "git hash to be associated with the upload"); options.addOption("v", "verbose", false, "Display Messages"); options.addOption("h", "help", false, "Print this help"); @@ -188,6 +153,7 @@ public static void main(String[] args) throws Exception { options.addOption(null, "dialects-export", true, "Export benchmark SQL to a dialects file"); options.addOption(null, "output-raw", true, "Output raw data"); options.addOption(null, "output-samples", true, "Output sample data"); + options.addOption("ea", "explain-analyze", true, "Use EXPLAIN ANALYZE for all queries"); // parse the command line arguments CommandLine argsLine = parser.parse(options, args); @@ -219,6 +185,15 @@ public static void main(String[] args) throws Exception { e.printStackTrace(); } + // Use EXPLAIN ANALYZE for all queries + Boolean isExplainAnalyze = false; + if (isBooleanOptionSet(argsLine, "explain-analyze")) { + isExplainAnalyze = true; + LOG.info("Using EXPLAIN ANALYZE for all queries"); + } else { + LOG.info("Not using EXPLAIN ANALYZE for all queries"); + } + // ------------------------------------------------------------------- // GET PLUGIN LIST // ------------------------------------------------------------------- @@ -280,6 +255,7 @@ public static void main(String[] args) throws Exception { wrkld.setScaleFactor(xmlConfig.getDouble("scalefactor", 1.0)); wrkld.setRecordAbortMessages(xmlConfig.getBoolean("recordabortmessages", false)); wrkld.setDataDir(xmlConfig.getString("datadir", ".")); + wrkld.setisExplainAnalyze(isExplainAnalyze); // microadd wrkld.setDistri(xmlConfig.getString("distribution", "rand")); @@ -330,6 +306,7 @@ public static void main(String[] args) throws Exception { initDebug.put("Distribution", wrkld.getDistri()); initDebug.put("StartNumber", wrkld.getStartNum()); initDebug.put("GapTime", wrkld.getGapTime()); + initDebug.put("isExplainAnalyze", wrkld.getisExplainAnalyze()); if (selectivity != -1) initDebug.put("Selectivity", selectivity); diff --git a/src/com/olxpbenchmark/WorkloadConfiguration.java b/src/com/olxpbenchmark/WorkloadConfiguration.java index d199250..92c00d1 100755 --- a/src/com/olxpbenchmark/WorkloadConfiguration.java +++ b/src/com/olxpbenchmark/WorkloadConfiguration.java @@ -92,6 +92,7 @@ public void setBenchmarkName(String benchmarkName) { private int loaderThreads = ThreadUtil.availableProcessors(); private int numTxnTypes; private TraceReader traceReader = null; + private boolean isExplainAnalyze = true; public TraceReader getTraceReader() { return traceReader; @@ -299,6 +300,20 @@ public String getNodeId() { return node_id; } + /* + * Return isExplainAnalyze flag + */ + public boolean getisExplainAnalyze() { + return isExplainAnalyze; + } + + /* + * Set isExplainAnalyze flag + */ + public void setisExplainAnalyze(boolean isExplainAnalyze) { + this.isExplainAnalyze = isExplainAnalyze; + } + /** * Set the scale factor for the database * A value of 1 means the default size. diff --git a/src/com/olxpbenchmark/api/Loader.java b/src/com/olxpbenchmark/api/Loader.java index f5d59c2..a6748f9 100755 --- a/src/com/olxpbenchmark/api/Loader.java +++ b/src/com/olxpbenchmark/api/Loader.java @@ -35,6 +35,7 @@ package com.olxpbenchmark.api; import java.sql.Connection; +import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Statement; import java.util.List; @@ -182,13 +183,15 @@ public Random rng() { public void unload(Connection conn, Catalog catalog) throws SQLException { conn.setAutoCommit(false); conn.setTransactionIsolation(workConf.getIsolationMode()); - Statement st = conn.createStatement(); - for (Table catalog_tbl : catalog.getTables()) { - LOG.debug(String.format("Deleting data from %s.%s", workConf.getDBName(), catalog_tbl.getName())); - String sql = "DELETE FROM " + catalog_tbl.getEscapedName(); - st.execute(sql); - } // FOR - conn.commit(); + String deleteSql = "DELETE FROM ?"; + try (PreparedStatement ps = conn.prepareStatement(deleteSql)) { + for (Table catalog_tbl : catalog.getTables()) { + LOG.debug(String.format("Deleting data from %s.%s", workConf.getDBName(), catalog_tbl.getName())); + ps.setString(1, catalog_tbl.getEscapedName()); + ps.executeUpdate(); + } // FOR + conn.commit(); + } } /** diff --git a/src/com/olxpbenchmark/api/Procedure.java b/src/com/olxpbenchmark/api/Procedure.java index 145b02c..67516c4 100644 --- a/src/com/olxpbenchmark/api/Procedure.java +++ b/src/com/olxpbenchmark/api/Procedure.java @@ -35,6 +35,8 @@ public abstract class Procedure { private static final Logger LOG = Logger.getLogger(Procedure.class); + protected static final String SQL_EXPLAIN_ANALYZE = "EXPLAIN ANALYZE "; + private final String procName; private DatabaseType dbType; private Map name_stmt_xref; diff --git a/src/com/olxpbenchmark/api/StatementDialects.java b/src/com/olxpbenchmark/api/StatementDialects.java index c541056..a6f9678 100644 --- a/src/com/olxpbenchmark/api/StatementDialects.java +++ b/src/com/olxpbenchmark/api/StatementDialects.java @@ -111,7 +111,9 @@ protected boolean load() { Unmarshaller unmarshaller = jc.createUnmarshaller(); // But did not shoot unmarshaller! unmarshaller.setSchema(schema); - @SuppressWarnings("unchecked") + // Disable External Entity Resolution + unmarshaller.setProperty("javax.xml.stream.isReplacingEntityReferences", false); + unmarshaller.setProperty("javax.xml.stream.isSupportingExternalEntities", false); JAXBElement result = (JAXBElement) unmarshaller.unmarshal(this.xmlFile); dialects = result.getValue(); } catch (JAXBException ex) { diff --git a/src/com/olxpbenchmark/api/Worker.java b/src/com/olxpbenchmark/api/Worker.java index f3536eb..a2c02e6 100755 --- a/src/com/olxpbenchmark/api/Worker.java +++ b/src/com/olxpbenchmark/api/Worker.java @@ -365,9 +365,11 @@ public final void run() { LOG.debug("Start:" + start + " End:" + end + " Start - End:" + (end - start)); LOG.debug("Latency:" + latency_ns); } - assert latency_ns != 0 : "Latency is 0"; - // Overwrite the end time with the latency time - end = start + latency_ns; + // Use the latency_ns if it's not 0, otherwise use the real end time to + // calculate the latency + if (latency_ns != 0) { + end = start + latency_ns; + } // Reset the latency to 0 latency_ns = 0; diff --git a/src/com/olxpbenchmark/api/collectors/DBCollector.java b/src/com/olxpbenchmark/api/collectors/DBCollector.java index 6bcf4b3..f997b89 100644 --- a/src/com/olxpbenchmark/api/collectors/DBCollector.java +++ b/src/com/olxpbenchmark/api/collectors/DBCollector.java @@ -20,6 +20,7 @@ import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.DriverManager; +import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; @@ -142,9 +143,14 @@ protected static Map getKeyValueResults(Connection conn, String return results; } - protected static List> getColumnResults(Connection conn, String sql) throws SQLException { - Statement s = conn.createStatement(); - ResultSet out = s.executeQuery(sql); + protected static List> getColumnResults(Connection conn, String sql, + Object... params) throws SQLException { + PreparedStatement pstmt = conn.prepareStatement(sql); + // Set parameters if any + for (int i = 0; i < params.length; i++) { + pstmt.setObject(i + 1, params[i]); + } + ResultSet out = pstmt.executeQuery(sql); // Get column names ResultSetMetaData metadata = out.getMetaData(); diff --git a/src/com/olxpbenchmark/api/collectors/MyRocksCollector.java b/src/com/olxpbenchmark/api/collectors/MyRocksCollector.java index d523cd2..05dc8a1 100644 --- a/src/com/olxpbenchmark/api/collectors/MyRocksCollector.java +++ b/src/com/olxpbenchmark/api/collectors/MyRocksCollector.java @@ -37,13 +37,13 @@ public class MyRocksCollector extends DBCollector { private static final String METRICS_SQL = "SHOW GLOBAL STATUS"; - private static final String DB_METRICS_SQL = "SELECT * FROM information_schema.db_statistics WHERE db = '%s'"; + private static final String DB_METRICS_SQL = "SELECT * FROM information_schema.db_statistics WHERE db = ?"; - private static final String TABLE_METRICS_SQL = "SELECT * FROM information_schema.table_statistics WHERE table_schema = '%s'"; + private static final String TABLE_METRICS_SQL = "SELECT * FROM information_schema.table_statistics WHERE table_schema = ?"; - private static final String INDEX_METRICS_SQL = "SELECT * FROM information_schema.statistics WHERE TABLE_SCHEMA = '%s'"; + private static final String INDEX_METRICS_SQL = "SELECT * FROM information_schema.statistics WHERE TABLE_SCHEMA = ?"; - private static final String METRICS_VIEWS_SQL = "SELECT * FROM information_schema.%s"; + private static final String METRICS_VIEWS_SQL = "SELECT * FROM information_schema.?"; private static final String[] METRICS_VIEWS = { "index_statistics", @@ -99,14 +99,14 @@ public String collectMetrics() { // Collect db-, table-, and index-level metrics (inherited from MySQL) String dbName = getDatabaseName(conn); - metrics.put("db_statistics", getColumnResults(conn, String.format(DB_METRICS_SQL, dbName))); - metrics.put("table_statistics", getColumnResults(conn, String.format(TABLE_METRICS_SQL, dbName))); - metrics.put("index_statistics", getColumnResults(conn, String.format(INDEX_METRICS_SQL, dbName))); + metrics.put("db_statistics", getColumnResults(conn, DB_METRICS_SQL, dbName)); + metrics.put("table_statistics", getColumnResults(conn, TABLE_METRICS_SQL, dbName)); + metrics.put("index_statistics", getColumnResults(conn, INDEX_METRICS_SQL, dbName)); // Collect myrocks-specific metrics for (String viewName : METRICS_VIEWS) { try { - metrics.put(viewName, getColumnResults(conn, String.format(METRICS_VIEWS_SQL, viewName))); + metrics.put(viewName, getColumnResults(conn, METRICS_VIEWS_SQL, viewName)); } catch (SQLException ex) { if (LOG.isDebugEnabled()) LOG.warn("Error collecting DB metric view: " + ex.getMessage()); diff --git a/src/com/olxpbenchmark/benchmarks/web3benchmark/WEB3Loader.java b/src/com/olxpbenchmark/benchmarks/web3benchmark/WEB3Loader.java index 709604c..d6d60c0 100755 --- a/src/com/olxpbenchmark/benchmarks/web3benchmark/WEB3Loader.java +++ b/src/com/olxpbenchmark/benchmarks/web3benchmark/WEB3Loader.java @@ -376,18 +376,18 @@ protected int loadBlocks(Connection conn, int w_id, int blocksStartInclusive, in } catch (BatchUpdateException ex) { SQLException next = ex.getNextException(); - LOG.error("Failed to load data for TPC-C", ex); + LOG.error("Failed to load data for Web3Bench", ex); if (next != null) LOG.error(ex.getClass().getSimpleName() + " Cause => " + next.getMessage()); fail = true; } catch (SQLException ex) { SQLException next = ex.getNextException(); - LOG.error("Failed to load data for TPC-C", ex); + LOG.error("Failed to load data for Web3Bench", ex); if (next != null) LOG.error(ex.getClass().getSimpleName() + " Cause => " + next.getMessage()); fail = true; } catch (Exception ex) { - LOG.error("Failed to load data for TPC-C", ex); + LOG.error("Failed to load data for Web3Bench", ex); fail = true; } finally { if (fail) { @@ -447,18 +447,18 @@ protected int loadContracts(Connection conn, int w_id, int Kount) { } catch (BatchUpdateException ex) { SQLException next = ex.getNextException(); - LOG.error("Failed to load data for TPC-C", ex); + LOG.error("Failed to load data for Web3Bench", ex); if (next != null) LOG.error(ex.getClass().getSimpleName() + " Cause => " + next.getMessage()); fail = true; } catch (SQLException ex) { SQLException next = ex.getNextException(); - LOG.error("Failed to load data for TPC-C", ex); + LOG.error("Failed to load data for Web3Bench", ex); if (next != null) LOG.error(ex.getClass().getSimpleName() + " Cause => " + next.getMessage()); fail = true; } catch (Exception ex) { - LOG.error("Failed to load data for TPC-C", ex); + LOG.error("Failed to load data for Web3Bench", ex); fail = true; } finally { if (fail) { @@ -632,18 +632,18 @@ protected int loadTransactions(Connection conn, int w_id, int Kount) { } catch (BatchUpdateException ex) { SQLException next = ex.getNextException(); - LOG.error("Failed to load data for TPC-C", ex); + LOG.error("Failed to load data for Web3Bench", ex); if (next != null) LOG.error(ex.getClass().getSimpleName() + " Cause => " + next.getMessage()); fail = true; } catch (SQLException ex) { SQLException next = ex.getNextException(); - LOG.error("Failed to load data for TPC-C", ex); + LOG.error("Failed to load data for Web3Bench", ex); if (next != null) LOG.error(ex.getClass().getSimpleName() + " Cause => " + next.getMessage()); fail = true; } catch (Exception ex) { - LOG.error("Failed to load data for TPC-C", ex); + LOG.error("Failed to load data for Web3Bench", ex); fail = true; } finally { if (fail) { @@ -712,18 +712,18 @@ protected int loadToken_transfers(Connection conn, int w_id, int Kount) { } catch (BatchUpdateException ex) { SQLException next = ex.getNextException(); - LOG.error("Failed to load data for TPC-C", ex); + LOG.error("Failed to load data for Web3Bench", ex); if (next != null) LOG.error(ex.getClass().getSimpleName() + " Cause => " + next.getMessage()); fail = true; } catch (SQLException ex) { SQLException next = ex.getNextException(); - LOG.error("Failed to load data for TPC-C", ex); + LOG.error("Failed to load data for Web3Bench", ex); if (next != null) LOG.error(ex.getClass().getSimpleName() + " Cause => " + next.getMessage()); fail = true; } catch (Exception ex) { - LOG.error("Failed to load data for TPC-C", ex); + LOG.error("Failed to load data for Web3Bench", ex); fail = true; } finally { if (fail) { @@ -796,18 +796,18 @@ public int loadTemptable(Connection conn, int numScale) { conn.commit(); } catch (BatchUpdateException ex) { SQLException next = ex.getNextException(); - LOG.error("Failed to load data for TPC-C", ex); + LOG.error("Failed to load data for Web3Bench", ex); if (next != null) LOG.error(ex.getClass().getSimpleName() + " Cause => " + next.getMessage()); fail = true; } catch (SQLException ex) { SQLException next = ex.getNextException(); - LOG.error("Failed to load data for TPC-C", ex); + LOG.error("Failed to load data for Web3Bench", ex); if (next != null) LOG.error(ex.getClass().getSimpleName() + " Cause => " + next.getMessage()); fail = true; } catch (Exception ex) { - LOG.error("Failed to load data for TPC-C", ex); + LOG.error("Failed to load data for Web3Bench", ex); fail = true; } finally { if (fail) { diff --git a/src/com/olxpbenchmark/benchmarks/web3benchmark/WEB3Worker.java b/src/com/olxpbenchmark/benchmarks/web3benchmark/WEB3Worker.java index 69e0af3..2e6d635 100755 --- a/src/com/olxpbenchmark/benchmarks/web3benchmark/WEB3Worker.java +++ b/src/com/olxpbenchmark/benchmarks/web3benchmark/WEB3Worker.java @@ -48,7 +48,6 @@ import com.olxpbenchmark.WorkloadConfiguration; import com.olxpbenchmark.distributions.CounterGenerator; -import com.olxpbenchmark.distributions.ZipfianGenerator; import com.olxpbenchmark.util.RandomGenerator; public class WEB3Worker extends Worker { @@ -74,7 +73,6 @@ public WEB3Worker(WEB3Benchmark benchmarkModule, int id, String distri, int numS WorkloadConfiguration workConf) throws SQLException { super(benchmarkModule, id); - // zipf = new ZipfianGenerator(100); distribution = distri; this.numScale = numScale; this.startNumber = startNum; @@ -111,10 +109,11 @@ protected long executeWork(TransactionType nextTransaction) throws UserAbortExce int startNumber = startRecord.nextInt(); String nodeid = workConf.getNodeId(); + boolean isExplainAnalyze = workConf.getisExplainAnalyze(); WEB3Procedure proc = (WEB3Procedure) this.getProcedure(nextTransaction.getProcedureClass()); if (distribution.equals("rand")) { - latency_ns = proc.run(conn, gen, this, startNumber, 0, numScale, nodeid); + latency_ns = proc.run(conn, gen, this, startNumber, 0, numScale, nodeid, isExplainAnalyze); } // else if (distribution.equals("zipf")) { // proc.run(conn, numScale, this, startNumber, 0); @@ -123,7 +122,7 @@ protected long executeWork(TransactionType nextTransaction) throws UserAbortExce // proc.run(conn, this, startNumber, 0, numScale, "poisson"); // } else if (distribution.equals("iRand")) { - latency_ns = proc.run(conn, gen, this, startNumber, upperLimit, numScale, nodeid); + latency_ns = proc.run(conn, gen, this, startNumber, upperLimit, numScale, nodeid, isExplainAnalyze); } // else if (distribution.equals("iZipf")) { // proc.run(conn, numScale, this, startNumber, upperLimit); diff --git a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R1.java b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R1.java index d47f29f..108b4c1 100755 --- a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R1.java +++ b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R1.java @@ -34,47 +34,61 @@ import java.util.Random; public class R1 extends WEB3Procedure { - private static final Logger LOG = Logger.getLogger(R1.class); + public String classname = this.getClass().getSimpleName(); + public String classname_note = "/* " + classname + " */ "; // Equality on hash in transaction table - public SQLStmt query_stmtSQL = new SQLStmt( - "/* R1 */ " - + "explain analyze " - + "select to_address, from_address " - + "from transactions " - + "where hash = ? "); - + public String query = "" + + "select to_address, from_address " + + "from transactions " + + "where hash = ? "; private PreparedStatement query_stmt = null; public long run(Connection conn, Random gen, WEB3Worker w, int startNumber, int upperLimit, int numScale, - String nodeid) throws SQLException { + String nodeid, boolean isExplainAnalyze) throws SQLException { + boolean debug = LOG.isDebugEnabled(); boolean trace = LOG.isTraceEnabled(); - // initializing all prepared statements - query_stmt = this.getPreparedStatement(conn, query_stmtSQL); - + // Prepare statement + SQLStmt query_stmtSQL = new SQLStmt( + classname_note + (isExplainAnalyze ? SQL_EXPLAIN_ANALYZE : "") + query); + // Parameters String hash = WEB3Util .convertToTxnHashString(WEB3Util.randomNumber(1, WEB3Config.configTransactionsCount * numScale, gen)); + // Create statement and set parameters + query_stmt = this.getPreparedStatement(conn, query_stmtSQL, hash); - // Set parameter - query_stmt.setString(1, hash); // Log query - if (LOG.isDebugEnabled()) + if (debug) { LOG.debug(queryToString(query_stmt)); - if (trace) - LOG.trace("query_stmt R1 START"); + } + + if (trace) { + LOG.trace("Query" + classname + " START"); + } // Execute query and commit ResultSet rs = query_stmt.executeQuery(); conn.commit(); - if (trace) - LOG.trace("query_stmt R1 END"); + if (trace) { + LOG.trace("Query" + classname + " END"); + } + + if (isExplainAnalyze) { + // If explain analyze, then return the latency + // Get the latency from the result set + long latency_ns = getTimeFromRS(rs); + rs.close(); + return latency_ns; + } + // Log result - if (trace) + if (trace) { LOG.trace(resultSetToString(rs)); + } - long latency_ns = getTimeFromRS(rs); + // Close result set rs.close(); - return latency_ns; + return 0; } } diff --git a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R21.java b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R21.java index 236e12c..5693ae7 100755 --- a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R21.java +++ b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R21.java @@ -34,49 +34,63 @@ import java.util.Random; public class R21 extends WEB3Procedure { - private static final Logger LOG = Logger.getLogger(R21.class); + public String classname = this.getClass().getSimpleName(); + public String classname_note = "/* " + classname + " */ "; // top N with small N on full table scan - public SQLStmt query_stmtSQL = new SQLStmt( - "/* R21 */ " - + "explain analyze " - + "select * " - + "from token_transfers " - + "where from_address = ? " - + "order by block_number desc " - + "limit 5 "); + public String query = "" + + "select * " + + "from token_transfers " + + "where from_address = ? " + + "order by block_number desc " + + "limit 5 "; private PreparedStatement query_stmt = null; public long run(Connection conn, Random gen, WEB3Worker w, int startNumber, int upperLimit, int numScale, - String nodeid) throws SQLException { + String nodeid, boolean isExplainAnalyze) throws SQLException { + boolean debug = LOG.isDebugEnabled(); boolean trace = LOG.isTraceEnabled(); - // initializing all prepared statements - query_stmt = this.getPreparedStatement(conn, query_stmtSQL); - + // Prepare statement + SQLStmt query_stmtSQL = new SQLStmt( + classname_note + (isExplainAnalyze ? SQL_EXPLAIN_ANALYZE : "") + query); + // Parameters String from_address = WEB3Util .convertToAddressString(WEB3Util.randomNumber(1, WEB3Config.configAccountsCount, gen)); + // Create statement and set parameters + query_stmt = this.getPreparedStatement(conn, query_stmtSQL, from_address); - // Set parameter - query_stmt.setString(1, from_address); // Log query - if (LOG.isDebugEnabled()) + if (debug) { LOG.debug(queryToString(query_stmt)); - if (trace) - LOG.trace("query_stmt R21 START"); + } + + if (trace) { + LOG.trace("Query" + classname + " START"); + } // Execute query and commit ResultSet rs = query_stmt.executeQuery(); conn.commit(); - if (trace) - LOG.trace("query_stmt R21 END"); + if (trace) { + LOG.trace("Query" + classname + " END"); + } + + if (isExplainAnalyze) { + // If explain analyze, then return the latency + // Get the latency from the result set + long latency_ns = getTimeFromRS(rs); + rs.close(); + return latency_ns; + } // Log result - if (trace) + if (trace) { LOG.trace(resultSetToString(rs)); + } - long latency_ns = getTimeFromRS(rs); + // Close result set rs.close(); - return latency_ns; + return 0; } } diff --git a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R22.java b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R22.java index ced79f1..b47a1a9 100755 --- a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R22.java +++ b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R22.java @@ -34,47 +34,61 @@ import java.util.Random; public class R22 extends WEB3Procedure { - private static final Logger LOG = Logger.getLogger(R22.class); + public String classname = this.getClass().getSimpleName(); + public String classname_note = "/* " + classname + " */ "; // Aggregation with no group by on a small range - public SQLStmt query_stmtSQL = new SQLStmt( - "/* R22 */ " - + "explain analyze " - + "select count(*) " - + "from token_transfers " - + "where token_address = ? "); + public String query = "" + + "select count(*) " + + "from token_transfers " + + "where token_address = ? "; private PreparedStatement query_stmt = null; public long run(Connection conn, Random gen, WEB3Worker w, int startNumber, int upperLimit, int numScale, - String nodeid) throws SQLException { + String nodeid, boolean isExplainAnalyze) throws SQLException { + boolean debug = LOG.isDebugEnabled(); boolean trace = LOG.isTraceEnabled(); - // initializing all prepared statements - query_stmt = this.getPreparedStatement(conn, query_stmtSQL); - + // Prepare statement + SQLStmt query_stmtSQL = new SQLStmt( + classname_note + (isExplainAnalyze ? SQL_EXPLAIN_ANALYZE : "") + query); + // Parameters String token_address = WEB3Util .convertToTokenAddressString(WEB3Util.randomNumber(1, WEB3Config.configTokenCount, gen)); + // Create statement and set parameters + query_stmt = this.getPreparedStatement(conn, query_stmtSQL, token_address); - // Set parameter - query_stmt.setString(1, token_address); // Log query - if (LOG.isDebugEnabled()) + if (debug) { LOG.debug(queryToString(query_stmt)); - if (trace) - LOG.trace("query_stmt R22 START"); + } + + if (trace) { + LOG.trace("Query" + classname + " START"); + } // Execute query and commit ResultSet rs = query_stmt.executeQuery(); conn.commit(); - if (trace) - LOG.trace("query_stmt R22 END"); + if (trace) { + LOG.trace("Query" + classname + " END"); + } + + if (isExplainAnalyze) { + // If explain analyze, then return the latency + // Get the latency from the result set + long latency_ns = getTimeFromRS(rs); + rs.close(); + return latency_ns; + } // Log result - if (trace) + if (trace) { LOG.trace(resultSetToString(rs)); + } - long latency_ns = getTimeFromRS(rs); + // Close result set rs.close(); - return latency_ns; + return 0; } } diff --git a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R23.java b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R23.java index 9008cfa..47f52c8 100755 --- a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R23.java +++ b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R23.java @@ -34,55 +34,68 @@ import java.util.Random; public class R23 extends WEB3Procedure { - private static final Logger LOG = Logger.getLogger(R23.class); - public SQLStmt query_stmtSQL = new SQLStmt( - "/* R23 */ " - + "explain analyze " - + "select * " - + "from token_transfers " - + "where token_address = ? " - + "and block_number <= ? " - + "and (next_block_number > ? or next_block_number = ?) " - + "order by block_number desc " - + "limit ?"); + public String classname = this.getClass().getSimpleName(); + public String classname_note = "/* " + classname + " */ "; + public String query = "" + + "select * " + + "from token_transfers " + + "where token_address = ? " + + "and block_number <= ? " + + "and (next_block_number > ? or next_block_number = ?) " + + "order by block_number desc " + + "limit ?"; private PreparedStatement query_stmt = null; public long run(Connection conn, Random gen, WEB3Worker w, int startNumber, int upperLimit, int numScale, - String nodeid) throws SQLException { + String nodeid, boolean isExplainAnalyze) throws SQLException { + boolean debug = LOG.isDebugEnabled(); boolean trace = LOG.isTraceEnabled(); - // initializing all prepared statements - query_stmt = this.getPreparedStatement(conn, query_stmtSQL); - + // Prepare statement + SQLStmt query_stmtSQL = new SQLStmt( + classname_note + (isExplainAnalyze ? SQL_EXPLAIN_ANALYZE : "") + query); + // Parameters String token_address = WEB3Util .convertToTokenAddressString(WEB3Util.randomNumber(1, WEB3Config.configTokenCount, gen)); long block_number = WEB3Util.randomNumber(1, numScale * WEB3Config.configBlocksCount, gen); long next_block_number = WEB3Util.randomNumber(1, block_number, gen); int limit = WEB3Util.randomNumber(1, 100, gen); + // Create statement and set parameters + query_stmt = this.getPreparedStatement(conn, query_stmtSQL, token_address, block_number, next_block_number, + next_block_number, limit); - query_stmt.setString(1, token_address); - query_stmt.setLong(2, block_number); - query_stmt.setLong(3, next_block_number); - query_stmt.setLong(4, next_block_number); - query_stmt.setInt(5, limit); // Log query - if (LOG.isDebugEnabled()) + if (debug) { LOG.debug(queryToString(query_stmt)); - if (trace) - LOG.trace("query_stmt R23 START"); + } + + if (trace) { + LOG.trace("Query" + classname + " START"); + } + // Execute query and commit ResultSet rs = query_stmt.executeQuery(); conn.commit(); - if (trace) - LOG.trace("query_stmt R23 END"); + if (trace) { + LOG.trace("Query" + classname + " END"); + } + + if (isExplainAnalyze) { + // If explain analyze, then return the latency + // Get the latency from the result set + long latency_ns = getTimeFromRS(rs); + rs.close(); + return latency_ns; + } // Log result - if (trace) + if (trace) { LOG.trace(resultSetToString(rs)); + } - long latency_ns = getTimeFromRS(rs); + // Close result set rs.close(); - return latency_ns; + return 0; } } diff --git a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R24.java b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R24.java index f2be038..b136469 100755 --- a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R24.java +++ b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R24.java @@ -34,53 +34,65 @@ import java.util.Random; public class R24 extends WEB3Procedure { - private static final Logger LOG = Logger.getLogger(R24.class); + public String classname = this.getClass().getSimpleName(); + public String classname_note = "/* " + classname + " */ "; // List of transactions excluding some black listed ones. - public SQLStmt query_to_address_SQL = new SQLStmt( - "/* R24 */ " - + "explain analyze " - + "select count(*) " - + "from transactions " - + "where to_address not in (?, ?, ?) "); + public String query = "" + + "select count(*) " + + "from transactions " + + "where to_address not in (?, ?, ?) "; private PreparedStatement query_stmt = null; public long run(Connection conn, Random gen, WEB3Worker w, int startNumber, int upperLimit, int numScale, - String nodeid) throws SQLException { + String nodeid, boolean isExplainAnalyze) throws SQLException { + boolean debug = LOG.isDebugEnabled(); boolean trace = LOG.isTraceEnabled(); - // initializing all prepared statements - query_stmt = this.getPreparedStatement(conn, query_to_address_SQL); - + // Prepare statement + SQLStmt query_stmtSQL = new SQLStmt( + classname_note + (isExplainAnalyze ? SQL_EXPLAIN_ANALYZE : "") + query); + // Parameters String to_address1 = WEB3Util .convertToAddressString(WEB3Util.randomNumber(1, WEB3Config.configAccountsCount, gen)); String to_address2 = WEB3Util .convertToAddressString(WEB3Util.randomNumber(1, WEB3Config.configAccountsCount, gen)); String to_address3 = WEB3Util .convertToAddressString(WEB3Util.randomNumber(1, WEB3Config.configAccountsCount, gen)); + // Create statement and set parameters + query_stmt = this.getPreparedStatement(conn, query_stmtSQL, to_address1, to_address2, to_address3); - // Set parameter - query_stmt.setString(1, to_address1); - query_stmt.setString(2, to_address2); - query_stmt.setString(3, to_address3); // Log query - if (LOG.isDebugEnabled()) + if (debug) { LOG.debug(queryToString(query_stmt)); - if (trace) - LOG.trace("query_stmt R24 START"); + } + + if (trace) { + LOG.trace("Query" + classname + " START"); + } // Execute query and commit ResultSet rs = query_stmt.executeQuery(); conn.commit(); - if (trace) - LOG.trace("query_stmt R24 END"); + if (trace) { + LOG.trace("Query" + classname + " END"); + } + + if (isExplainAnalyze) { + // If explain analyze, then return the latency + // Get the latency from the result set + long latency_ns = getTimeFromRS(rs); + rs.close(); + return latency_ns; + } // Log result - if (trace) + if (trace) { LOG.trace(resultSetToString(rs)); + } - long latency_ns = getTimeFromRS(rs); + // Close result set rs.close(); - return latency_ns; + return 0; } } diff --git a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R25.java b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R25.java index eaf2d87..8a25707 100755 --- a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R25.java +++ b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R25.java @@ -34,43 +34,60 @@ import java.util.Random; public class R25 extends WEB3Procedure { - private static final Logger LOG = Logger.getLogger(R25.class); + public String classname = this.getClass().getSimpleName(); + public String classname_note = "/* " + classname + " */ "; // Constraint checking that next_block_number <= block_number in token_transfers // Query result should be empty. - public SQLStmt query_SQL = new SQLStmt( - "/* R25 */ " - + "explain analyze " - + "select count(*) " - + "from token_transfers " - + "where next_block_number <= block_number " - + "group by next_block_number "); + public String query = "" + + "select count(*) " + + "from token_transfers " + + "where next_block_number <= block_number " + + "group by next_block_number "; private PreparedStatement query_stmt = null; public long run(Connection conn, Random gen, WEB3Worker w, int startNumber, int upperLimit, int numScale, - String nodeid) throws SQLException { + String nodeid, boolean isExplainAnalyze) throws SQLException { + boolean debug = LOG.isDebugEnabled(); boolean trace = LOG.isTraceEnabled(); - // initializing all prepared statements - query_stmt = this.getPreparedStatement(conn, query_SQL); + // Prepare statement + SQLStmt query_stmtSQL = new SQLStmt( + classname_note + (isExplainAnalyze ? SQL_EXPLAIN_ANALYZE : "") + query); + // Create statement and set parameters + query_stmt = this.getPreparedStatement(conn, query_stmtSQL); + // Log query - if (LOG.isDebugEnabled()) + if (debug) { LOG.debug(queryToString(query_stmt)); - if (trace) - LOG.trace("query_stmt R25 START"); + } + + if (trace) { + LOG.trace("Query" + classname + " START"); + } // Execute query and commit ResultSet rs = query_stmt.executeQuery(); conn.commit(); - if (trace) - LOG.trace("query_stmt R25 END"); + if (trace) { + LOG.trace("Query" + classname + " END"); + } + + if (isExplainAnalyze) { + // If explain analyze, then return the latency + // Get the latency from the result set + long latency_ns = getTimeFromRS(rs); + rs.close(); + return latency_ns; + } // Log result - if (trace) + if (trace) { LOG.trace(resultSetToString(rs)); + } - long latency_ns = getTimeFromRS(rs); + // Close result set rs.close(); - return latency_ns; + return 0; } } diff --git a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R31.java b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R31.java index 3ed7768..8d96ee8 100755 --- a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R31.java +++ b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R31.java @@ -34,50 +34,65 @@ import java.util.Random; public class R31 extends WEB3Procedure { - private static final Logger LOG = Logger.getLogger(R31.class); + public String classname = this.getClass().getSimpleName(); + public String classname_note = "/* " + classname + " */ "; // For a specific person, find transactions where this person is either a sender // or receiver. Limit the result by the most recent timestamp. - public SQLStmt query_stmtSQL = new SQLStmt( - "/* R31 */ " - + "explain analyze " - + "select * " - + "from transactions " - + "where from_address = ? or to_address = ? " - + "order by block_timestamp desc " - + "limit 10"); + public String query = "" + + "select * " + + "from transactions " + + "where from_address = ? or to_address = ? " + + "order by block_timestamp desc " + + "limit 10"; private PreparedStatement query_stmt = null; public long run(Connection conn, Random gen, WEB3Worker w, int startNumber, int upperLimit, int numScale, - String nodeid) throws SQLException { + String nodeid, boolean isExplainAnalyze) throws SQLException { + boolean debug = LOG.isDebugEnabled(); boolean trace = LOG.isTraceEnabled(); - // initializing prepared statements - query_stmt = this.getPreparedStatement(conn, query_stmtSQL); - + // Prepare statement + SQLStmt query_stmtSQL = new SQLStmt( + classname_note + (isExplainAnalyze ? SQL_EXPLAIN_ANALYZE : "") + query); + // Parameters String from_address = WEB3Util .convertToAddressString(WEB3Util.randomNumber(1, WEB3Config.configAccountsCount, gen)); String to_address = from_address; // one person + // Create statement and set parameters + query_stmt = this.getPreparedStatement(conn, query_stmtSQL, from_address, to_address); - query_stmt.setString(1, from_address); - query_stmt.setString(2, to_address); // Log query - if (LOG.isDebugEnabled()) + if (debug) { LOG.debug(queryToString(query_stmt)); - if (trace) - LOG.trace("query_stmt R31 START"); + } + + if (trace) { + LOG.trace("Query" + classname + " START"); + } + // Execute query and commit ResultSet rs = query_stmt.executeQuery(); conn.commit(); - if (trace) - LOG.trace("query_stmt R31 END"); + if (trace) { + LOG.trace("Query" + classname + " END"); + } + + if (isExplainAnalyze) { + // If explain analyze, then return the latency + // Get the latency from the result set + long latency_ns = getTimeFromRS(rs); + rs.close(); + return latency_ns; + } // Log result - if (trace) + if (trace) { LOG.trace(resultSetToString(rs)); + } - long latency_ns = getTimeFromRS(rs); + // Close result set rs.close(); - return latency_ns; + return 0; } } diff --git a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R32.java b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R32.java index 27bc1c1..c0fafa3 100755 --- a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R32.java +++ b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R32.java @@ -34,42 +34,59 @@ import java.util.Random; public class R32 extends WEB3Procedure { - private static final Logger LOG = Logger.getLogger(R32.class); + public String classname = this.getClass().getSimpleName(); + public String classname_note = "/* " + classname + " */ "; // Top N transactions based on block timestamp. - public SQLStmt query_stmtSQL = new SQLStmt( - "/* R32 */ " - + "explain analyze " - + "select * " - + "from transactions " - + "order by block_timestamp desc " - + "limit 100"); + public String query = "" + + "select * " + + "from transactions " + + "order by block_timestamp desc " + + "limit 100"; private PreparedStatement query_stmt = null; public long run(Connection conn, Random gen, WEB3Worker w, int startNumber, int upperLimit, int numScale, - String nodeid) throws SQLException { + String nodeid, boolean isExplainAnalyze) throws SQLException { + boolean debug = LOG.isDebugEnabled(); boolean trace = LOG.isTraceEnabled(); - // initializing prepared statements + // Prepare statement + SQLStmt query_stmtSQL = new SQLStmt( + classname_note + (isExplainAnalyze ? SQL_EXPLAIN_ANALYZE : "") + query); + // Create statement and set parameters query_stmt = this.getPreparedStatement(conn, query_stmtSQL); + // Log query - if (LOG.isDebugEnabled()) + if (debug) { LOG.debug(queryToString(query_stmt)); + } - if (trace) - LOG.trace("query_stmt R32 START"); + if (trace) { + LOG.trace("Query" + classname + " START"); + } + // Execute query and commit ResultSet rs = query_stmt.executeQuery(); conn.commit(); - if (trace) - LOG.trace("query_stmt R32 END"); + if (trace) { + LOG.trace("Query" + classname + " END"); + } + + if (isExplainAnalyze) { + // If explain analyze, then return the latency + // Get the latency from the result set + long latency_ns = getTimeFromRS(rs); + rs.close(); + return latency_ns; + } // Log result - if (trace) + if (trace) { LOG.trace(resultSetToString(rs)); + } - long latency_ns = getTimeFromRS(rs); + // Close result set rs.close(); - return latency_ns; + return 0; } } diff --git a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R33.java b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R33.java index 699b41b..2766960 100755 --- a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R33.java +++ b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R33.java @@ -34,39 +34,57 @@ import java.util.Random; public class R33 extends WEB3Procedure { - private static final Logger LOG = Logger.getLogger(R33.class); + public String classname = this.getClass().getSimpleName(); + public String classname_note = "/* " + classname + " */ "; // Find the number of unique senders (from\_address) in transactions - public SQLStmt query_stmtSQL = new SQLStmt( - "/* R33 */ " - + "explain analyze " - + "select count(distinct from_address) " - + "from transactions "); + public String query = "" + + "select count(distinct from_address) " + + "from transactions "; private PreparedStatement query_stmt = null; public long run(Connection conn, Random gen, WEB3Worker w, int startNumber, int upperLimit, int numScale, - String nodeid) throws SQLException { + String nodeid, boolean isExplainAnalyze) throws SQLException { + boolean debug = LOG.isDebugEnabled(); boolean trace = LOG.isTraceEnabled(); - // initializing prepared statements + // Prepare statement + SQLStmt query_stmtSQL = new SQLStmt( + classname_note + (isExplainAnalyze ? SQL_EXPLAIN_ANALYZE : "") + query); + // Create statement and set parameters query_stmt = this.getPreparedStatement(conn, query_stmtSQL); + // Log query - if (LOG.isDebugEnabled()) + if (debug) { LOG.debug(queryToString(query_stmt)); - if (trace) - LOG.trace("query_stmt R33 START"); + } + + if (trace) { + LOG.trace("Query" + classname + " START"); + } + // Execute query and commit ResultSet rs = query_stmt.executeQuery(); conn.commit(); - if (trace) - LOG.trace("query_stmt R33 END"); + if (trace) { + LOG.trace("Query" + classname + " END"); + } + + if (isExplainAnalyze) { + // If explain analyze, then return the latency + // Get the latency from the result set + long latency_ns = getTimeFromRS(rs); + rs.close(); + return latency_ns; + } // Log result - if (trace) + if (trace) { LOG.trace(resultSetToString(rs)); + } - long latency_ns = getTimeFromRS(rs); + // Close result set rs.close(); - return latency_ns; + return 0; } } diff --git a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R34.java b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R34.java index 10571ce..6adc8f9 100755 --- a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R34.java +++ b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R34.java @@ -34,46 +34,64 @@ import java.util.Random; public class R34 extends WEB3Procedure { - private static final Logger LOG = Logger.getLogger(R34.class); + public String classname = this.getClass().getSimpleName(); + public String classname_note = "/* " + classname + " */ "; // Find top N senders (from\_address) by total transaction value - public SQLStmt query_stmtSQL = new SQLStmt( - "/* R34 */ " - + "explain analyze " - + "select " - + "sum(value) as totalamount, " - + "count(value) as transactioncount, " - + "from_address as fromaddress " - + "from transactions " - + "group by from_address " - + "order by sum(value) desc " - + "limit 10 "); + public String query = "" + + "select " + + "sum(value) as totalamount, " + + "count(value) as transactioncount, " + + "from_address as fromaddress " + + "from transactions " + + "group by from_address " + + "order by sum(value) desc " + + "limit 10 "; private PreparedStatement query_stmt = null; public long run(Connection conn, Random gen, WEB3Worker w, int startNumber, int upperLimit, int numScale, - String nodeid) throws SQLException { + String nodeid, boolean isExplainAnalyze) throws SQLException { + boolean debug = LOG.isDebugEnabled(); boolean trace = LOG.isTraceEnabled(); // initializing prepared statements + // Prepare statement + SQLStmt query_stmtSQL = new SQLStmt( + classname_note + (isExplainAnalyze ? SQL_EXPLAIN_ANALYZE : "") + query); + // Create statement and set parameters query_stmt = this.getPreparedStatement(conn, query_stmtSQL); + // Log query - if (LOG.isDebugEnabled()) + if (debug) { LOG.debug(queryToString(query_stmt)); + } - if (trace) - LOG.trace("query_stmt R34 START"); + if (trace) { + LOG.trace("Query" + classname + " START"); + } + // Execute query and commit ResultSet rs = query_stmt.executeQuery(); conn.commit(); - if (trace) - LOG.trace("query_stmt R34 END"); + if (trace) { + LOG.trace("Query" + classname + " END"); + } + + if (isExplainAnalyze) { + // If explain analyze, then return the latency + // Get the latency from the result set + long latency_ns = getTimeFromRS(rs); + rs.close(); + return latency_ns; + } // Log result - if (trace) + if (trace) { LOG.trace(resultSetToString(rs)); + } - long latency_ns = getTimeFromRS(rs); + // Close result set rs.close(); - return latency_ns; + return 0; } } diff --git a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R35.java b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R35.java index 1629bbd..b0953a8 100755 --- a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R35.java +++ b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R35.java @@ -34,56 +34,72 @@ import java.util.Random; public class R35 extends WEB3Procedure { - private static final Logger LOG = Logger.getLogger(R35.class); + public String classname = this.getClass().getSimpleName(); + public String classname_note = "/* " + classname + " */ "; // Total count of token transfers for a specific sender and token transfers for // recipients who are also senders in other transactions. - public SQLStmt query_stmtSQL = new SQLStmt( - "/* R35 */ " - + "explain analyze " - + "select count(*) as count " - + "from " - + "( " - + "select * " - + "from token_transfers t " - + "where from_address = ? " - + "union all " - + "select t2.* " - + "from token_transfers t2 " - + "inner join token_transfers t on t2.from_address = t.to_address " - + "and t.value < t2.value " - + ") as temp "); + public String query = "" + + "select count(*) as count " + + "from " + + "( " + + "select * " + + "from token_transfers t " + + "where from_address = ? " + + "union all " + + "select t2.* " + + "from token_transfers t2 " + + "inner join token_transfers t on t2.from_address = t.to_address " + + "and t.value < t2.value " + + ") as temp "; private PreparedStatement query_stmt = null; public long run(Connection conn, Random gen, WEB3Worker w, int startNumber, int upperLimit, int numScale, - String nodeid) throws SQLException { + String nodeid, boolean isExplainAnalyze) throws SQLException { + boolean debug = LOG.isDebugEnabled(); boolean trace = LOG.isTraceEnabled(); // initializing prepared statements - query_stmt = this.getPreparedStatement(conn, query_stmtSQL); - + // Prepare statement + SQLStmt query_stmtSQL = new SQLStmt( + classname_note + (isExplainAnalyze ? SQL_EXPLAIN_ANALYZE : "") + query); + // Parameters String from_address = WEB3Util .convertToAddressString(WEB3Util.randomNumber(1, WEB3Config.configAccountsCount, gen)); + // Create statement and set parameters + query_stmt = this.getPreparedStatement(conn, query_stmtSQL, from_address); - query_stmt.setString(1, from_address); // Log query - if (LOG.isDebugEnabled()) + if (debug) { LOG.debug(queryToString(query_stmt)); + } - if (trace) - LOG.trace("query_stmt R35 START"); + if (trace) { + LOG.trace("Query" + classname + " START"); + } + // Execute query and commit ResultSet rs = query_stmt.executeQuery(); conn.commit(); - if (trace) - LOG.trace("query_stmt R35 END"); + if (trace) { + LOG.trace("Query" + classname + " END"); + } + + if (isExplainAnalyze) { + // If explain analyze, then return the latency + // Get the latency from the result set + long latency_ns = getTimeFromRS(rs); + rs.close(); + return latency_ns; + } // Log result - if (trace) + if (trace) { LOG.trace(resultSetToString(rs)); + } - long latency_ns = getTimeFromRS(rs); + // Close result set rs.close(); - return latency_ns; + return 0; } } diff --git a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W11.java b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W11.java index 946082f..fc3dc05 100755 --- a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W11.java +++ b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W11.java @@ -32,26 +32,28 @@ import com.olxpbenchmark.benchmarks.web3benchmark.WEB3Worker; public class W11 extends WEB3Procedure { - private static final Logger LOG = Logger.getLogger(W11.class); - public SQLStmt query_stmtSQL = new SQLStmt( - "/* W11 */ " - + "explain analyze " - + "insert into blocks " - + "values " - + "(?, ?, ?, ?, ?," - + " ?, ?, ?, ?, ?," - + " ?, ?, ?, ?, ?," - + " ?, ?, ?)"); - + public String classname = this.getClass().getSimpleName(); + public String classname_note = "/* " + classname + " */ "; + public String query = "" + + "insert into blocks " + + "values " + + "(?, ?, ?, ?, ?," + + " ?, ?, ?, ?, ?," + + " ?, ?, ?, ?, ?," + + " ?, ?, ?)"; private PreparedStatement query_stmt = null; public long run(Connection conn, Random gen, WEB3Worker w, int startNumber, int upperLimit, int numScale, - String nodeid) throws SQLException { + String nodeid, boolean isExplainAnalyze) throws SQLException { + boolean debug = LOG.isDebugEnabled(); boolean trace = LOG.isTraceEnabled(); - // initializing all prepared statements + // Prepare statement + SQLStmt query_stmtSQL = new SQLStmt( + classname_note + (isExplainAnalyze ? SQL_EXPLAIN_ANALYZE : "") + query); + // Create statement and set parameters query_stmt = this.getPreparedStatement(conn, query_stmtSQL); long number = numScale * WEB3Config.configBlocksCount + startNumber; @@ -93,20 +95,41 @@ public long run(Connection conn, Random gen, WEB3Worker w, int startNumber, int query_stmt.setLong(idx++, transaction_count); query_stmt.setLong(idx++, base_fee_per_gas); - if (LOG.isDebugEnabled()) { + // Log query + if (debug) { LOG.debug(queryToString(query_stmt)); } - if (trace) - LOG.trace("query_stmt W11 InsertBlocks START"); - // int affectedRows = query_stmt.executeUpdate(); - ResultSet rs = query_stmt.executeQuery(); + if (trace) { + LOG.trace("Query" + classname + " START"); + } + int affectedRows = 0; // Number of rows affected + ResultSet rs = null; + // Execute query and commit + if (isExplainAnalyze) { + // Use executeQuery for explain analyze + rs = query_stmt.executeQuery(); + } else { + // Use executeUpdate for normal query + affectedRows = query_stmt.executeUpdate(); + } conn.commit(); - if (trace) - LOG.trace("query_stmt W11 InsertBlocks END"); + if (trace) { + LOG.trace("Query" + classname + " END"); + } + + if (isExplainAnalyze) { + // If explain analyze, then return the latency + // Get the latency from the result set + long latency_ns = getTimeFromRS(rs); + rs.close(); + return latency_ns; + } else { + if (debug) { + LOG.debug("Affected Rows: " + affectedRows); + } + } - long latency_ns = getTimeFromRS(rs); - rs.close(); - return latency_ns; + return 0; } } diff --git a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W12.java b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W12.java index be5b12f..ff76b47 100755 --- a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W12.java +++ b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W12.java @@ -32,22 +32,24 @@ import com.olxpbenchmark.benchmarks.web3benchmark.WEB3Worker; public class W12 extends WEB3Procedure { - private static final Logger LOG = Logger.getLogger(W12.class); - public SQLStmt query_stmtSQL = new SQLStmt( - "/* W12 */ " - + "explain analyze " - + "insert into contracts " - + "values (?, ?, ?, ?, ?, ?) "); - + public String classname = this.getClass().getSimpleName(); + public String classname_note = "/* " + classname + " */ "; + public String query = "" + + "insert into contracts " + + "values (?, ?, ?, ?, ?, ?) "; private PreparedStatement query_stmt = null; public long run(Connection conn, Random gen, WEB3Worker w, int startNumber, int upperLimit, int numScale, - String nodeid) throws SQLException { + String nodeid, boolean isExplainAnalyze) throws SQLException { + boolean debug = LOG.isDebugEnabled(); boolean trace = LOG.isTraceEnabled(); - // initializing all prepared statements + // Prepare statement + SQLStmt query_stmtSQL = new SQLStmt( + classname_note + (isExplainAnalyze ? SQL_EXPLAIN_ANALYZE : "") + query); + // Create statement and set parameters query_stmt = this.getPreparedStatement(conn, query_stmtSQL); String address = WEB3Util @@ -66,20 +68,41 @@ public long run(Connection conn, Random gen, WEB3Worker w, int startNumber, int query_stmt.setBoolean(idx++, is_erc721); query_stmt.setLong(idx++, block_number); - if (LOG.isDebugEnabled()) { + // Log query + if (debug) { LOG.debug(queryToString(query_stmt)); } - if (trace) - LOG.trace("query_stmt W12 InsertContracts START"); - // int affectedRows = query_stmt.executeUpdate(); - ResultSet rs = query_stmt.executeQuery(); + if (trace) { + LOG.trace("Query" + classname + " START"); + } + int affectedRows = 0; // Number of rows affected + ResultSet rs = null; + // Execute query and commit + if (isExplainAnalyze) { + // Use executeQuery for explain analyze + rs = query_stmt.executeQuery(); + } else { + // Use executeUpdate for normal query + affectedRows = query_stmt.executeUpdate(); + } conn.commit(); - if (trace) - LOG.trace("query_stmt W12 InsertContracts END"); + if (trace) { + LOG.trace("Query" + classname + " END"); + } + + if (isExplainAnalyze) { + // If explain analyze, then return the latency + // Get the latency from the result set + long latency_ns = getTimeFromRS(rs); + rs.close(); + return latency_ns; + } else { + if (debug) { + LOG.debug("Affected Rows: " + affectedRows); + } + } - long latency_ns = getTimeFromRS(rs); - rs.close(); - return latency_ns; + return 0; } } diff --git a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W13.java b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W13.java index 325c230..11764c6 100755 --- a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W13.java +++ b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W13.java @@ -32,26 +32,28 @@ import com.olxpbenchmark.benchmarks.web3benchmark.WEB3Worker; public class W13 extends WEB3Procedure { - private static final Logger LOG = Logger.getLogger(W13.class); - public SQLStmt query_stmtSQL = new SQLStmt( - "/* W13 */ " - + "explain analyze " - + "insert into transactions " - + "values " - + "(?, ?, ?, ?, ?," - + " ?, ?, ?, ?, ?," - + " ?, ?, ?, ?, ?," - + " ?, ?, ?, ?, ?)"); - + public String classname = this.getClass().getSimpleName(); + public String classname_note = "/* " + classname + " */ "; + public String query = "" + + "insert into transactions " + + "values " + + "(?, ?, ?, ?, ?," + + " ?, ?, ?, ?, ?," + + " ?, ?, ?, ?, ?," + + " ?, ?, ?, ?, ?)"; private PreparedStatement query_stmt = null; public long run(Connection conn, Random gen, WEB3Worker w, int startNumber, int upperLimit, int numScale, - String nodeid) throws SQLException { + String nodeid, boolean isExplainAnalyze) throws SQLException { + boolean debug = LOG.isDebugEnabled(); boolean trace = LOG.isTraceEnabled(); - // initializing all prepared statements + // Prepare statement + SQLStmt query_stmtSQL = new SQLStmt( + classname_note + (isExplainAnalyze ? SQL_EXPLAIN_ANALYZE : "") + query); + // Create statement and set parameters query_stmt = this.getPreparedStatement(conn, query_stmtSQL); String hash = WEB3Util.convertToTxnHashString(startNumber, nodeid + "-W13"); @@ -100,20 +102,41 @@ public long run(Connection conn, Random gen, WEB3Worker w, int startNumber, int query_stmt.setLong(idx++, max_priority_fee_per_gas); query_stmt.setLong(idx++, transaction_type); - if (LOG.isDebugEnabled()) { + // Log query + if (debug) { LOG.debug(queryToString(query_stmt)); } - if (trace) - LOG.trace("query_stmt W13 InsertTransactions START"); - // int affectedRows = query_stmt.executeUpdate(); - ResultSet rs = query_stmt.executeQuery(); + if (trace) { + LOG.trace("Query" + classname + " START"); + } + int affectedRows = 0; // Number of rows affected + ResultSet rs = null; + // Execute query and commit + if (isExplainAnalyze) { + // Use executeQuery for explain analyze + rs = query_stmt.executeQuery(); + } else { + // Use executeUpdate for normal query + affectedRows = query_stmt.executeUpdate(); + } conn.commit(); - if (trace) - LOG.trace("query_stmt W13 InsertTransactions END"); + if (trace) { + LOG.trace("Query" + classname + " END"); + } + + if (isExplainAnalyze) { + // If explain analyze, then return the latency + // Get the latency from the result set + long latency_ns = getTimeFromRS(rs); + rs.close(); + return latency_ns; + } else { + if (debug) { + LOG.debug("Affected Rows: " + affectedRows); + } + } - long latency_ns = getTimeFromRS(rs); - rs.close(); - return latency_ns; + return 0; } } diff --git a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W14.java b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W14.java index 0411062..a87d29c 100755 --- a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W14.java +++ b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W14.java @@ -32,23 +32,25 @@ import com.olxpbenchmark.benchmarks.web3benchmark.WEB3Worker; public class W14 extends WEB3Procedure { - private static final Logger LOG = Logger.getLogger(W14.class); - public SQLStmt query_stmtSQL = new SQLStmt( - "/* W14 */ " - + "explain analyze " - + "insert into token_transfers " - + "values " - + "(?, ?, ?, ?, ?, ?, ?)"); - + public String classname = this.getClass().getSimpleName(); + public String classname_note = "/* " + classname + " */ "; + public String query = "" + + "insert into token_transfers " + + "values " + + "(?, ?, ?, ?, ?, ?, ?)"; private PreparedStatement query_stmt = null; public long run(Connection conn, Random gen, WEB3Worker w, int startNumber, int upperLimit, int numScale, - String nodeid) throws SQLException { + String nodeid, boolean isExplainAnalyze) throws SQLException { + boolean debug = LOG.isDebugEnabled(); boolean trace = LOG.isTraceEnabled(); - // initializing all prepared statements + // Prepare statement + SQLStmt query_stmtSQL = new SQLStmt( + classname_note + (isExplainAnalyze ? SQL_EXPLAIN_ANALYZE : "") + query); + // Create statement and set parameters query_stmt = this.getPreparedStatement(conn, query_stmtSQL); String token_address = WEB3Util @@ -76,20 +78,41 @@ public long run(Connection conn, Random gen, WEB3Worker w, int startNumber, int query_stmt.setLong(idx++, block_number); query_stmt.setLong(idx++, next_block_number); - if (LOG.isDebugEnabled()) { + // Log query + if (debug) { LOG.debug(queryToString(query_stmt)); } - if (trace) - LOG.trace("query_stmt W14 InsertTokenTransfers START"); - // int affectedRows = query_stmt.executeUpdate(); - ResultSet rs = query_stmt.executeQuery(); + if (trace) { + LOG.trace("Query" + classname + " START"); + } + int affectedRows = 0; // Number of rows affected + ResultSet rs = null; + // Execute query and commit + if (isExplainAnalyze) { + // Use executeQuery for explain analyze + rs = query_stmt.executeQuery(); + } else { + // Use executeUpdate for normal query + affectedRows = query_stmt.executeUpdate(); + } conn.commit(); - if (trace) - LOG.trace("query_stmt W14 InsertTokenTransfers END"); + if (trace) { + LOG.trace("Query" + classname + " END"); + } + + if (isExplainAnalyze) { + // If explain analyze, then return the latency + // Get the latency from the result set + long latency_ns = getTimeFromRS(rs); + rs.close(); + return latency_ns; + } else { + if (debug) { + LOG.debug("Affected Rows: " + affectedRows); + } + } - long latency_ns = getTimeFromRS(rs); - rs.close(); - return latency_ns; + return 0; } } diff --git a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W2.java b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W2.java index fd7bf28..b6bcb19 100755 --- a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W2.java +++ b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W2.java @@ -33,28 +33,30 @@ import com.olxpbenchmark.benchmarks.web3benchmark.WEB3Worker; public class W2 extends WEB3Procedure { - private static final Logger LOG = Logger.getLogger(W2.class); - public SQLStmt query_stmtSQL = new SQLStmt( - "/* W2 */ " - + "explain analyze " - + "insert into transactions " - + "values " - // Java 11 - // + "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?), ".repeat(99) - // Java 7 - + new String(new char[99]).replace("\0", - "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?), ") - + "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); - + public String classname = this.getClass().getSimpleName(); + public String classname_note = "/* " + classname + " */ "; + public String query = "" + + "insert into transactions " + + "values " + // Java 11 + // + "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?), ".repeat(99) + // Java 7 + + new String(new char[99]).replace("\0", + "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?), ") + + "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; private PreparedStatement query_stmt = null; public long run(Connection conn, Random gen, WEB3Worker w, int startNumber, int upperLimit, int numScale, - String nodeid) throws SQLException { + String nodeid, boolean isExplainAnalyze) throws SQLException { + boolean debug = LOG.isDebugEnabled(); boolean trace = LOG.isTraceEnabled(); - // initializing all prepared statements + // Prepare statement + SQLStmt query_stmtSQL = new SQLStmt( + classname_note + (isExplainAnalyze ? SQL_EXPLAIN_ANALYZE : "") + query); + // Create statement and set parameters query_stmt = this.getPreparedStatement(conn, query_stmtSQL); // Small batch inserts (100 rows) for the transaction table. @@ -108,21 +110,41 @@ public long run(Connection conn, Random gen, WEB3Worker w, int startNumber, int query_stmt.setLong(idx++, transaction_type); } - // Log query and affected rows - if (LOG.isDebugEnabled()) { + // Log query + if (debug) { LOG.debug(queryToString(query_stmt)); - // LOG.debug("Result: " + resultSetToString(rs)); } - if (trace) - LOG.trace("query_stmt W2 RangeInsertTransactions START"); - ResultSet rs = query_stmt.executeQuery(); + if (trace) { + LOG.trace("Query" + classname + " START"); + } + int[] affectedRows = null; // Number of rows affected + ResultSet rs = null; + // Execute query and commit + if (isExplainAnalyze) { + // Use executeQuery for explain analyze + rs = query_stmt.executeQuery(); + } else { + // Use executeUpdate/Batch for normal queries + affectedRows = query_stmt.executeBatch(); + } conn.commit(); - if (trace) - LOG.trace("query_stmt W2 RangeInsertTransactions END"); + if (trace) { + LOG.trace("Query" + classname + " END"); + } + + if (isExplainAnalyze) { + // If explain analyze, then return the latency + // Get the latency from the result set + long latency_ns = getTimeFromRS(rs); + rs.close(); + return latency_ns; + } else { + if (debug) { + LOG.debug("Affected Rows: " + affectedRows.length); + } + } - long latency_ns = getTimeFromRS(rs); - rs.close(); - return latency_ns; + return 0; } } diff --git a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W3.java b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W3.java index c6916a8..8d86005 100755 --- a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W3.java +++ b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W3.java @@ -31,39 +31,62 @@ import com.olxpbenchmark.benchmarks.web3benchmark.WEB3Worker; public class W3 extends WEB3Procedure { - private static final Logger LOG = Logger.getLogger(W3.class); + public String classname = this.getClass().getSimpleName(); + public String classname_note = "/* " + classname + " */ "; // Insert 1000 rows into transactions from a temp table - public SQLStmt query_stmtSQL = new SQLStmt( - "/* W3 */ " - + "explain analyze " - + "insert transactions " - + "select * from temp_table limit 1000 "); - + public String query = "" + + "insert transactions " + + "select * from temp_table limit 1000 "; private PreparedStatement query_stmt = null; public long run(Connection conn, Random gen, WEB3Worker w, int startNumber, int upperLimit, int numScale, - String nodeid) throws SQLException { + String nodeid, boolean isExplainAnalyze) throws SQLException { + boolean debug = LOG.isDebugEnabled(); boolean trace = LOG.isTraceEnabled(); - // initializing all prepared statements + // Prepare statement + SQLStmt query_stmtSQL = new SQLStmt( + classname_note + (isExplainAnalyze ? SQL_EXPLAIN_ANALYZE : "") + query); + // Create statement and set parameters query_stmt = this.getPreparedStatement(conn, query_stmtSQL); - if (LOG.isDebugEnabled()) { + // Log query + if (debug) { LOG.debug(queryToString(query_stmt)); } - if (trace) - LOG.trace("query_stmt W3 InsertSelect START"); - // int affectedRows = query_stmt.executeUpdate(); - ResultSet rs = query_stmt.executeQuery(); + if (trace) { + LOG.trace("Query" + classname + " START"); + } + int affectedRows = 0; // Number of rows affected + ResultSet rs = null; + // Execute query and commit + if (isExplainAnalyze) { + // Use executeQuery for explain analyze + rs = query_stmt.executeQuery(); + } else { + // Use executeUpdate for normal query + affectedRows = query_stmt.executeUpdate(); + } conn.commit(); - if (trace) - LOG.trace("query_stmt W3 InsertSelect END"); + if (trace) { + LOG.trace("Query" + classname + " END"); + } + + if (isExplainAnalyze) { + // If explain analyze, then return the latency + // Get the latency from the result set + long latency_ns = getTimeFromRS(rs); + rs.close(); + return latency_ns; + } else { + if (debug) { + LOG.debug("Affected Rows: " + affectedRows); + } + } - long latency_ns = getTimeFromRS(rs); - rs.close(); - return latency_ns; + return 0; } } diff --git a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W4.java b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W4.java index ebbfd4c..7e19005 100755 --- a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W4.java +++ b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W4.java @@ -35,44 +35,66 @@ import java.util.List; public class W4 extends WEB3Procedure { - private static final Logger LOG = Logger.getLogger(W4.class); - public SQLStmt query_stmtSQL = new SQLStmt( - "/* W4 */ " - + "explain analyze " - + "update transactions " - + "set gas_price = ? " - + "where hash = ? "); - + public String classname = this.getClass().getSimpleName(); + public String classname_note = "/* " + classname + " */ "; + public String query = "" + + "update transactions " + + "set gas_price = ? " + + "where hash = ? "; private PreparedStatement query_stmt = null; public long run(Connection conn, Random gen, WEB3Worker w, int startNumber, int upperLimit, int numScale, - String nodeid) throws SQLException { + String nodeid, boolean isExplainAnalyze) throws SQLException { + boolean debug = LOG.isDebugEnabled(); boolean trace = LOG.isTraceEnabled(); - // initializing all prepared statements - query_stmt = this.getPreparedStatement(conn, query_stmtSQL); - + // Prepare statement + SQLStmt query_stmtSQL = new SQLStmt( + classname_note + (isExplainAnalyze ? SQL_EXPLAIN_ANALYZE : "") + query); + // Parameters long gas_price = WEB3Util.randomNumber(1000, 10000000, gen); String hash = WEB3Util .convertToTxnHashString(WEB3Util.randomNumber(1, WEB3Config.configTransactionsCount * numScale, gen)); + // Create statement and set parameters + query_stmt = this.getPreparedStatement(conn, query_stmtSQL, gas_price, hash); - query_stmt.setLong(1, gas_price); - query_stmt.setString(2, hash); - if (LOG.isDebugEnabled()) { + // Log query + if (debug) { LOG.debug(queryToString(query_stmt)); } - if (trace) - LOG.trace("query_stmt W4 UpdateQuery1 START"); - // int affectedRows = query_stmt.executeUpdate(); - ResultSet rs = query_stmt.executeQuery(); + + if (trace) { + LOG.trace("Query" + classname + " START"); + } + int affectedRows = 0; // Number of rows affected + ResultSet rs = null; + // Execute query and commit + if (isExplainAnalyze) { + // Use executeQuery for explain analyze + rs = query_stmt.executeQuery(); + } else { + // Use executeUpdate for normal query + affectedRows = query_stmt.executeUpdate(); + } conn.commit(); - if (trace) - LOG.trace("query_stmt W4 UpdateQuery1 END"); + if (trace) { + LOG.trace("Query" + classname + " END"); + } + + if (isExplainAnalyze) { + // If explain analyze, then return the latency + // Get the latency from the result set + long latency_ns = getTimeFromRS(rs); + rs.close(); + return latency_ns; + } else { + if (debug) { + LOG.debug("Affected Rows: " + affectedRows); + } + } - long latency_ns = getTimeFromRS(rs); - rs.close(); - return latency_ns; + return 0; } } diff --git a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W51.java b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W51.java index decb1d7..7c99ad6 100755 --- a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W51.java +++ b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W51.java @@ -31,27 +31,29 @@ import com.olxpbenchmark.benchmarks.web3benchmark.WEB3Worker; public class W51 extends WEB3Procedure { - private static final Logger LOG = Logger.getLogger(W51.class); - public SQLStmt query_stmtSQL = new SQLStmt( - "/* W51 */ " - + "explain analyze " - + "update token_transfers " - + "set value = ? " - + "where to_address = from_address "); - + public String classname = this.getClass().getSimpleName(); + public String classname_note = "/* " + classname + " */ "; + public String query = "" + + "update token_transfers " + + "set value = ? " + + "where to_address = from_address "; private PreparedStatement query_stmt = null; public long run(Connection conn, Random gen, WEB3Worker w, int startNumber, int upperLimit, int numScale, - String nodeid) throws SQLException { + String nodeid, boolean isExplainAnalyze) throws SQLException { + boolean debug = LOG.isDebugEnabled(); boolean trace = LOG.isTraceEnabled(); - // initializing all prepared statements - query_stmt = this.getPreparedStatement(conn, query_stmtSQL); - + // Prepare statement + SQLStmt query_stmtSQL = new SQLStmt( + classname_note + (isExplainAnalyze ? SQL_EXPLAIN_ANALYZE : "") + query); + // Parameters double value = (double) WEB3Util.randomNumber(0, 1000000, gen); - query_stmt.setDouble(1, value); + // Create statement and set parameters + query_stmt = this.getPreparedStatement(conn, query_stmtSQL, value); + if (LOG.isDebugEnabled()) { LOG.debug(queryToString(query_stmt)); } @@ -59,13 +61,13 @@ public long run(Connection conn, Random gen, WEB3Worker w, int startNumber, int if (trace) LOG.trace("query_stmt W51 UpdateQuery2 START"); // int affectedRows = query_stmt.executeUpdate(); - ResultSet rs = query_stmt.executeQuery(); + query_stmt.executeUpdate(); conn.commit(); if (trace) LOG.trace("query_stmt W51 UpdateQuery2 END"); - long latency_ns = getTimeFromRS(rs); - rs.close(); - return latency_ns; + // long latency_ns = getTimeFromRS(rs); + // rs.close(); + return 0; } } diff --git a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W52.java b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W52.java index ae0a7dd..c7c27c2 100755 --- a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W52.java +++ b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W52.java @@ -31,24 +31,26 @@ import com.olxpbenchmark.benchmarks.web3benchmark.WEB3Worker; public class W52 extends WEB3Procedure { - private static final Logger LOG = Logger.getLogger(W52.class); - public SQLStmt query_stmtSQL = new SQLStmt( - "/* W52 */ " - + "explain analyze " - + "update token_transfers " - + "set value = value + 1 " - + "where from_address in " - + "(select to_address from token_transfers) "); - + public String classname = this.getClass().getSimpleName(); + public String classname_note = "/* " + classname + " */ "; + public String query = "" + + "update token_transfers " + + "set value = value + 1 " + + "where from_address in " + + "(select to_address from token_transfers) "; private PreparedStatement query_stmt = null; public long run(Connection conn, Random gen, WEB3Worker w, int startNumber, int upperLimit, int numScale, - String nodeid) throws SQLException { + String nodeid, boolean isExplainAnalyze) throws SQLException { + boolean debug = LOG.isDebugEnabled(); boolean trace = LOG.isTraceEnabled(); - // initializing all prepared statements + // Prepare statement + SQLStmt query_stmtSQL = new SQLStmt( + classname_note + (isExplainAnalyze ? SQL_EXPLAIN_ANALYZE : "") + query); + // Create statement and set parameters query_stmt = this.getPreparedStatement(conn, query_stmtSQL); if (LOG.isDebugEnabled()) { LOG.debug(queryToString(query_stmt)); @@ -60,7 +62,7 @@ public long run(Connection conn, Random gen, WEB3Worker w, int startNumber, int if (trace) LOG.trace("query_stmt UpdateQuery3 START"); // int affectedRows = query_stmt.executeUpdate(); - ResultSet rs = query_stmt.executeQuery(); + query_stmt.executeUpdate(); // conn.commit(); if (trace) LOG.trace("query_stmt UpdateQuery3 END"); @@ -68,8 +70,8 @@ public long run(Connection conn, Random gen, WEB3Worker w, int startNumber, int // reset autocommit to false conn.setAutoCommit(false); - long latency_ns = getTimeFromRS(rs); - rs.close(); - return latency_ns; + // long latency_ns = getTimeFromRS(rs); + // rs.close(); + return 0; } } diff --git a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W6.java b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W6.java index 6c1361e..6ff7687 100755 --- a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W6.java +++ b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W6.java @@ -32,44 +32,66 @@ import com.olxpbenchmark.benchmarks.web3benchmark.WEB3Worker; public class W6 extends WEB3Procedure { - private static final Logger LOG = Logger.getLogger(W6.class); + public String classname = this.getClass().getSimpleName(); + public String classname_note = "/* " + classname + " */ "; // Single record deletes for the transaction table. - public SQLStmt query_stmtSQL = new SQLStmt( - "/* W6 */ " - + "explain analyze " - + "delete from transactions " - + "where hash = ? "); - + public String query = "" + + "delete from transactions " + + "where hash = ? "; private PreparedStatement query_stmt = null; public long run(Connection conn, Random gen, WEB3Worker w, int startNumber, int upperLimit, int numScale, - String nodeid) throws SQLException { + String nodeid, boolean isExplainAnalyze) throws SQLException { + boolean debug = LOG.isDebugEnabled(); boolean trace = LOG.isTraceEnabled(); - // initializing all prepared statements - query_stmt = this.getPreparedStatement(conn, query_stmtSQL); - + // Prepare statement + SQLStmt query_stmtSQL = new SQLStmt( + classname_note + (isExplainAnalyze ? SQL_EXPLAIN_ANALYZE : "") + query); + // Parameters // make sure the startNumber is odd, to avoid foreign key conflicts with W14 startNumber = startNumber - (startNumber % 2) + 1; String hash = WEB3Util.convertToTxnHashString(startNumber % (WEB3Config.configTransactionsCount * numScale)); + // Create statement and set parameters + query_stmt = this.getPreparedStatement(conn, query_stmtSQL, hash); - // Setting the parameters for the query - query_stmt.setString(1, hash); - if (LOG.isDebugEnabled()) { + // Log query + if (debug) { LOG.debug(queryToString(query_stmt)); } - if (trace) - LOG.trace("query_stmt W6 single record deletes for the transaction table START"); - // int affectedRows = query_stmt.executeUpdate(); - ResultSet rs = query_stmt.executeQuery(); + + if (trace) { + LOG.trace("Query" + classname + " START"); + } + int affectedRows = 0; // Number of rows affected + ResultSet rs = null; + // Execute query and commit + if (isExplainAnalyze) { + // Use executeQuery for explain analyze + rs = query_stmt.executeQuery(); + } else { + // Use executeUpdate for normal query + affectedRows = query_stmt.executeUpdate(); + } conn.commit(); - if (trace) - LOG.trace("query_stmt W6 single record deletes for the transaction table END"); + if (trace) { + LOG.trace("Query" + classname + " END"); + } + + if (isExplainAnalyze) { + // If explain analyze, then return the latency + // Get the latency from the result set + long latency_ns = getTimeFromRS(rs); + rs.close(); + return latency_ns; + } else { + if (debug) { + LOG.debug("Affected Rows: " + affectedRows); + } + } - long latency_ns = getTimeFromRS(rs); - rs.close(); - return latency_ns; + return 0; } } diff --git a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/WEB3Procedure.java b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/WEB3Procedure.java index 987a61e..07a1957 100755 --- a/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/WEB3Procedure.java +++ b/src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/WEB3Procedure.java @@ -51,7 +51,7 @@ public abstract class WEB3Procedure extends Procedure { // rand and iRand public abstract long run(Connection conn, Random gen, WEB3Worker w, int startNumber, int upperLimit, - int numScale, String nodeid) throws SQLException; + int numScale, String nodeid, boolean isExplainAnalyze) throws SQLException; protected String queryToString(PreparedStatement query) { return query.toString().split(":")[1].trim(); diff --git a/src/com/olxpbenchmark/util/StringUtil.java b/src/com/olxpbenchmark/util/StringUtil.java index 72836c7..71d2e68 100644 --- a/src/com/olxpbenchmark/util/StringUtil.java +++ b/src/com/olxpbenchmark/util/StringUtil.java @@ -102,25 +102,6 @@ public static String header(String msg, String marker, int length) { return String.format("%s %s %s%s", border, msg, border, (add_extra ? marker : "")); } - /** - * Return the MD5 checksum of the given string - * - * @param input - * @return - */ - public static String md5sum(String input) { - MessageDigest digest = null; - try { - digest = MessageDigest.getInstance("MD5"); - } catch (NoSuchAlgorithmException ex) { - throw new RuntimeException("Unable to compute md5sum for string", ex); - } - assert (digest != null); - digest.update(input.getBytes()); - BigInteger hash = new BigInteger(1, digest.digest()); - return (hash.toString(16)); - } - /** * Split the multi-lined strings into separate columns *