forked from xxisxuxuqq/byconity-tpcds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.sh
executable file
·101 lines (80 loc) · 2.89 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
#!/bin/bash
#
# Copyright (2022) Bytedance Ltd. and/or its affiliates
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
source ./config.sh
source ./helper.sh
[ -z "$1" ] && DATASIZE=1 || DATASIZE=$1
DATABASE=${DATABASE:-${DB_PREFIX}${SUITE}${DATASIZE}${DB_SUFFIX}}
TIMEOUT=${TIMEOUT:-600}
RESULT=${RESULT:-${LOGDIR}/result.csv}
SQL_DIR=${SCRIPTPATH}/sql
LOG_CUR=$LOGDIR/curr.txt
TIME_FILE=$LOGDIR/time.txt
echo "qid,duration,status" > "$RESULT"
log "Make sure stats are created for tables, this will take some time..."
clickhouse_client "create stats if not exists all" -d "$DATABASE"
clickhouse_client "show stats all format PrettyCompact" -d "$DATABASE" >> $TRACE_LOG
set -e
log "Run warm up sql..."
if [ -f ${SQL_DIR}/warmup.sql ]; then
QUERY=$(cat "${SQL_DIR}/warmup.sql")
log "$QUERY"
clickhouse_client "$QUERY" -d "$DATABASE" > /dev/null
fi
function parse_time() {
sec_to_ms $(cat ${TIME_FILE} | grep real | awk '{print $2}'; rm ${TIME_FILE} > /dev/null)
}
function benchmark_query() {
for i in {1..18}; do
SQL=$(sed -e "/^--/d; s/${SUITE}\./${DATABASE}\./g" ${1})
if [ "${ENABLE_ENGINE_TIME}" == "true" ]; then
DURATION=$(clickhouse_client "$SQL" -d $DATABASE -t --format=Null 2>&1) && RET=0 || RET=$?
DURATION=$(sec_to_ms ${DURATION})
else
CMD=$(clickhouse_client_cmd "$SQL" "-d $DATABASE -t --format=Null")
/usr/bin/time -p -o "${TIME_FILE}" timeout $TIMEOUT sh -c "$CMD" >${LOG_CUR} 2>&1 && RET=0 || RET=$?
fi
# connection refused, try again
if [ $RET -ne 210 ]; then
break
fi
sleep 5
done
if [ $RET -eq 210 ]; then
echo "server down, abort testing"
exit 1
fi
[[ -f "${TIME_FILE}" ]] && DURATION=$(parse_time)
# workaround for case that engine error happens but returns 0
if [ $RET -eq 0 ]; then
VAL=$(sed -n "s|^Code: \([0-9]\+\), e.displayText().*$|\1|p" $LOG_CUR)
if [ -n "$VAL" ]; then
RET=$VAL
fi
fi
STATUS=$RET
}
TIMEOUT_VAL=999999
QPATH="$SQL_DIR/standard"
TOTAL_DURATION=0
log "Run benchmark sql from ${QPATH}"
for FILE_PATH in ${QPATH}/*.sql; do
QID=$(query_file_to_id ${FILE_PATH})
benchmark_query ${FILE_PATH}
log "[Query$QID]duration: ${DURATION}ms, status: ${STATUS}"
echo "${QID},${DURATION},${STATUS}" >> $RESULT
TOTAL_DURATION=$(($TOTAL_DURATION + $DURATION))
done
log "total duration: ${TOTAL_DURATION}ms"