提交 b2b995e2 编写于 作者: sangshuduo's avatar sangshuduo

[TD-2771] <feature>: python version taosdemo. RESTful works.

上级 26f7e973
...@@ -15,15 +15,16 @@ Author: Shuduo Sang <sangshuduo@gmail.com> ...@@ -15,15 +15,16 @@ Author: Shuduo Sang <sangshuduo@gmail.com>
-p, --port <port> port, The TCP/IP port number to use for the connection. Default is 0. -p, --port <port> port, The TCP/IP port number to use for the connection. Default is 0.
-u, --user <username> user, The user name to use when connecting to the server. Default is 'root'. -u, --user <username> user, The user name to use when connecting to the server. Default is 'root'.
-P, --password <password> password, The password to use when connecting to the server. Default is 'taosdata'. -P, --password <password> password, The password to use when connecting to the server. Default is 'taosdata'.
-l, --colsPerRec <number> num_of_columns_per_record, The number of columns per record. Default is 3.
-d, --dbname <dbname> database, Destination database. Default is 'test'. -d, --dbname <dbname> database, Destination database. Default is 'test'.
-a, --replica <replications> replica, Set the replica parameters of the database, Default 1, min: 1, max: 5. -a, --replica <replications> replica, Set the replica parameters of the database, Default 1, min: 1, max: 5.
-m, --tbname <table prefix> table_prefix, Table prefix name. Default is 't'. -m, --tbname <table prefix> table_prefix, Table prefix name. Default is 't'.
-M, --supertable flag, Use super table. Default is no -M, --stable flag, Use super table. Default is no
-s, --stbname <stable prefix> stable_prefix, STable prefix name. Default is 'st' -s, --stbname <stable prefix> stable_prefix, STable prefix name. Default is 'st'
-Q, --query <DEFAULT | command> query, Execute query command. set 'DEFAULT' means select * from each table -Q, --query <DEFAULT | command> query, Execute query command. set 'DEFAULT' means select * from each table
-T, --numOfThreads <number> num_of_threads, The number of threads. Default is 1. -T, --numOfThreads <number> num_of_threads, The number of threads. Default is 1.
-P, --numOfProcesses <number> num_of_processes, The number of threads. Default is 1. -P, --numOfProcesses <number> num_of_processes, The number of threads. Default is 1.
-r, --numOfRecPerReq <number> num_of_records_per_req, The number of records per request. Default is 1000. -r, --batch <number> num_of_records_per_req, The number of records per request. Default is 1000.
-t, --numOfTb <number> num_of_tables, The number of tables. Default is 1. -t, --numOfTb <number> num_of_tables, The number of tables. Default is 1.
-n, --numOfRec <number> num_of_records_per_table, The number of records per table. Default is 1. -n, --numOfRec <number> num_of_records_per_table, The number of records per table. Default is 1.
-c, --config <path> config_directory, Configuration directory. Default is '/etc/taos/'. -c, --config <path> config_directory, Configuration directory. Default is '/etc/taos/'.
...@@ -33,5 +34,5 @@ Author: Shuduo Sang <sangshuduo@gmail.com> ...@@ -33,5 +34,5 @@ Author: Shuduo Sang <sangshuduo@gmail.com>
-D, --deleteMethod <number> Delete data methods 0: don't delete, 1: delete by table, 2: delete by stable, 3: delete by database. -D, --deleteMethod <number> Delete data methods 0: don't delete, 1: delete by table, 2: delete by stable, 3: delete by database.
-v, --verbose Print verbose output -v, --verbose Print verbose output
-g, --debug Print debug output -g, --debug Print debug output
-y, --skipprompt Skip read key for continous test, default is not skip -y, --skipPrompt Skip read key for continous test, default is not skip
...@@ -75,7 +75,7 @@ def v_print(msg: str, arg1: int, arg2: int, arg3: int, arg4: int): ...@@ -75,7 +75,7 @@ def v_print(msg: str, arg1: int, arg2: int, arg3: int, arg4: int):
def restful_execute(host: str, port: int, user: str, password: str, cmd: str): def restful_execute(host: str, port: int, user: str, password: str, cmd: str):
url = "http://%s:%d/rest/sql" % (host, port) url = "http://%s:%d/rest/sql" % (host, restPort)
if verbose: if verbose:
v_print("cmd: %s", cmd) v_print("cmd: %s", cmd)
...@@ -252,15 +252,8 @@ def insert_func(process: int, thread: int): ...@@ -252,15 +252,8 @@ def insert_func(process: int, thread: int):
if measure: if measure:
exec_start_time = datetime.datetime.now() exec_start_time = datetime.datetime.now()
if oneMoreHost != "NotSupported" and random.randint( restful_execute(
0, 1) == 1: host, port, user, password, cmd)
v_print("%s", "Send to second host")
restful_execute(
oneMoreHost, port, user, password, cmd)
else:
v_print("%s", "Send to first host")
restful_execute(
host, port, user, password, cmd)
if measure: if measure:
exec_end_time = datetime.datetime.now() exec_end_time = datetime.datetime.now()
...@@ -319,38 +312,84 @@ def insert_data_process(i: int, begin: int, end: int): ...@@ -319,38 +312,84 @@ def insert_data_process(i: int, begin: int, end: int):
end)] end)]
wait(workers, return_when=ALL_COMPLETED) wait(workers, return_when=ALL_COMPLETED)
def printConfig():
print("###################################################################");
print("# Use native interface: %s" % native);
print("# Server IP: %s" % host);
if native:
print("# Server port: %s" % port);
else:
print("# Server port: %s" % restPort);
print("# User: %s" % user);
print("# Password: %s" % password);
print("# Number of Columns per record: %s" % colsPerRecord);
print("# Number of Threads: %s" % threads);
print("# Number of Processes: %s" % processes);
print("# Number of Tables: %s" % numOfTb);
print("# Number of records per Table: %s" % numOfRec);
print("# Records/Request: %s" % batch);
print("# Database name: %s" % dbName);
print("# Replica: %s" % replica);
print("# Use STable: %s" % useStable);
print("# Table prefix: %s" % tbNamePrefix);
if useStable:
print("# STable prefix: %s" % stbNamePrefix);
print("# Data order: %s" % outOfOrder);
print("# Data out of order rate: %s" % rateOOOO);
print("# Delete method: %s" % deleteMethod);
print("# Query command: %s" % queryCmd);
print("# Insert Only: %s" % insertOnly);
print("# Verbose output %s" % verbose);
print("# Test time: %s" % datetime.datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
print("###################################################################");
if __name__ == "__main__": if __name__ == "__main__":
native = False
verbose = False verbose = False
measure = False measure = True
dropDbOnly = False dropDbOnly = False
colsPerRecord = 3
numOfDb = 1 numOfDb = 1
dbName = "test"
replica = 1
batch = 1 batch = 1
numOfTb = 1 numOfTb = 1
tbNamePrefix = "tb"
useStable = False
numOfStb = 0 numOfStb = 0
stbNamePrefix = "stb"
numOfRec = 10 numOfRec = 10
ieration = 1 ieration = 1
host = "127.0.0.1" host = "127.0.0.1"
configDir = "/etc/taos"
oneMoreHost = "NotSupported" oneMoreHost = "NotSupported"
port = 6041 port = 6030
restPort = 6041
user = "root" user = "root"
defaultPass = "taosdata" defaultPass = "taosdata"
processes = 1 processes = 1
threads = 1 threads = 1
insertonly = False insertOnly = False
autosubtable = False autosubtable = False
queryCmd = "" queryCmd = "select * from "
outOfOrder = 0
rateOOOO = 0
deleteMethod = 0
skipPrompt = False
try: try:
opts, args = getopt.gnu_getopt(sys.argv[1:], opts, args = getopt.gnu_getopt(sys.argv[1:],
'Nh:p:u:P:d:a:m:Ms:Q:T:P:r:t:n:c:xOR:D:vgyH', 'Nh:p:u:P:d:a:m:Ms:Q:T:P:r:l:t:n:c:xOR:D:vgyH',
[ [
'native', 'host', 'port', 'user', 'password', 'dbname', 'replica', 'tbname', 'native', 'host', 'port', 'user', 'password', 'dbname', 'replica', 'tbname',
'supertable', 'stbname', 'query', 'numOfThreads', 'numOfProcesses', 'stable', 'stbname', 'query', 'numOfThreads', 'numOfProcesses',
'numOfRecPerReq', 'numbOfTb', 'numOfRec', 'config', 'recPerReq', 'colsPerRecord', 'numOfTb', 'numOfRec', 'config',
'insertOnly', 'outOfOrder', 'rateOOOO','deleteMethod', 'insertOnly', 'outOfOrder', 'rateOOOO','deleteMethod',
'verbose', 'debug', 'skipprompt', 'help' 'verbose', 'debug', 'skipPrompt', 'help'
]) ])
except getopt.GetoptError as err: except getopt.GetoptError as err:
print('ERROR:', err) print('ERROR:', err)
...@@ -378,15 +417,16 @@ if __name__ == "__main__": ...@@ -378,15 +417,16 @@ if __name__ == "__main__":
print('\t-p, --port <port> port, The TCP/IP port number to use for the connection. Default is 0.') print('\t-p, --port <port> port, The TCP/IP port number to use for the connection. Default is 0.')
print('\t-u, --user <username> user, The user name to use when connecting to the server. Default is \'root\'.') print('\t-u, --user <username> user, The user name to use when connecting to the server. Default is \'root\'.')
print('\t-P, --password <password> password, The password to use when connecting to the server. Default is \'taosdata\'.') print('\t-P, --password <password> password, The password to use when connecting to the server. Default is \'taosdata\'.')
print('\t-l, --colsPerRec <number> num_of_columns_per_record, The number of columns per record. Default is 3.')
print('\t-d, --dbname <dbname> database, Destination database. Default is \'test\'.') print('\t-d, --dbname <dbname> database, Destination database. Default is \'test\'.')
print('\t-a, --replica <replications> replica, Set the replica parameters of the database, Default 1, min: 1, max: 5.') print('\t-a, --replica <replications> replica, Set the replica parameters of the database, Default 1, min: 1, max: 5.')
print('\t-m, --tbname <table prefix> table_prefix, Table prefix name. Default is \'t\'.') print('\t-m, --tbname <table prefix> table_prefix, Table prefix name. Default is \'t\'.')
print('\t-M, --supertable flag, Use super table. Default is no') print('\t-M, --stable flag, Use super table. Default is no')
print('\t-s, --stbname <stable prefix> stable_prefix, STable prefix name. Default is \'st\'') print('\t-s, --stbname <stable prefix> stable_prefix, STable prefix name. Default is \'st\'')
print('\t-Q, --query <DEFAULT | command> query, Execute query command. set \'DEFAULT\' means select * from each table') print('\t-Q, --query <DEFAULT | command> query, Execute query command. set \'DEFAULT\' means select * from each table')
print('\t-T, --numOfThreads <number> num_of_threads, The number of threads. Default is 1.') print('\t-T, --numOfThreads <number> num_of_threads, The number of threads. Default is 1.')
print('\t-P, --numOfProcesses <number> num_of_processes, The number of threads. Default is 1.') print('\t-P, --numOfProcesses <number> num_of_processes, The number of threads. Default is 1.')
print('\t-r, --numOfRecPerReq <number> num_of_records_per_req, The number of records per request. Default is 1000.') print('\t-r, --batch <number> num_of_records_per_req, The number of records per request. Default is 1000.')
print('\t-t, --numOfTb <number> num_of_tables, The number of tables. Default is 1.') print('\t-t, --numOfTb <number> num_of_tables, The number of tables. Default is 1.')
print('\t-n, --numOfRec <number> num_of_records_per_table, The number of records per table. Default is 1.') print('\t-n, --numOfRec <number> num_of_records_per_table, The number of records per table. Default is 1.')
print('\t-c, --config <path> config_directory, Configuration directory. Default is \'/etc/taos/\'.') print('\t-c, --config <path> config_directory, Configuration directory. Default is \'/etc/taos/\'.')
...@@ -396,104 +436,118 @@ if __name__ == "__main__": ...@@ -396,104 +436,118 @@ if __name__ == "__main__":
print('\t-D, --deleteMethod <number> Delete data methods 0: don\'t delete, 1: delete by table, 2: delete by stable, 3: delete by database.') print('\t-D, --deleteMethod <number> Delete data methods 0: don\'t delete, 1: delete by table, 2: delete by stable, 3: delete by database.')
print('\t-v, --verbose Print verbose output') print('\t-v, --verbose Print verbose output')
print('\t-g, --debug Print debug output') print('\t-g, --debug Print debug output')
print('\t-y, --skipprompt Skip read key for continous test, default is not skip') print('\t-y, --skipPrompt Skip read key for continous test, default is not skip')
print('') print('')
sys.exit(0) sys.exit(0)
if key in ['-s', '--hoSt']: if key in ['-N', '--native']:
host = value try:
import taos
except Exception as e:
print("Error: %s" % e.args[0])
sys.exit(1)
native = True
if key in ['-m', '--one-More-host']: if key in ['-h', '--host']:
oneMoreHost = value host = value
if key in ['-o', '--pOrt']: if key in ['-p', '--port']:
port = int(value) port = int(value)
if key in ['-u', '--User']: if key in ['-u', '--user']:
user = value user = value
if key in ['-w', '--passWord']: if key in ['-P', '--password']:
password = value password = value
else: else:
password = defaultPass password = defaultPass
if key in ['-v', '--Verbose']: if key in ['-d', '--dbname']:
verbose = True dbName = value
if key in ['-a', '--replica']:
replica = int(value)
if replica < 1:
print("FATAL: number of replica need > 0")
sys.exit(1)
if key in ['-A', '--Autosubtable']: if key in ['-m', '--tbname']:
autosubtable = True tbNamePrefix = value
if key in ['-M', '--Measure']: if key in ['-M', '--stable']:
measure = True useStable = True
numOfStb = 1
if key in ['-P', '--Processes']: if key in ['-s', '--stbname']:
processes = int(value) stbNamePrefix = value
if processes < 1:
print("FATAL: number of processes must be larger than 0") if key in ['-Q', '--query']:
sys.exit(1) queryCmd = str(value)
if key in ['-T', '--Threads']: if key in ['-T', '--numOfThreads']:
threads = int(value) threads = int(value)
if threads < 1: if threads < 1:
print("FATAL: number of threads must be larger than 0") print("FATAL: number of threads must be larger than 0")
sys.exit(1) sys.exit(1)
if key in ['-q', '--Query']: if key in ['-P', '--numOfProcesses']:
queryCmd = str(value) processes = int(value)
if processes < 1:
if key in ['-p', '--droPdbonly']: print("FATAL: number of processes must be larger than 0")
dropDbOnly = True
if key in ['-d', '--numofDb']:
numOfDb = int(value)
v_print("numOfDb is %d", numOfDb)
if (numOfdb <= 0):
print("ERROR: wrong number of database given!")
sys.exit(1) sys.exit(1)
if key in ['-c', '--batCh']: if key in ['-r', '--batch']:
batch = int(value) batch = int(value)
if key in ['-t', '--numofTb']: if key in ['-l', '--colsPerRec']:
colsPerRec = int(value)
if key in ['-t', '--numOfTb']:
numOfTb = int(value) numOfTb = int(value)
v_print("numOfTb is %d", numOfTb) v_print("numOfTb is %d", numOfTb)
if key in ['-b', '--numofstB']: if key in ['-n', '--numOfRec']:
numOfStb = int(value)
v_print("numOfStb is %d", numOfStb)
if key in ['-r', '--numofRec']:
numOfRec = int(value) numOfRec = int(value)
v_print("numOfRec is %d", numOfRec) v_print("numOfRec is %d", numOfRec)
if key in ['-f', '--File']:
fileOut = value
v_print("file is %s", fileOut)
if key in ['-x', '--insertonLy']: if key in ['-x', '--insertonLy']:
insertonly = True insertOnly = True
v_print("insert only: %d", insertonly) v_print("insert only: %d", insertOnly)
if key in ['-O', '--outOfOrder']:
outOfOrder = int(value)
v_print("out of order is %d", outOfOrder)
if key in ['-R', '--rateOOOO']:
rateOOOO = int(value)
v_print("the rate of out of order is %d", rateOOOO)
# if verbose: if key in ['-D', '--deleteMethod']:
# restful_execute( deleteMethod = int(value)
# host, v_print("the delete method is %d", deleteMethod)
# port,
# user, if key in ['-v', '--verbose']:
# password, verbose = True
# "SHOW DATABASES")
if key in ['-g', '--debug']:
debug = True
if key in ['-y', '--skipPrompt']:
skipPrompt = True
if verbose:
printConfig()
if skipPrompt == False:
input("Press any key to continue..")
if dropDbOnly: if dropDbOnly:
drop_databases() drop_databases()
print("Drop Database done.") print("Drop Database done.")
sys.exit(0) sys.exit(0)
if queryCmd != "":
print("queryCmd: %s" % queryCmd)
query_data(queryCmd)
sys.exit(0)
# create databases # create databases
if (insertonly == False): if (insertOnly == False):
drop_databases() drop_databases()
create_databases() create_databases()
...@@ -538,6 +592,11 @@ if __name__ == "__main__": ...@@ -538,6 +592,11 @@ if __name__ == "__main__":
restful_execute(host, port, user, password, restful_execute(host, port, user, password,
"SELECT COUNT(*) FROM tb%d" % (j,)) "SELECT COUNT(*) FROM tb%d" % (j,))
if queryCmd != "":
print("queryCmd: %s" % queryCmd)
query_data(queryCmd)
sys.exit(0)
print("done") print("done")
if measure: if measure:
end_time = time.time() end_time = time.time()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册