TDengine/tests/army/tools/benchmark/basic/queryMain.py
Alex Duan c133489917
new-libtaos-with-ws (#29971)
* enh: rename libtaos.so to libtaosinternal.so

* enh: let python system-test work

* enh: shell for libinternal.so

* enh: refact script

* enh: wrapper for libtaosinternal

* enh: rename some files

* enh: let shell support internal driver

* enh: minor changes

* enh: minor changes

* add intenal.h

* enh: remove unused codes

* enh: minor changs

* feat: mac os issues

* enh: let python test use internal connection

* enh: let nettest work

* enh: let taosc -C work

* enh: test shell in mac os

* enh: minor changes

* enh: let libtaosinternal.so work in linux

* enh: update install script

* enh: for ci

* enh: for windows compile

* enh: minor changes

* enh: compile in windows

* enh: minor changes

* enh: taosinternal work in windows

* enh: add taos_internal_static

* enh: rollback os_for_wrapper

* fix: conflicts

* fix: conflicts

* fix: compile errors

* fix: conflicts

* enh: rename taosinternal to taosnative

* enh: rename taosinternal to taosnative

* fix: compile error

* enh: remove taosnative.h

* fix: compile errors

* enh: set default shell options

* fix: compile errors

* fix: compile errors

* debug: switch taosws branch to feat/new-libtaos-with-ws

* enh: taosBenchmark remove WEBSOCKET finished

* fix: CMakeLists.txt remove WEBSOCKET

* fix: compile errors

* fix: taosBenchmark delete restful code

* .gitignore remove taos-tools folder

* fix: remove taosdump WEBSOCKET MACRO

* fix: build error for taosdump

* fix: build project passed

* fix: support -Z for connect mode

* fix: build error

* fix: build error fixed

* fix: add -Z options

* fix: native and websocket with string

* fix: -Z option core

* fix: build unit test

* fix: build error

* fix: add colon for array

* fix: unit test can not include fun

* fix: CTest pointer null is nullptr

* fix: include pub.h

* fix: taosdump add -Z --driver options

* fix: taosdump support -Z with pub.h pub.c

* fix: toolsGetTimeDay move to pub.c

* fix: restore pub.c only simple fun

* fix: add error tips

* fix: tmfree remove from taosdump

* fix: remove double declare taos variant

* fix: taos support -Z option

* enh: configDir set with main fun

* fix: add g_arguments.configDir

* fix: show tips add cfgdir

* fix: g_argument is pointer

* fix: configDir is global var

* fix: declare g_configDir in benchMain.c

* fix: taos version not show on websocket

* stmt2 websocket prepare with supertable

* stmt2 websocket prepare build

* fix: stmt and stmt2 prepare add db name

* fix: remove -R --restful test case

* fix: taosBenchmark adjust priority cmd > json > evn

* fix: add connect mode test case connMode.py

* fix: clear evn and add host port check

* fix: army/test.py modify start taosAdapter is default

* change: system-test/test.py default start taosAdapter

* fix: add taosAdapter variant to system-test/test.py

* fix: -y must put behind other options

* fix: remove rest sml and add -N normal case

* fix: add -c work cfg test case

* del: queryMain.py remove rest query

* fix: remove groups have a blank append bug

* fix: caseBase.py add db in sql query

* fix: query_json.py remove rest test

* fix: taosBenchmark uniform dsn describe

* fix: add pub.h pub.c to tools public

* fix: case remove restful interface

* fix: build error

* fix: taosDriverCleanup no arg call

* fix: taosdump add test conn mode case taosdumpCommandline.py

* fix: modify insertFullType.json db name

* fix: taosdump connMode test case taosDumpCommandline.py passed

* enh: priority cmd > env > json

* fix: taosCli remove is_native variant

* fix: password is not pointer

* fix: comment -o test case

* fix: solve fun return code check

* fix: windows unresolved strcasecmp

* fix: remove coverHostToServAddr

* fix: forbid check ODR violation

* ci: trigger pr run

* fix: build error not del >>>>>3.0

* fix: support json dbinfo->vgroups have blank space

* fix: solve conflict with merge

* fix: with TrimCaseCmp fun to compare vgroups

* fix: del vgroups support blank code

* feat: wrapper add taos_fetch_fields_e

* fix: move jni from libtaosnative.so to libtaos.so

* fix: move clientTmqConnector.c for jni

* fix: fix assert check with del comment code

* fix: taosBenchmark add prepare stmt debug log

* fix: stmt2 already have debug log on preapare

* fix:  (double)LLONG_MAX force covert

* fix: stmt insert normal table with websocket

* fix: normal table with stmt too many ?

* fix: taosdump stmt_prepare with child tbname

* fix: build error add int code

* feat: stmtPrepare with child table to do

* taos -a options move to native test case

* fix:unit test benchmarkTest passed

* fix: query_json-with-sqlfile.py case no check results

* fix: queryMain.py case lost, put in tasks again

---------

Co-authored-by: Shengliang Guan <slguan@taosdata.com>
2025-03-20 22:54:29 +08:00

264 lines
8.3 KiB
Python

###################################################################
# 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 os
import json
import sys
import os
import time
import datetime
import platform
import subprocess
import frame
import frame.etool
from frame.log import *
from frame.cases import *
from frame.sql import *
from frame.caseBase import *
from frame import *
class TDTestCase(TBase):
def caseDescription(self):
"""
taosBenchmark query->Basic test cases
"""
def runSeconds(self, command, timeout = 180):
tdLog.info(f"runSeconds {command} ...")
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
process.wait(timeout)
# get output
output = process.stdout.read().decode(encoding="gbk")
error = process.stderr.read().decode(encoding="gbk")
return output, error
def getKeyValue(self, content, key, end):
# find key
s = content.find(key)
if s == -1:
return False,""
# skip self
s += len(key)
# skip blank
while s < len(content):
if content[s] != " ":
break
s += 1
# end check
if s + 1 == len(content):
return False, ""
# find end
if len(end) == 0:
e = -1
else:
e = content.find(end, s)
# get value
if e == -1:
value = content[s : ]
else:
value = content[s : e]
return True, value
def getDbRows(self, times):
sql = f"select count(*) from test.meters"
tdSql.waitedQuery(sql, 1, times)
dbRows = tdSql.getData(0, 0)
return dbRows
def checkItem(self, output, key, end, expect, equal):
ret, value = self.getKeyValue(output, key, end)
if ret == False:
tdLog.exit(f"not found key:{key}. end:{end} output:\n{output}")
fval = float(value)
# compare
if equal and fval != expect:
tdLog.exit(f"check not expect. expect:{expect} real:{fval}, key:'{key}' end:'{end}' output:\n{output}")
elif equal == False and fval <= expect:
tdLog.exit(f"failed because {fval} <= {expect}, key:'{key}' end:'{end}' output:\n{output}")
else:
# succ
if equal:
tdLog.info(f"check successfully. key:'{key}' expect:{expect} real:{fval}")
else:
tdLog.info(f"check successfully. key:'{key}' {fval} > {expect}")
def checkAfterRun(self, benchmark, jsonFile, specMode, tbCnt):
# run
cmd = f"{benchmark} -f {jsonFile}"
output, error = self.runSeconds(cmd)
if specMode :
label = "specified_table_query"
else:
label = "super_table_query"
#
# check insert result
#
with open(jsonFile, "r") as file:
data = json.load(file)
queryTimes = data["query_times"]
# contineIfFail
try:
continueIfFail = data["continue_if_fail"]
except:
continueIfFail = "no"
threads = data[label]["threads"]
sqls = data[label]["sqls"]
# batch_query
try:
batchQuery = data[label]["batch_query"]
except:
batchQuery = "no"
# mixed_query
try:
mixedQuery = data[label]["mixed_query"]
except:
mixedQuery = "no"
tdLog.info(f"queryTimes={queryTimes} threads={threads} mixedQuery={mixedQuery} "
f"batchQuery={batchQuery} len(sqls)={len(sqls)} label={label}\n")
totalQueries = 0
threadQueries = 0
QPS = 10
if continueIfFail.lower() == "yes":
allEnd = " "
else:
allEnd = "\n"
if specMode and mixedQuery.lower() != "yes":
# spec
threadQueries = queryTimes * threads
totalQueries = queryTimes * threads * len(sqls)
threadKey = f"complete query with {threads} threads and "
qpsKey = "QPS: "
avgKey = "query delay avg: "
minKey = "min:"
else:
# spec mixed or super
if specMode:
totalQueries = queryTimes * len(sqls)
# spec mixed
if batchQuery.lower() == "yes":
# batch
threadQueries = len(sqls)
QPS = 2
else:
threadQueries = totalQueries
else:
# super
totalQueries = queryTimes * len(sqls) * tbCnt
threadQueries = totalQueries
nSql = len(sqls)
if specMode and nSql < threads :
tdLog.info(f"set threads = {nSql} because len(sqls) < threads")
threads = nSql
threadKey = f"using {threads} threads complete query "
qpsKey = ""
avgKey = "avg delay:"
minKey = "min delay:"
items = [
[threadKey, " ", threadQueries, True],
[qpsKey, " ", 5, False], # qps need > 1
[avgKey, "s", 0, False],
[minKey, "s", 0, False],
["max: ", "s", 0, False],
["p90: ", "s", 0, False],
["p95: ", "s", 0, False],
["p99: ", "s", 0, False],
["INFO: Spend ", " ", 0, False],
["completed total queries: ", ",", totalQueries, True],
["the QPS of all threads:", allEnd, QPS , False] # all qps need > 5
]
# check
for item in items:
if len(item[0]) > 0:
self.checkItem(output, item[0], item[1], item[2], item[3])
# native
def threeQueryMode(self, benchmark, tbCnt, tbRow):
# json
args = [
["./tools/benchmark/basic/json/queryModeSpec", True],
["./tools/benchmark/basic/json/queryModeSpecMix", True],
["./tools/benchmark/basic/json/queryModeSpecMixBatch", True],
["./tools/benchmark/basic/json/queryModeSuper", False]
]
# native
for arg in args:
self.checkAfterRun(benchmark, arg[0] + ".json", arg[1], tbCnt)
def expectFailed(self, command):
ret = os.system(command)
if ret == 0:
tdLog.exit(f" expect failed but success. command={command}")
else:
tdLog.info(f" expect failed is ok. command={command}")
# check excption
def exceptTest(self, benchmark, tbCnt, tbRow):
# 'specified_table_query' and 'super_table_query' error
self.expectFailed(f"{benchmark} -f ./tools/benchmark/basic/json/queryErrorNoSpecSuper.json")
self.expectFailed(f"{benchmark} -f ./tools/benchmark/basic/json/queryErrorBothSpecSuper.json")
# json format error
self.expectFailed(f"{benchmark} -f ./tools/benchmark/basic/json/queryErrorFormat.json")
# batch query
self.expectFailed(f"{benchmark} -f ./tools/benchmark/basic/json/queryErrorBatchNoMix.json")
self.expectFailed(f"{benchmark} -f ./tools/benchmark/basic/json/queryErrorBatchRest.json")
def run(self):
tbCnt = 10
tbRow = 1000
benchmark = etool.benchMarkFile()
# insert
command = f"{benchmark} -d test -t {tbCnt} -n {tbRow} -I stmt2 -r 100 -y"
ret = os.system(command)
if ret !=0 :
tdLog.exit(f"exec failed. command={command}")
# query mode test
self.threeQueryMode(benchmark, tbCnt, tbRow)
# exception test
self.exceptTest(benchmark, tbCnt, tbRow);
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())