-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.sh
executable file
·187 lines (162 loc) · 4.33 KB
/
benchmark.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/env bash
set -e
export PS4='+ [`basename ${BASH_SOURCE[0]}`:$LINENO ${FUNCNAME[0]} \D{%F %T} $$ ] '
CURDIR=$(cd "$(dirname "$0")"; pwd);
MYNAME="${0##*/}"
GITTPCH="https://github.com/vidardb/tpch-dbgen"
TPCHPATH="$CURDIR/tpch-dbgen"
TPCHCMD="$TPCHPATH/dbgen"
TPCHDAT="lineitem.tbl"
PLATFORM_PG="pg"
PLATFORM_FDW="fdw"
PLATFORM_TBAM="tbam"
PLATFORM_ENG="engine"
RET_OK=0
RET_FAIL=1
##################### function #########################
_report_err() { echo "${MYNAME}: Error: $*" >&2 ; }
if [ -t 1 ]
then
RED="$( echo -e "\e[31m" )"
HL_RED="$( echo -e "\e[31;1m" )"
HL_BLUE="$( echo -e "\e[34;1m" )"
NORMAL="$( echo -e "\e[0m" )"
fi
_hl_red() { echo "$HL_RED""$@""$NORMAL";}
_hl_blue() { echo "$HL_BLUE""$@""$NORMAL";}
_trace() {
echo $(_hl_blue ' ->') "$@" >&2
}
_print_fatal() {
echo $(_hl_red '==>') "$@" >&2
exit $RET_FAIL
}
# shellcheck disable=SC1009
_install_tpch() {
_trace "git clone tpch from $GITTPCH ..."
if [ ! -d "$TPCHPATH" ]; then
git clone "$GITTPCH" "$TPCHPATH" &> /dev/null
# shellcheck disable=SC2181
if [ $? -ne 0 ]; then
_print_fatal "clone tpch-dbgen failed."
fi
fi
_trace "compile source code for dbgen ..."
cd "$TPCHPATH" && make &> /dev/null
if [ $? -ne 0 ]; then
_print_fatal "make tpch-dbgen failed."
fi
if [ -x ${TPCHCMD} ];then
_trace "install tpch success"
else
_print_fatal "install tpch failed"
fi
}
_gen_data() {
size=$2
if [ -z "$size" ]; then
size=1 # default 1GB
fi
path=$3
if [ -z "$path" -o "$path" = "$TPCHDAT" ]; then
path=$TPCHPATH/$TPCHDAT
fi
table="L" # lineitem
cd $(dirname $TPCHCMD)
if [ -e "$TPCHPATH/$TPCHDAT" ]; then
echo "remove $TPCHPATH/$TPCHDAT"
rm -rf "$TPCHPATH/$TPCHDAT"
fi
_trace "generate data for benchmark ( size: ${size}G table: $table ) ..."
"$TPCHCMD" -f -s "$size" -T "$table"
# important: shuffle tcph data
shuf $TPCHPATH/$TPCHDAT -o $TPCHPATH/${TPCHDAT}.shuf
rm -rf "$TPCHPATH/$TPCHDAT"
mv $TPCHPATH/${TPCHDAT}.shuf $path
if [ -e "$path" ]; then
_trace "benchmark data path: $path"
else
_print_fatal "generate benchmark data failed."
fi
}
# psql should be installed
_create_benchmark_tbl() {
_trace "create benchmark table ..."
if ! command -v psql > /dev/null; then
_print_fatal "psql should be installed."
else
psql -h$PGHOST -p$PGPORT -U$PGUSER -d$PGDATABASE -f $CURDIR/$1
fi
}
_run_benchmark() {
case $2 in
$PLATFORM_PG)
platform="PostgreSQL"
bench="pg_bench"
tbl_ddl="sql/pg_tbl_ddl.sql"
;;
$PLATFORM_FDW)
platform="VidarDB"
bench="fdw_bench"
tbl_ddl="sql/fdw_tbl_ddl.sql"
;;
$PLATFORM_TBAM)
platform="VidarDB"
bench="tbam_bench"
tbl_ddl="sql/tbam_tbl_ddl.sql"
;;
$PLATFORM_ENG)
platform="VidarDB Engine"
bench="engine_bench"
;;
*)
_print_fatal "unsupported platform: $2"
_usage
;;
esac
_gen_data "dummy" $DATASIZE $DATASOURCE
if [ "$platform" = "PostgreSQL" -o "$platform" = "VidarDB" ]; then
_create_benchmark_tbl $tbl_ddl
fi
# run benchmark for specified platform
_trace "starting benchmark for $platform ..."
if [ "$DATASOURCE" = "$TPCHDAT" ]; then
export DATASOURCE=$TPCHPATH/$TPCHDAT
else
export DATASOURCE=$DATASOURCE
fi
export PLATFORM=$PLATFORM
export SCENARIO=$SCENARIO
export PGHOST=$PGHOST
export PGPORT=$PGPORT
export PGDATABASE=$PGDATABASE
export PGUSER=$PGUSER
export DBPATH=$DBPATH
$CURDIR/benchmark
}
_usage() {
cat << USAGE
Usage: ./${MYNAME} install_tpch|gen_data|run_benchmark
Action:
install_tpch Install tpch-dbgen tool.
gen_data [size] [path] Generate tpch data, unit is GB.
run_benchmark [pg|fdw|engine] Run benchmark for specified platform.
USAGE
exit 1
}
## main ##
action=$1
case $action in
"install_tpch" )
_install_tpch
;;
"gen_data" )
_gen_data "$@"
;;
"run_benchmark" )
_run_benchmark "$@"
;;
*)
_usage
;;
esac