11#! /usr/bin/env bash
22set -euo pipefail
33
4- # ============================================================
5- # TidesDB vs RocksDB vs PostgreSQL — HammerDB TPC-C / TPC-H benchmark
6- # Requires: HammerDB 5.0
7- # MariaDB with TidesDB+RocksDB engines (for MariaDB engines)
8- # PostgreSQL (for postgres engine)
9- # ============================================================
10-
11- # ---------- defaults ----------
4+ # defaults
125HAMMERDB_DIR=${HAMMERDB_DIR:-/ opt/ HammerDB-5.0}
136ENGINE_SELECT=${ENGINE_SELECT:- both}
147BENCH_SELECT=${BENCH_SELECT:- both}
@@ -69,8 +62,6 @@ usage() {
6962 cat << EOF
7063Usage: $0 [OPTIONS]
7164
72- HammerDB TPC-C / TPC-H benchmark: TidesDB vs RocksDB vs PostgreSQL
73-
7465Options:
7566 -e, --engine STR Engine: tidesdb|rocksdb|innodb|postgres|both|all
7667 (default: $ENGINE_SELECT )
@@ -187,7 +178,7 @@ while [[ $# -gt 0 ]]; do
187178 esac
188179done
189180
190- # ---------- plot-only mode ----------
181+ # plot-only mode
191182if [[ -n " $PLOT_ONLY " ]]; then
192183 if [[ ! -f " $PLOT_ONLY " ]]; then
193184 echo " ERROR: CSV file not found: $PLOT_ONLY "
211202
212203if [[ " ${SKIP_BENCH:- 0} " -ne 1 ]]; then
213204
214- # ---------- validate ----------
205+ # validate
215206if [[ ! -x " $HAMMERDBCLI " ]]; then
216207 echo " ERROR: hammerdbcli not found at $HAMMERDBCLI "
217208 echo " Set HAMMERDB_DIR or use --hammerdb-dir"
@@ -228,7 +219,7 @@ case "${ENGINE_SELECT,,}" in
228219 * ) echo " ERROR: --engine must be tidesdb, rocksdb, innodb, postgres, both, or all" ; exit 1 ;;
229220esac
230221
231- # ---------- perf preflight ----------
222+ # perf preflight
232223if [[ " $PERF_RECORD " -eq 1 ]]; then
233224 if ! command -v perf & > /dev/null; then
234225 echo " ERROR: perf not found. Install with: sudo apt install linux-tools-\$ (uname -r)"
296287export TMP=" ${LOG_DIR} /hammerdb_tmp"
297288mkdir -p " $TMP "
298289
299- # ---------- conditional password lines for Tcl scripts ----------
300- # HammerDB's diset requires a value — omit the line entirely if empty
290+ # conditional password lines for Tcl scripts
291+ # HammerDB's diset requires a value - omit the line entirely if empty
301292if [[ -n " $MYSQL_PASS " ]]; then
302293 DISET_TPCC_PASS=" diset tpcc maria_pass $MYSQL_PASS "
303294 DISET_TPCH_PASS=" diset tpch maria_tpch_pass $MYSQL_PASS "
322313 DISET_PG_TPCH_PASS=" # pg tpch password not set"
323314fi
324315
325- # ---------- CSV header ----------
316+ # CSV header
326317cat > " $CSV_FILE " << EOF
327318benchmark,engine,nopm,tpm,warehouses,virtual_users,rampup_min,duration_min,scale_factor,querysets,build_sec,settle_sec,neword_avg_ms,neword_p95_ms,payment_avg_ms,payment_p95_ms,delivery_avg_ms,delivery_p95_ms,tpch_geomean_sec,tpch_total_sec
328319EOF
@@ -357,7 +348,7 @@ echo " Logs: $LOG_DIR/"
357348echo " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
358349echo " "
359350
360- # ---------- helper: generate tcl scripts ----------
351+ # helper: generate tcl scripts
361352
362353gen_tpcc_build () {
363354 local engine=" $1 " outfile=" $2 "
@@ -511,7 +502,7 @@ puts "DROP SCHEMA COMPLETED"
511502TCLEOF
512503}
513504
514- # ---------- PostgreSQL Tcl script generators ----------
505+ # PostgreSQL Tcl script generators
515506
516507gen_pg_tpcc_build () {
517508 local outfile=" $1 "
@@ -673,7 +664,7 @@ puts "DROP SCHEMA COMPLETED"
673664TCLEOF
674665}
675666
676- # ---------- helper: parse TPC-C results ----------
667+ # helper: parse TPC-C results
677668parse_tpcc () {
678669 local logfile=" $1 "
679670 local nopm tpm
@@ -722,7 +713,7 @@ parse_tpch() {
722713 echo " ${geomean} ,${total} "
723714}
724715
725- # ---------- settle helper ----------
716+ # settle helper
726717do_settle () {
727718 if [[ " $SETTLE " -gt 0 ]]; then
728719 echo " [$( date +%H:%M:%S) ] Settling ${SETTLE} s..."
@@ -738,11 +729,11 @@ do_settle() {
738729 fi
739730}
740731
741- # ---------- set default storage engine ----------
732+ # set default storage engine
742733set_default_engine () {
743734 local engine=" $1 "
744735 if is_pg_engine " $engine " ; then
745- echo " [$( date +%H:%M:%S) ] PostgreSQL engine — no default_storage_engine to set"
736+ echo " [$( date +%H:%M:%S) ] PostgreSQL engine - no default_storage_engine to set"
746737 return 0
747738 fi
748739 local engine_lower
@@ -753,13 +744,13 @@ set_default_engine() {
753744}
754745
755746# ============================================================
756- # DEBUG RUN (optional) — short test with raiseerror=true
747+ # DEBUG RUN (optional) - short test with raiseerror=true
757748# ============================================================
758749if [[ " $DEBUG_RUN " -eq 1 ]]; then
759750 DEBUG_VU=2
760751
761752 echo " ######################################################"
762- echo " DEBUG RUN — checking for lock conflicts"
753+ echo " DEBUG RUN - checking for lock conflicts"
763754 echo " VUs: $DEBUG_VU | Duration: 1 min (0 ramp)"
764755 echo " raiseerror: TRUE | driver: timed"
765756 echo " ######################################################"
@@ -866,18 +857,18 @@ TCLEOF
866857 echo " "
867858 echo " Issues detected for $ENGINE ."
868859 if [[ " $DEADLOCKS " -gt 0 || " $PROC_ERRORS " -gt 0 ]]; then
869- echo " Lock conflicts found — the timed benchmark uses"
860+ echo " Lock conflicts found - the timed benchmark uses"
870861 echo " raiseerror=false (default) so these will be silently"
871862 echo " caught and skipped. High rates may deflate TPM."
872863 fi
873864 if [[ " $ABORTS " -gt 0 ]]; then
874- echo " Some VUs FINISHED FAILED — check log for details."
865+ echo " Some VUs FINISHED FAILED - check log for details."
875866 fi
876867 echo " "
877868 echo " Relevant lines:"
878869 grep -iE " deadlock|lock wait|Error 1213|Error 1180|Procedure Error|FINISHED FAILED" " ${DBG_PREFIX} _run.log" | head -10 || true
879870 else
880- echo " No lock conflicts detected — clean run."
871+ echo " No lock conflicts detected - clean run."
881872 fi
882873 echo " ========================================="
883874 echo " "
@@ -896,7 +887,7 @@ TCLEOF
896887 done
897888
898889 echo " ######################################################"
899- echo " DEBUG RUN COMPLETE — proceeding to benchmark"
890+ echo " DEBUG RUN COMPLETE - proceeding to benchmark"
900891 echo " ######################################################"
901892 echo " "
902893fi
@@ -918,7 +909,7 @@ for BENCH in "${BENCHMARKS[@]}"; do
918909 set_default_engine " $ENGINE "
919910
920911 if [[ " $BENCH " == " TPC-C" ]]; then
921- # ---- TPC-C BUILD ----
912+ # TPC-C BUILD
922913 if is_pg_engine " $ENGINE " ; then
923914 gen_pg_tpcc_build " ${LOG_PREFIX} _build.tcl"
924915 else
@@ -934,7 +925,7 @@ for BENCH in "${BENCHMARKS[@]}"; do
934925
935926 do_settle
936927
937- # ---- PERF START ----
928+ # PERF START
938929 PERF_PID=" "
939930 if [[ " $PERF_RECORD " -eq 1 ]]; then
940931 DB_PID=$( find_db_pid " $ENGINE " ) || true
@@ -955,7 +946,7 @@ for BENCH in "${BENCHMARKS[@]}"; do
955946 fi
956947 fi
957948
958- # ---- TPC-C RUN ----
949+ # TPC-C RUN
959950 if is_pg_engine " $ENGINE " ; then
960951 gen_pg_tpcc_run " ${LOG_PREFIX} _run.tcl"
961952 else
@@ -965,7 +956,7 @@ for BENCH in "${BENCHMARKS[@]}"; do
965956 (cd " $HAMMERDB_DIR " && TMP=" $TMP " " $HAMMERDBCLI " auto " ${LOG_PREFIX} _run.tcl" ) 2>&1 | tee " ${LOG_PREFIX} _run.log" || true
966957 echo " "
967958
968- # ---- PERF STOP ----
959+ # PERF STOP
969960 if [[ -n " $PERF_PID " ]] && kill -0 " $PERF_PID " 2> /dev/null; then
970961 echo " [$( date +%H:%M:%S) ] Stopping perf..."
971962 $SUDO kill -INT " $PERF_PID "
@@ -1012,7 +1003,7 @@ for BENCH in "${BENCHMARKS[@]}"; do
10121003 echo " "
10131004 fi
10141005
1015- # ---- TPC-C RESULT ----
1006+ # TPC-C RESULT
10161007 if is_pg_engine " $ENGINE " ; then
10171008 gen_pg_tpcc_result " ${LOG_PREFIX} _result.tcl"
10181009 else
@@ -1022,13 +1013,13 @@ for BENCH in "${BENCHMARKS[@]}"; do
10221013 (cd " $HAMMERDB_DIR " && TMP=" $TMP " " $HAMMERDBCLI " auto " ${LOG_PREFIX} _result.tcl" ) 2>&1 | tee " ${LOG_PREFIX} _result.log" || true
10231014 echo " "
10241015
1025- # ---- PARSE ----
1016+ # PARSE
10261017 NOPM_TPM=$( parse_tpcc " ${LOG_PREFIX} _run.log" )
10271018 TIMING=$( parse_tpcc_timing " ${LOG_PREFIX} _result.log" 2> /dev/null) || TIMING=" 0,0,0,0,0,0"
10281019
10291020 echo " ${BENCH} ,${ENGINE} ,${NOPM_TPM} ,${TPCC_WAREHOUSES} ,${TPCC_VU} ,${TPCC_RAMPUP} ,${TPCC_DURATION} ,,,${BUILD_ELAPSED} ,${SETTLE} ,${TIMING} ,,," >> " $CSV_FILE "
10301021
1031- # ---- TPC-C DELETE ----
1022+ # TPC-C DELETE
10321023 if is_pg_engine " $ENGINE " ; then
10331024 gen_pg_tpcc_delete " ${LOG_PREFIX} _delete.tcl"
10341025 else
@@ -1039,7 +1030,7 @@ for BENCH in "${BENCHMARKS[@]}"; do
10391030 echo " "
10401031
10411032 elif [[ " $BENCH " == " TPC-H" ]]; then
1042- # ---- TPC-H BUILD ----
1033+ # TPC-H BUILD
10431034 if is_pg_engine " $ENGINE " ; then
10441035 gen_pg_tpch_build " ${LOG_PREFIX} _build.tcl"
10451036 else
@@ -1055,7 +1046,7 @@ for BENCH in "${BENCHMARKS[@]}"; do
10551046
10561047 do_settle
10571048
1058- # ---- TPC-H RUN ----
1049+ # TPC-H RUN
10591050 if is_pg_engine " $ENGINE " ; then
10601051 gen_pg_tpch_run " ${LOG_PREFIX} _run.tcl"
10611052 else
@@ -1065,12 +1056,12 @@ for BENCH in "${BENCHMARKS[@]}"; do
10651056 (cd " $HAMMERDB_DIR " && TMP=" $TMP " " $HAMMERDBCLI " auto " ${LOG_PREFIX} _run.tcl" ) 2>&1 | tee " ${LOG_PREFIX} _run.log" || true
10661057 echo " "
10671058
1068- # ---- PARSE ----
1059+ # PARSE
10691060 TPCH_METRICS=$( parse_tpch " ${LOG_PREFIX} _run.log" )
10701061
10711062 echo " ${BENCH} ,${ENGINE} ,,,,,,,${TPCH_SCALE} ,${TPCH_QUERYSETS} ,${BUILD_ELAPSED} ,${SETTLE} ,,,,,,${TPCH_METRICS} " >> " $CSV_FILE "
10721063
1073- # ---- TPC-H DELETE ----
1064+ # TPC-H DELETE
10741065 if is_pg_engine " $ENGINE " ; then
10751066 gen_pg_tpch_delete " ${LOG_PREFIX} _delete.tcl"
10761067 else
@@ -1173,7 +1164,7 @@ def safe_float(v):
11731164 try: return float(v) if v else 0
11741165 except: return 0
11751166
1176- # ---- TPC-C charts ----
1167+ # TPC-C charts
11771168if tpcc_rows:
11781169 engines = []
11791170 seen = set()
@@ -1264,7 +1255,7 @@ if tpcc_rows:
12641255 fig.savefig(path); plt.close(fig)
12651256 print(f" Chart: {path}")
12661257
1267- # ---- TPC-H charts ----
1258+ # TPC-H charts
12681259if tpch_rows:
12691260 engines = []
12701261 seen = set()
@@ -1318,7 +1309,7 @@ if tpch_rows:
13181309 fig.savefig(path); plt.close(fig)
13191310 print(f" Chart: {path}")
13201311
1321- # ---- Build time chart (all benchmarks) ----
1312+ # Build time chart (all benchmarks)
13221313if len(rows) >= 2:
13231314 labels = [f"{r['benchmark']}\n{r['engine']}" for r in rows]
13241315 build_vals = [safe_float(r.get("build_sec", 0)) for r in rows]
0 commit comments