runTDengine.sh 11.0 KB
Newer Older
S
Shuduo Sang 已提交
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 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
#!/bin/bash
#set -x

WORK_DIR=/mnt/root
DATA_DIR=/mnt/data

# Color setting
RED='\033[0;31m'
GREEN='\033[1;32m'
GREEN_DARK='\033[0;32m'
GREEN_UNDERLINE='\033[4;32m'
NC='\033[0m'

# default value
DEFAULT_BATCH=5000
DEFAULT_DAYS=1
DEFAULT_INTERVAL=1
DEFAULT_SCALEVAR=10
DEFAULT_DOPREPARE=false
DEFAULT_DOWRITE=false
DEFAULT_DOQUERY=false

# function 
function do_prepare {
	echo
	echo "---------------Generating Data-----------------"
	echo

	echo 
	echo "Prepare data for TDengine...."

	# bin/bulk_data_gen -seed 123 -format tdengine -tdschema-file config/TDengineSchema.toml -scale-var 100 -use-case devops -timestamp-start "2018-01-01T00:00:00Z" -timestamp-end "2018-01-02T00:00:00Z"  > $DATA_DIR/tdengine.dat
	echo "bin/bulk_data_gen -seed 123 -format tdengine -sampling-interval $interval_s \
		-tdschema-file config/TDengineSchema.toml -scale-var $scalevar \
		-use-case devops -timestamp-start $TIME_START \ 
		-timestamp-end $TIME_END \ 
	       	> $DATA_FILE"

	bin/bulk_data_gen -seed 123 -format tdengine -sampling-interval $interval_s \
		-tdschema-file config/TDengineSchema.toml -scale-var $scalevar \
		-use-case devops -timestamp-start $TIME_START \
		-timestamp-end $TIME_END  \
		> $DATA_FILE
}

function do_write {
	echo "TDENGINERES=cat $DATA_FILE |bin/bulk_load_tdengine --url 127.0.0.1:0 \
		--batch-size $batch -do-load -report-tags n1 -workers 20 -fileout=false| grep loaded"

	TDENGINERES=`cat $DATA_FILE |bin/bulk_load_tdengine --url 127.0.0.1:0 \
		--batch-size $batch -do-load -report-tags n1 -workers 20 -fileout=false| grep loaded`

	echo
	echo -e "${GREEN}TDengine writing result:${NC}"
	echo -e "${GREEN}$TDENGINERES${NC}"
	DATA=`echo $TDENGINERES|awk '{print($2)}'`
	TMP=`echo $TDENGINERES|awk '{print($5)}'`
	TDWTM=`echo ${TMP%s*}`

}

