Skip to content

Commit

Permalink
Merge pull request #11 from cococo2000/sdbtest
Browse files Browse the repository at this point in the history
Add Explain Analyze Option and Conduct Testing on Singlestore
  • Loading branch information
cococo2000 authored Feb 26, 2024
2 parents 9c0295e + 9cc6ed2 commit 0bfe318
Show file tree
Hide file tree
Showing 36 changed files with 905 additions and 564 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mysql-connector-python==8.2.0
pandas==2.0.3
tqdm==4.65.0
defusedxml==0.7.1
2 changes: 1 addition & 1 deletion script/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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
17 changes: 10 additions & 7 deletions src/com/olxpbenchmark/api/Loader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}

/**
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
4 changes: 3 additions & 1 deletion src/com/olxpbenchmark/api/StatementDialects.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<DialectsType> result = (JAXBElement<DialectsType>) unmarshaller.unmarshal(this.xmlFile);
dialects = result.getValue();
} catch (JAXBException ex) {
Expand Down
8 changes: 5 additions & 3 deletions src/com/olxpbenchmark/api/Worker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
12 changes: 9 additions & 3 deletions src/com/olxpbenchmark/api/collectors/DBCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -142,9 +143,14 @@ protected static Map<String, String> getKeyValueResults(Connection conn, String
return results;
}

protected static List<Map<String, String>> getColumnResults(Connection conn, String sql) throws SQLException {
Statement s = conn.createStatement();
ResultSet out = s.executeQuery(sql);
protected static List<Map<String, String>> 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();
Expand Down
16 changes: 8 additions & 8 deletions src/com/olxpbenchmark/api/collectors/MyRocksCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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());
Expand Down
Loading

0 comments on commit 0bfe318

Please sign in to comment.