Skip to content

Commit

Permalink
add explain-analyze option
Browse files Browse the repository at this point in the history
  • Loading branch information
cococo2000 committed Feb 26, 2024
1 parent 442f30e commit 9cc6ed2
Show file tree
Hide file tree
Showing 27 changed files with 865 additions and 519 deletions.
14 changes: 7 additions & 7 deletions script/runbench.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
65 changes: 21 additions & 44 deletions src/com/olxpbenchmark/DBWorkload.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
Expand Down Expand Up @@ -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
// -------------------------------------------------------------------
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions src/com/olxpbenchmark/WorkloadConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/com/olxpbenchmark/api/Procedure.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, SQLStmt> name_stmt_xref;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<WEB3Benchmark> {
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
56 changes: 35 additions & 21 deletions src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R1.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,46 +34,60 @@
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 0;
}
Expand Down
58 changes: 36 additions & 22 deletions src/com/olxpbenchmark/benchmarks/web3benchmark/procedures/R21.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,48 +34,62 @@
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 0;
}
Expand Down
Loading

0 comments on commit 9cc6ed2

Please sign in to comment.