function do_query {

	echo
	echo "------------------Querying Data-----------------"
	echo

	echo 
	echo  "start query test, query max from 8 hosts group by 1 hour, TDengine"
	echo

#Test case 1
#测试用例1,查询所有数据中,用8个hostname标签进行匹配,匹配出这8个hostname对应的模拟服务器CPU数据中的usage_user这个监控数据的最大值。
#select max(usage_user) from cpu where(hostname='host_a' and hostname='host_b'and hostname='host_c'and hostname='host_d'and hostname='host_e'and hostname='host_f' and hostname='host_g'and hostname='host_h') ;
# a,b,c,d,e,f,g,h are random 8 numbers.
	echo "TDQS1=bin/bulk_query_gen  -seed 123 -format tdengine -query-type 8-host-all \
		-scale-var $scalevar -queries 1000 | bin/query_benchmarker_tdengine  \
		-urls=http://127.0.0.1:6020 -workers 50 -print-interval 0|grep wall"

	TDQS1=`bin/bulk_query_gen  -seed 123 -format tdengine -query-type 8-host-all \
		-scale-var $scalevar -queries 1000 | bin/query_benchmarker_tdengine  \
		-urls="http://127.0.0.1:6020" -workers 50 -print-interval 0|grep wall`
	echo
	echo -e "${GREEN}TDengine query test case 1 result:${NC}"
	echo -e "${GREEN}$TDQS1${NC}"
	TMP=`echo $TDQS1|awk '{print($4)}'`
	TDQ1=`echo ${TMP%s*}`

#Test case 2
#测试用例2,查询所有数据中,用8个hostname标签进行匹配,匹配出这8个hostname对应的模拟服务器CPU数据中的usage_user这个监控数据,以1小时为粒度,查询每1小时的最大值。
#select max(usage_user) from cpu where(hostname='host_a' and hostname='host_b'and hostname='host_c'and hostname='host_d'and hostname='host_e'and hostname='host_f' and hostname='host_g'and hostname='host_h') interval(1h);
# a,b,c,d,e,f,g,h are random 8 numbers
	echo "TDQS2=bin/bulk_query_gen  -seed 123 -format tdengine -query-type 8-host-allbyhr \
		-scale-var $scalevar -queries 1000 | bin/query_benchmarker_tdengine  \
		-urls=http://127.0.0.1:6020 -workers 50 -print-interval 0|grep wall"

	TDQS2=`bin/bulk_query_gen  -seed 123 -format tdengine -query-type 8-host-allbyhr \
		-scale-var $scalevar -queries 1000 | bin/query_benchmarker_tdengine  \
		-urls="http://127.0.0.1:6020" -workers 50 -print-interval 0|grep wall`

	echo
	echo -e "${GREEN}TDengine query test case 2 result:${NC}"
	echo -e "${GREEN}$TDQS2${NC}"
	TMP=`echo $TDQS2|awk '{print($4)}'`
	TDQ2=`echo ${TMP%s*}`

#Test case 3
#测试用例3,测试用例3,随机查询12个小时的数据,用8个hostname标签进行匹配,匹配出这8个hostname对应的模拟服务器CPU数据中的usage_user这个监控数据,以10分钟为粒度,查询每10分钟的最大值
#select max(usage_user) from cpu where(hostname='host_a' and hostname='host_b'and hostname='host_c'and hostname='host_d'and hostname='host_e'and hostname='host_f' and hostname='host_g'and hostname='host_h') and time >x and time <y interval(10m);
# a,b,c,d,e,f,g,h are random 8 numbers, y-x =12 hour
	echo "TDQS3=bin/bulk_query_gen  -seed 123 -format tdengine -query-type 8-host-12-hr \
		-scale-var $scalevar -queries 1000 | bin/query_benchmarker_tdengine  \
		-urls=http://127.0.0.1:6020 -workers 50 -print-interval 0|grep wall"

	TDQS3=`bin/bulk_query_gen  -seed 123 -format tdengine -query-type 8-host-12-hr \
		-scale-var $scalevar -queries 1000 | bin/query_benchmarker_tdengine  \
		-urls="http://127.0.0.1:6020" -workers 50 -print-interval 0|grep wall`
	echo
	echo -e "${GREEN}TDengine query test case 3 result:${NC}"
	echo -e "${GREEN}$TDQS3${NC}"
	TMP=`echo $TDQS3|awk '{print($4)}'`
	TDQ3=`echo ${TMP%s*}`

#Test case 4
#测试用例4,随机查询1个小时的数据,用8个hostname标签进行匹配,匹配出这8个hostname对应的模拟服务器CPU数据中的usage_user这个监控数据,以1分钟为粒度,查询每1分钟的最大值
#select max(usage_user) from cpu where(hostname='host_a' and hostname='host_b'and hostname='host_c'and hostname='host_d'and hostname='host_e'and hostname='host_f' and hostname='host_g'and hostname='host_h') and time >x and time <y interval(10m);
# a,b,c,d,e,f,g,h are random 8 numbers, y-x =1 hours
	echo "TDQS4=bin/bulk_query_gen  -seed 123 -format tdengine -query-type 8-host-1-hr \
		-scale-var $scalevar -queries 1000 | bin/query_benchmarker_tdengine  \
		-urls=http://127.0.0.1:6020 -workers 50 -print-interval 0|grep wall"

	TDQS4=`bin/bulk_query_gen  -seed 123 -format tdengine -query-type 8-host-1-hr \
		-scale-var $scalevar -queries 1000 | bin/query_benchmarker_tdengine  \
		-urls="http://127.0.0.1:6020" -workers 50 -print-interval 0|grep wall`
	echo
	echo -e "${GREEN}TDengine query test case 4 result:${NC}"
	echo -e "${GREEN}$TDQS4${NC}"
	TMP=`echo $TDQS4|awk '{print($4)}'`
	TDQ4=`echo ${TMP%s*}`

}

batch=$DEFAULT_BATCH
days=$DEFAULT_DAYS
interval=$DEFAULT_INTERVAL
scalevar=$DEFAULT_SCALEVAR
doprepare=$DEFAULT_DOPREPARE
dowrite=$DEFAULT_DOWRITE
doquery=$DEFAULT_DOQUERY

help="$(basename "$0") [-h] [-b batchsize] [-d data-of-days] [-i interval] [-v scalevar] [-p false for don't prepare] [-w false for don't do write] [-q false for don't do query]"

while getopts ':b:d:i:v:pwqh' flag; do
	case "${flag}" in
		b) batch=${OPTARG};;
		d) days=${OPTARG};;
		i) interval=${OPTARG};;
		v) scalevar=${OPTARG};;
		p) doprepare=${OPTARG};;
		w) dowrite=${OPTARG};;
		q) doquery=${OPTARG};;
		:) echo -e "{RED}Missing argument!{NC}"
			echo "$help"
			exit 1
			;;
		h) echo "$help"
			exit 1
			;;
	esac
done

