perftest-query.sh 4.9 KB
Newer Older
P
Ping Xiao 已提交
1 2
#!/bin/bash

3 4 5 6 7 8 9 10 11 12
branch=
if [ x$1 != x ];then
        branch=$1
        echo "Testing branch: $branch"
else
        echo "Please enter branch name as a parameter"
        exit 1
fi
jemalloc=
if [ x$2 != x ];then
P
Ping Xiao 已提交
13
		jemalloc=jemalloc
14 15 16 17 18
        echo "Building TDengine using jemalloc"
else
        echo "Building TDengine using glibc"
fi

P
Ping Xiao 已提交
19
today=`date +"%Y%m%d"`
P
Ping Xiao 已提交
20 21
WORK_DIR=/home/ubuntu/pxiao
PERFORMANCE_TEST_REPORT=$WORK_DIR/TDengine/tests/performance-test-report-$today.log
P
Ping Xiao 已提交
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

# Coloured Echoes                                                                                                       #
function red_echo      { echo -e "\033[31m$@\033[0m";   }                                                               #
function green_echo    { echo -e "\033[32m$@\033[0m";   }                                                               #
function yellow_echo   { echo -e "\033[33m$@\033[0m";   }                                                               #
function white_echo    { echo -e "\033[1;37m$@\033[0m"; }                                                               #
# Coloured Printfs                                                                                                      #
function red_printf    { printf "\033[31m$@\033[0m";    }                                                               #
function green_printf  { printf "\033[32m$@\033[0m";    }                                                               #
function yellow_printf { printf "\033[33m$@\033[0m";    }                                                               #
function white_printf  { printf "\033[1;37m$@\033[0m";  }                                                               #
# Debugging Outputs                                                                                                     #
function white_brackets { local args="$@"; white_printf "["; printf "${args}"; white_printf "]"; }                      #
function echoInfo   { local args="$@"; white_brackets $(green_printf "INFO") && echo " ${args}"; }                      #
function echoWarn   { local args="$@";  echo "$(white_brackets "$(yellow_printf "WARN")" && echo " ${args}";)" 1>&2; }  #
function echoError  { local args="$@"; echo "$(white_brackets "$(red_printf    "ERROR")" && echo " ${args}";)" 1>&2; }  #


function stopTaosd {
	echo "Stop taosd"
    systemctl stop taosd
	snap stop tdengine
  	PID=`ps -ef|grep -w taosd | grep -v grep | awk '{print $2}'`
	while [ -n "$PID" ]
	do
    pkill -TERM -x taosd
    sleep 1
  	PID=`ps -ef|grep -w taosd | grep -v grep | awk '{print $2}'`
	done
}

function buildTDengine {
	echoInfo "Build TDengine"
	cd $WORK_DIR/TDengine

	git remote update > /dev/null
P
Ping Xiao 已提交
58
	git reset --hard HEAD
59 60
	git checkout $branch
	REMOTE_COMMIT=`git rev-parse --short remotes/origin/$branch`
P
Ping Xiao 已提交
61 62 63 64 65 66 67 68
	LOCAL_COMMIT=`git rev-parse --short @`

	echo " LOCAL: $LOCAL_COMMIT"
	echo "REMOTE: $REMOTE_COMMIT"
	if [ "$LOCAL_COMMIT" == "$REMOTE_COMMIT" ]; then
		echo "repo up-to-date"
	else
		echo "repo need to pull"
69
		git pull > /dev/null 2>&1
P
Ping Xiao 已提交
70 71

		LOCAL_COMMIT=`git rev-parse --short @`
P
Ping Xiao 已提交
72 73
		if [ $jemalloc = "jemalloc" ];then
			echo "git submodule update --init --recursive"
74 75 76
			git submodule update --init --recursive
		fi
		
P
Ping Xiao 已提交
77 78
		cd debug
		rm -rf *
79

P
Ping Xiao 已提交
80 81
		if [ $jemalloc = "jemalloc" ];then
			echo "cmake .. -DJEMALLOC_ENABLED=true > /dev/null"
82 83 84 85
			cmake .. -DJEMALLOC_ENABLED=true > /dev/null
		else
			cmake .. > /dev/null
		fi
P
Ping Xiao 已提交
86
		make && make install > /dev/null		
P
Ping Xiao 已提交
87 88 89 90
	fi
}

function runQueryPerfTest {
P
Ping Xiao 已提交
91 92
	[ -f $PERFORMANCE_TEST_REPORT ] && rm $PERFORMANCE_TEST_REPORT
	nohup $WORK_DIR/TDengine/debug/build/bin/taosd -c /etc/taosperf/ > /dev/null 2>&1 &
P
Ping Xiao 已提交
93
	echoInfo "Wait TDengine to start"
94
	sleep 60
P
Ping Xiao 已提交
95
	echoInfo "Run Performance Test"	
P
Ping Xiao 已提交
96 97
	cd $WORK_DIR/TDengine/tests/pytest
	
98 99
	python3 query/queryPerformance.py -c $LOCAL_COMMIT | tee -a $PERFORMANCE_TEST_REPORT

100 101 102 103 104 105 106 107 108 109
	mkdir -p /var/lib/perf/
	mkdir -p /var/log/perf/
	rm -rf /var/lib/perf/*
	rm -rf /var/log/perf/*
	nohup $WORK_DIR/TDengine/debug/build/bin/taosd -c /etc/perf/ > /dev/null 2>&1 &	
	echoInfo "Wait TDengine to start"
	sleep 10
	echoInfo "Run Performance Test"	
	cd $WORK_DIR/TDengine/tests/pytest

110 111
	python3 insert/insertFromCSVPerformance.py -c $LOCAL_COMMIT | tee -a $PERFORMANCE_TEST_REPORT
	
112
	python3 tools/taosdemoPerformance.py -c $LOCAL_COMMIT | tee -a $PERFORMANCE_TEST_REPORT
P
Ping Xiao 已提交
113 114 115 116 117
}


function sendReport {
	echo "send report"
118
	receiver="develop@taosdata.com"
P
Ping Xiao 已提交
119 120 121 122 123 124
	mimebody="MIME-Version: 1.0\nContent-Type: text/html; charset=utf-8\n"

	cd $TDENGINE_DIR

	sed -i 's/\x1b\[[0-9;]*m//g' $PERFORMANCE_TEST_REPORT
	BODY_CONTENT=`cat $PERFORMANCE_TEST_REPORT`
P
Ping Xiao 已提交
125 126
	
	echo -e "From: <support@taosdata.com>\nto: ${receiver}\nsubject: Query Performace Report ${branch} ${jemalloc} ${today}, commit ID: ${LOCAL_COMMIT}\n\n${today}:\n${BODY_CONTENT}" | \
P
Ping Xiao 已提交
127
	(cat - && uuencode $PERFORMANCE_TEST_REPORT performance-test-report-$today.log) | \
P
Ping Xiao 已提交
128
	/usr/sbin/ssmtp "${receiver}" && echo "Report Sent!"
P
Ping Xiao 已提交
129 130 131 132 133 134
}


stopTaosd
buildTDengine
runQueryPerfTest
P
Ping Xiao 已提交
135
stopTaosd
P
Ping Xiao 已提交
136 137 138 139

echoInfo "Send Report"
sendReport
echoInfo "End of Test"