2022-05-05 14:17:25 +00:00
###################################################################
# Copyright (c) 2016 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confidential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provided by the written permission from Jianhui Tao
#
###################################################################
# -*- coding: utf-8 -*-
import sys
2022-05-07 12:14:27 +00:00
import os
2022-05-18 17:25:49 +00:00
import threading as thd
2022-05-05 14:17:25 +00:00
import multiprocessing as mp
from numpy . lib . function_base import insert
import taos
from util . log import *
from util . cases import *
from util . sql import *
import numpy as np
import datetime as dt
import time
# constant define
WAITS = 5 # wait seconds
class TDTestCase :
#
# --------------- main frame -------------------
#
2022-05-20 01:49:47 +00:00
clientCfgDict = { ' queryproxy ' : ' 1 ' , ' debugFlag ' : 135 }
2022-05-16 01:47:08 +00:00
clientCfgDict [ " queryproxy " ] = ' 2 '
2022-05-20 01:49:47 +00:00
clientCfgDict [ " debugFlag " ] = 143
2022-05-16 01:47:08 +00:00
updatecfgDict = { ' clientCfg ' : { } }
2022-05-20 01:49:47 +00:00
updatecfgDict = { ' debugFlag ' : 143 }
2022-05-16 01:47:08 +00:00
updatecfgDict [ " clientCfg " ] = clientCfgDict
2022-05-05 14:17:25 +00:00
def caseDescription ( self ) :
'''
limit and offset keyword function test cases ;
case1 : limit offset base function test
case2 : offset return valid
'''
2022-07-29 07:23:56 +00:00
return
2022-05-05 14:17:25 +00:00
def getBuildPath ( self ) :
selfPath = os . path . dirname ( os . path . realpath ( __file__ ) )
if ( " community " in selfPath ) :
projPath = selfPath [ : selfPath . find ( " community " ) ]
else :
projPath = selfPath [ : selfPath . find ( " tests " ) ]
for root , dirs , files in os . walk ( projPath ) :
2022-06-09 03:48:41 +00:00
if ( " taosd " in files or " taosd.exe " in files ) :
2022-05-05 14:17:25 +00:00
rootRealPath = os . path . dirname ( os . path . realpath ( root ) )
if ( " packaging " not in rootRealPath ) :
buildPath = root [ : len ( root ) - len ( " /build/bin " ) ]
break
return buildPath
# init
2022-10-31 06:41:59 +00:00
def init ( self , conn , logSql , replicaVar = 1 ) :
2022-11-02 09:33:44 +00:00
self . replicaVar = int ( replicaVar )
2022-05-05 14:17:25 +00:00
tdLog . debug ( " start to execute %s " % __file__ )
tdSql . init ( conn . cursor ( ) )
# tdSql.prepare()
# self.create_tables();
self . ts = 1500000000000
2022-07-29 07:23:56 +00:00
# stop
2022-05-05 14:17:25 +00:00
def stop ( self ) :
tdSql . close ( )
tdLog . success ( " %s successfully executed " % __file__ )
2022-05-18 17:25:49 +00:00
# --------------- case -------------------
2022-05-05 14:17:25 +00:00
def newcur ( self , host , cfg ) :
user = " root "
password = " taosdata "
2022-07-29 07:23:56 +00:00
port = 6030
2022-06-28 11:17:01 +00:00
con = taos . connect ( host = host , user = user , password = password , config = cfg , port = port )
2022-05-05 14:17:25 +00:00
cur = con . cursor ( )
print ( cur )
return cur
2022-05-18 17:25:49 +00:00
# create tables
def create_tables ( self , host , dbname , stbname , count ) :
2022-05-05 14:17:25 +00:00
buildPath = self . getBuildPath ( )
config = buildPath + " ../sim/dnode1/cfg/ "
2022-07-29 07:23:56 +00:00
2022-05-05 14:17:25 +00:00
tsql = self . newcur ( host , config )
tsql . execute ( " use %s " % dbname )
pre_create = " create table "
sql = pre_create
2022-05-18 17:25:49 +00:00
count = int ( count )
2022-05-05 14:17:25 +00:00
tdLog . debug ( " doing create one stable %s and %d child table in %s ... " % ( stbname , count , dbname ) )
# print(time.time())
exeStartTime = time . time ( )
# print(type(tcountStop),type(tcountStart))
2022-05-18 17:25:49 +00:00
for i in range ( 0 , count ) :
2022-05-05 14:17:25 +00:00
sql + = " %s _ %d using %s tags( %d ) " % ( stbname , i , stbname , i + 1 )
if i > 0 and i % 20000 == 0 :
# print(sql)
tsql . execute ( sql )
sql = pre_create
# print(time.time())
2022-07-29 07:23:56 +00:00
# end sql
2022-05-05 14:17:25 +00:00
if sql != pre_create :
# print(sql)
tsql . execute ( sql )
exeEndTime = time . time ( )
spendTime = exeEndTime - exeStartTime
speedCreate = count / spendTime
# tdLog.debug("spent %.2fs to create 1 stable and %d table, create speed is %.2f table/s... [OK]"% (spendTime,count,speedCreate))
return
2022-06-16 14:07:27 +00:00
def mutiThread_create_tables ( self , host , dbname , stbname , vgroups , threadNumbers , childcount ) :
2022-05-18 17:25:49 +00:00
buildPath = self . getBuildPath ( )
config = buildPath + " ../sim/dnode1/cfg/ "
2022-07-29 07:23:56 +00:00
2022-05-18 17:25:49 +00:00
tsql = self . newcur ( host , config )
tdLog . debug ( " create database %s " % dbname )
tsql . execute ( " drop database if exists %s " % dbname )
tsql . execute ( " create database %s vgroups %d " % ( dbname , vgroups ) )
tsql . execute ( " use %s " % dbname )
2022-06-16 14:07:27 +00:00
count = int ( childcount )
2022-05-18 17:25:49 +00:00
threads = [ ]
for i in range ( threadNumbers ) :
tsql . execute ( " create stable %s %d (ts timestamp, c1 int, c2 binary(10)) tags(t1 int) " % ( stbname , i ) )
2022-07-29 07:23:56 +00:00
threads . append ( thd . Thread ( target = self . create_tables , args = ( host , dbname , stbname + " %d " % i , count , ) ) )
2022-05-18 17:25:49 +00:00
start_time = time . time ( )
for tr in threads :
tr . start ( )
for tr in threads :
tr . join ( )
end_time = time . time ( )
spendTime = end_time - start_time
2022-05-20 08:20:27 +00:00
speedCreate = threadNumbers * count / spendTime
2022-05-18 17:25:49 +00:00
tdLog . debug ( " spent %.2f s to create %d stable and %d table, create speed is %.2f table/s... [OK] " % ( spendTime , threadNumbers , threadNumbers * count , speedCreate ) )
2022-07-29 07:23:56 +00:00
2022-05-18 17:25:49 +00:00
return
# def create_tables(self,host,dbname,stbname,vgroups,tcountStart,tcountStop):
2022-05-05 14:17:25 +00:00
# insert data
2022-05-20 01:49:47 +00:00
def insert_data ( self , host , dbname , stbname , chilCount , ts_start , rowCount ) :
2022-05-18 17:25:49 +00:00
buildPath = self . getBuildPath ( )
config = buildPath + " ../sim/dnode1/cfg/ "
tsql = self . newcur ( host , config )
tdLog . debug ( " ready to inser data " )
tsql . execute ( " use %s " % dbname )
pre_insert = " insert into "
sql = pre_insert
2022-05-20 01:49:47 +00:00
chilCount = int ( chilCount )
allRows = chilCount * rowCount
2022-05-18 17:25:49 +00:00
tdLog . debug ( " doing insert data into stable-index: %s rows: %d ... " % ( stbname , allRows ) )
exeStartTime = time . time ( )
2022-05-20 01:49:47 +00:00
for i in range ( 0 , chilCount ) :
2022-05-18 17:25:49 +00:00
sql + = " %s _ %d values " % ( stbname , i )
for j in range ( rowCount ) :
sql + = " ( %d , %d , ' taos_ %d ' ) " % ( ts_start + j * 1000 , j , j )
2022-05-20 01:49:47 +00:00
if j > 0 and j % 4000 == 0 :
2022-05-18 17:25:49 +00:00
# print(sql)
2022-05-20 01:49:47 +00:00
tsql . execute ( sql )
2022-05-18 17:25:49 +00:00
sql = " insert into %s _ %d values " % ( stbname , i )
2022-07-29 07:23:56 +00:00
# end sql
2022-05-18 17:25:49 +00:00
if sql != pre_insert :
2022-05-20 08:20:27 +00:00
# print(sql)
2022-05-20 01:49:47 +00:00
print ( len ( sql ) )
tsql . execute ( sql )
2022-05-18 17:25:49 +00:00
exeEndTime = time . time ( )
spendTime = exeEndTime - exeStartTime
speedInsert = allRows / spendTime
2022-05-20 01:49:47 +00:00
tdLog . debug ( " spent %.2f s to INSERT %d rows into %s , insert rate is %.2f rows/s... [OK] " % ( spendTime , allRows , stbname , speedInsert ) )
# tdLog.debug("INSERT TABLE DATA ............ [OK]")
2022-05-18 17:25:49 +00:00
return
2022-05-20 01:49:47 +00:00
def mutiThread_insert_data ( self , host , dbname , stbname , threadNumbers , chilCount , ts_start , childrowcount ) :
2022-05-18 17:25:49 +00:00
buildPath = self . getBuildPath ( )
config = buildPath + " ../sim/dnode1/cfg/ "
2022-07-29 07:23:56 +00:00
2022-05-18 17:25:49 +00:00
tsql = self . newcur ( host , config )
tdLog . debug ( " ready to inser data " )
tsql . execute ( " use %s " % dbname )
2022-05-20 01:49:47 +00:00
chilCount = int ( chilCount )
2022-05-18 17:25:49 +00:00
threads = [ ]
for i in range ( threadNumbers ) :
2022-05-20 01:49:47 +00:00
# tsql.execute("create stable %s%d(ts timestamp, c1 int, c2 binary(10)) tags(t1 int)"%(stbname,i))
2022-07-29 07:23:56 +00:00
threads . append ( thd . Thread ( target = self . insert_data , args = ( host , dbname , stbname + " %d " % i , chilCount , ts_start , childrowcount , ) ) )
2022-05-18 17:25:49 +00:00
start_time = time . time ( )
for tr in threads :
tr . start ( )
for tr in threads :
tr . join ( )
end_time = time . time ( )
spendTime = end_time - start_time
2022-05-20 01:49:47 +00:00
tableCounts = threadNumbers * chilCount
stableRows = chilCount * childrowcount
allRows = stableRows * threadNumbers
speedInsert = allRows / spendTime
for i in range ( threadNumbers ) :
tdSql . execute ( " use %s " % dbname )
tdSql . query ( " select count(*) from %s %d " % ( stbname , i ) )
tdSql . checkData ( 0 , 0 , stableRows )
tdLog . debug ( " spent %.2f s to insert %d rows into %d stable and %d table, speed is %.2f table/s... [OK] " % ( spendTime , allRows , threadNumbers , tableCounts , speedInsert ) )
tdLog . debug ( " INSERT TABLE DATA ............ [OK] " )
2022-05-05 14:17:25 +00:00
return
2022-05-18 17:25:49 +00:00
2022-05-07 12:14:27 +00:00
def taosBench ( self , jsonFile ) :
buildPath = self . getBuildPath ( )
if ( buildPath == " " ) :
tdLog . exit ( " taosd not found! " )
else :
tdLog . info ( " taosd found in %s " % buildPath )
taosBenchbin = buildPath + " /build/bin/taosBenchmark "
os . system ( " %s -f %s -y " % ( taosBenchbin , jsonFile ) )
2022-07-29 07:23:56 +00:00
2022-05-07 12:14:27 +00:00
return
2022-05-16 01:47:08 +00:00
def taosBenchCreate ( self , host , dropdb , dbname , stbname , vgroups , processNumbers , count ) :
2022-07-29 07:23:56 +00:00
2022-05-07 12:14:27 +00:00
# count=50000
buildPath = self . getBuildPath ( )
2022-05-09 15:10:25 +00:00
config = buildPath + " ../sim/dnode1/cfg/ "
tsql = self . newcur ( host , config )
2022-05-07 12:14:27 +00:00
# insert: create one or mutiple tables per sql and insert multiple rows per sql
2022-05-09 15:10:25 +00:00
tsql . execute ( " drop database if exists %s " % dbname )
2022-05-05 14:17:25 +00:00
2022-05-09 15:10:25 +00:00
tsql . execute ( " create database %s vgroups %d " % ( dbname , vgroups ) )
print ( " db has been created " )
2022-08-11 13:55:20 +00:00
# tsql.getResult("select * from information_schema.ins_databases")
2022-05-09 15:10:25 +00:00
# print(tdSql.queryResult)
tsql . execute ( " use %s " % dbname )
2022-07-29 07:23:56 +00:00
2022-05-07 12:14:27 +00:00
threads = [ ]
2022-05-16 01:47:08 +00:00
for i in range ( processNumbers ) :
2022-05-07 12:14:27 +00:00
jsonfile = " 1-insert/Vgroups %d %d .json " % ( vgroups , i )
os . system ( " cp -f 1-insert/manyVgroups.json %s " % ( jsonfile ) )
2022-05-09 06:59:23 +00:00
os . system ( " sed -i ' s/ \" name \" : \" db \" ,/ \" name \" : \" %s \" ,/g ' %s " % ( dbname , jsonfile ) )
2022-05-09 15:10:25 +00:00
os . system ( " sed -i ' s/ \" drop \" : \" no \" ,/ \" drop \" : \" %s \" ,/g ' %s " % ( dropdb , jsonfile ) )
os . system ( " sed -i ' s/ \" host \" : \" 127.0.0.1 \" ,/ \" host \" : \" %s \" ,/g ' %s " % ( host , jsonfile ) )
os . system ( " sed -i ' s/ \" childtable_count \" : 10000,/ \" childtable_count \" : %d ,/g ' %s " % ( count , jsonfile ) )
2022-05-07 12:14:27 +00:00
os . system ( " sed -i ' s/ \" name \" : \" stb1 \" ,/ \" name \" : \" %s %d \" ,/g ' %s " % ( stbname , i , jsonfile ) )
os . system ( " sed -i ' s/ \" childtable_prefix \" : \" stb1_ \" ,/ \" childtable_prefix \" : \" %s %d _ \" ,/g ' %s " % ( stbname , i , jsonfile ) )
2022-07-29 07:23:56 +00:00
threads . append ( mp . Process ( target = self . taosBench , args = ( " %s " % jsonfile , ) ) )
2022-05-07 12:14:27 +00:00
start_time = time . time ( )
for tr in threads :
tr . start ( )
for tr in threads :
tr . join ( )
end_time = time . time ( )
spendTime = end_time - start_time
speedCreate = count / spendTime
tdLog . debug ( " spent %.2f s to create 1 stable and %d table, create speed is %.2f table/s... [OK] " % ( spendTime , count , speedCreate ) )
return
2022-06-17 13:44:16 +00:00
2022-06-16 14:07:27 +00:00
def checkData ( self , dbname , stbname , stableCount , CtableCount , rowsPerSTable , ) :
tdSql . execute ( " use %s " % dbname )
tdSql . query ( " show stables " )
tdSql . checkRows ( stableCount )
tdSql . query ( " show tables " )
tdSql . checkRows ( CtableCount )
for i in range ( stableCount ) :
tdSql . query ( " select count(*) from %s %d " % ( stbname , i ) )
tdSql . checkData ( 0 , 0 , rowsPerSTable )
2022-07-29 07:23:56 +00:00
return
# test case1 base
2022-05-05 14:17:25 +00:00
def test_case1 ( self ) :
2022-06-16 14:07:27 +00:00
#stableCount=threadNumbersCtb
parameterDict = { ' vgroups ' : 1 , \
' threadNumbersCtb ' : 5 , \
' threadNumbersIda ' : 5 , \
' stableCount ' : 5 , \
' tablesPerStb ' : 50 , \
' rowsPerTable ' : 10 , \
' dbname ' : ' db ' , \
' stbname ' : ' stb ' , \
' host ' : ' localhost ' , \
' startTs ' : 1640966400000 } # 2022-01-01 00:00:00.000
2022-07-29 07:23:56 +00:00
2022-05-18 17:25:49 +00:00
tdLog . debug ( " -----create database and muti-thread create tables test------- " )
#host,dbname,stbname,vgroups,threadNumbers,tcountStart,tcountStop
2022-05-20 01:49:47 +00:00
#host, dbname, stbname, threadNumbers, chilCount, ts_start, childrowcount
2022-06-16 14:07:27 +00:00
self . mutiThread_create_tables (
host = parameterDict [ ' host ' ] ,
dbname = parameterDict [ ' dbname ' ] ,
2022-07-29 07:23:56 +00:00
stbname = parameterDict [ ' stbname ' ] ,
vgroups = parameterDict [ ' vgroups ' ] ,
threadNumbers = parameterDict [ ' threadNumbersCtb ' ] ,
2022-06-16 14:07:27 +00:00
childcount = parameterDict [ ' tablesPerStb ' ] )
self . mutiThread_insert_data (
host = parameterDict [ ' host ' ] ,
dbname = parameterDict [ ' dbname ' ] ,
2022-07-29 07:23:56 +00:00
stbname = parameterDict [ ' stbname ' ] ,
2022-06-16 14:07:27 +00:00
threadNumbers = parameterDict [ ' threadNumbersIda ' ] ,
chilCount = parameterDict [ ' tablesPerStb ' ] ,
ts_start = parameterDict [ ' startTs ' ] ,
childrowcount = parameterDict [ ' rowsPerTable ' ] )
tableCount = parameterDict [ ' threadNumbersCtb ' ] * parameterDict [ ' tablesPerStb ' ]
rowsPerStable = parameterDict [ ' rowsPerTable ' ] * parameterDict [ ' tablesPerStb ' ]
self . checkData ( dbname = parameterDict [ ' dbname ' ] , stbname = parameterDict [ ' stbname ' ] , stableCount = parameterDict [ ' threadNumbersCtb ' ] , CtableCount = tableCount , rowsPerSTable = rowsPerStable )
2022-07-29 07:23:56 +00:00
2022-05-07 12:14:27 +00:00
def test_case3 ( self ) :
2022-06-16 14:07:27 +00:00
#stableCount=threadNumbersCtb
parameterDict = { ' vgroups ' : 1 , \
' threadNumbersCtb ' : 8 , \
' stableCount ' : 5 , \
' tablesPerStb ' : 10 , \
' rowsPerTable ' : 100 , \
' dbname ' : ' db1 ' , \
' stbname ' : ' stb1 ' , \
' host ' : ' localhost ' , \
' startTs ' : 1640966400000 } # 2022-01-01 00:00:00.000
2022-07-29 07:23:56 +00:00
2022-06-16 14:07:27 +00:00
self . taosBenchCreate (
parameterDict [ ' host ' ] ,
" no " ,
2022-07-29 07:23:56 +00:00
parameterDict [ ' dbname ' ] ,
parameterDict [ ' stbname ' ] ,
parameterDict [ ' vgroups ' ] ,
parameterDict [ ' threadNumbersCtb ' ] ,
2022-06-16 14:07:27 +00:00
parameterDict [ ' tablesPerStb ' ] )
tableCount = parameterDict [ ' threadNumbersCtb ' ] * parameterDict [ ' tablesPerStb ' ]
rowsPerStable = parameterDict [ ' rowsPerTable ' ] * parameterDict [ ' tablesPerStb ' ]
self . checkData (
dbname = parameterDict [ ' dbname ' ] ,
2022-07-29 07:23:56 +00:00
stbname = parameterDict [ ' stbname ' ] ,
2022-06-16 14:07:27 +00:00
stableCount = parameterDict [ ' threadNumbersCtb ' ] ,
CtableCount = tableCount ,
rowsPerSTable = rowsPerStable )
2022-05-12 01:42:53 +00:00
# self.taosBenchCreate("test209","no","db2", "stb2", 1, 8, 1*10000)
2022-05-11 13:56:16 +00:00
2022-05-09 15:10:25 +00:00
# self.taosBenchCreate("chenhaoran02","no","db1", "stb1", 1, 8, 1*10000)
2022-05-07 12:14:27 +00:00
2022-05-09 06:59:23 +00:00
# self.taosBenchCreate("db1", "stb1", 4, 5, 100*10000)
# self.taosBenchCreate("db1", "stb1", 1, 5, 100*10000)
2022-07-29 07:23:56 +00:00
return
2022-05-07 12:14:27 +00:00
2022-07-29 07:23:56 +00:00
# run case
2022-05-18 17:25:49 +00:00
def run ( self ) :
2022-06-13 01:56:23 +00:00
# create database and tables。
self . test_case1 ( )
tdLog . debug ( " LIMIT test_case1 ............ [OK] " )
2022-05-18 17:25:49 +00:00
2022-05-23 06:43:39 +00:00
# taosBenchmark: create database/table and insert data
self . test_case3 ( )
tdLog . debug ( " LIMIT test_case3 ............ [OK] " )
2022-05-18 17:25:49 +00:00
2022-07-29 07:23:56 +00:00
return
2022-05-05 14:17:25 +00:00
#
# add case with filename
#
tdCases . addWindows ( __file__ , TDTestCase ( ) )
2022-06-28 11:17:01 +00:00
tdCases . addLinux ( __file__ , TDTestCase ( ) )