walLevel=`grep "^walLevel" /etc/taos/taos.cfg | awk '{print $2}'`
if [[ "$walLevel" -eq "2" ]]; then
	walPostfix="wal2"
elif [[ "$walLevel" -eq "1" ]]; then
	walPostfix="wal1"
else
	echo -e "${RED}wrong walLevel $walLevel found! ${NC}"
	exit 1
fi

echo -e "${GREEN} $walPostfix found! ${NC}"

if [[ $scalevar -eq 10000 ]]
then
	TIME_START="2018-01-01T00:00:00Z"
	TIME_END="2018-01-02T00:00:00Z"

	if [[ $interval -eq 100 ]]
	then
		interval_s=100s
		DATA_FILE=$DATA_DIR/tdengine-var10k-int100s.dat
		RECORD_CSV_FILE=$WORK_DIR/perftest-var10k-int100s-$walPostfix-report.csv
	else
		interval_s=10s
		DATA_FILE=$DATA_DIR/tdengine-var10k-int10s.dat
		RECORD_CSV_FILE=$WORK_DIR/perftest-var10k-int10s-$walPostfix-report.csv
	fi
else
	if [[ $days -eq 1 ]]
	then
		TIME_START="2018-01-01T00:00:00Z"
		TIME_END="2018-01-02T00:00:00Z"
		DATA_FILE=$DATA_DIR/tdengine-1d.dat
		RECORD_CSV_FILE=$WORK_DIR/perftest-1d-$walPostfix-report.csv
	elif [[ $days -eq 13 ]]
	then
		TIME_START="2018-01-01T00:00:00Z"
		TIME_END="2018-01-14T00:00:00Z"
		DATA_FILE=$DATA_DIR/tdengine-13d.dat
		RECORD_CSV_FILE=$WORK_DIR/perftest-13d-$walPostfix-report.csv
	else
		echo -e "{RED} don't support input $days{NC}"
		exit 1
	fi

	interval_s=${interval}s
fi

echo "TIME_START: $TIME_START, TIME_END: $TIME_END, DATA_FILE: $DATA_FILE"
echo "doprepare: $doprepare, dowrite: $dowrite, doquery: $doquery"

if $doprepare;
then
	do_prepare
fi

echo

if $dowrite;
then
	echo -e "Start test TDengine writting, result in ${GREEN}Green line${NC}"
	do_write
fi

if $doquery;
then
	echo -e "Start test TDengine query, result in ${GREEN}Green line${NC}"
	do_query
fi

echo
echo
echo    "======================================================"
echo    "             tsdb performance comparision             "
echo    "======================================================"
if $dowrite;
then
	echo -e "       Writing $DATA records test takes:          "
	printf  "       TDengine           |       %-4.5f Seconds    \n" $TDWTM
	echo    "------------------------------------------------------"
fi

if $doquery;
then
	echo    "                   Query test cases:                "
	echo    " case 1: select the max(value) from all data    "
	echo    " filtered out 8 hosts                                 "
	echo    "       Query test case 1 takes:                      "
	printf  "       TDengine           |       %-4.5f Seconds    \n" $TDQ1
	echo    "------------------------------------------------------"
	echo    " case 2: select the max(value) from all data          "
	echo    " filtered out 8 hosts with an interval of 1 hour     "
	echo    " case 2 takes:                                       "
	printf  "       TDengine           |       %-4.5f Seconds    \n" $TDQ2
	echo    "------------------------------------------------------"
	echo    " case 3: select the max(value) from random 12 hours"
	echo    " data filtered out 8 hosts with an interval of 10 min         "
	echo    " filtered out 8 hosts interval(1h)                   "
	echo    " case 3 takes:                                       "
	printf  "       TDengine           |       %-4.5f Seconds    \n" $TDQ3
	echo    "------------------------------------------------------"
	echo    " case 4: select the max(value) from random 1 hour data  "
	echo    " data filtered out 8 hosts with an interval of 1 min         "
	echo    " case 4 takes:                                        "
	printf  "       TDengine           |       %-4.5f Seconds    \n" $TDQ4
	echo    "------------------------------------------------------"
fi

#bulk_query_gen/bulk_query_gen  -format influx-http -query-type 1-host-1-hr -scale-var 10 -queries 1000 | query_benchmarker_influxdb/query_benchmarker_influxdb  -urls="http://172.26.89.231:8086" 
#bulk_query_gen/bulk_query_gen  -format tdengine -query-type 1-host-1-hr -scale-var 10 -queries 1000 | query_benchmarker_tdengine/query_benchmarker_tdengine  -urls="http://172.26.89.231:6020" 
today=`date +"%Y%m%d"`
echo "${today}, ${TDWTM}, ${TDQ1}, ${TDQ2}, ${TDQ3}, ${TDQ4}" >> $RECORD_CSV_FILE