concurrent_inquiry.py 6.5 KB
Newer Older
L
liuyq-617 已提交
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
###################################################################
#           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 threading
import taos

import json
import time
import random
# query sql
query_sql = [
# first supertable
"select count(*) from test.meters where c1 > 50;",
"select count(*) from test.meters where c2 >= 50 and c2 < 100;",
"select count(*) from test.meters where c3 != 5;",
"select count(*) from test.meters where t3 > 2;",
"select count(*) from test.meters where ts <> '2020-05-13 10:00:00.002';",
"select count(*) from test.meters where t7 like 'fi%';",
"select count(*) from test.meters where t7 like '_econd';",
"select count(*) from test.meters interval(1n) order by ts desc;",
L
liuyq-617 已提交
30
"select max(c0) from test.meters group by tbname",
L
liuyq-617 已提交
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
"select first(*)  from test.meters;",
"select last(*)  from test.meters;",
"select last_row(*)  from test.meters;",
"select twa(c1) from test.t1 where ts > 1500000001000  and ts < 1500000101000" ,
"select avg(c1) from test.meters;",
"select bottom(c1, 2) from test.t1;",
"select diff(c1) from test.t1;",
"select leastsquares(c1, 1, 1) from test.t1  ;",
"select max(c1) from test.meters;",
"select min(c1) from test.meters;",
"select c1 + c2 * c3 + c1 / c5 + c4 + c2 from test.t1;",
"select percentile(c1, 50) from test.t1;",
"select spread(c1) from test.t1  ;",
"select stddev(c1) from test.t1;",
"select sum(c1) from test.meters;",
"select top(c1, 2) from test.meters;"
"select twa(c6) from test.t1 where ts > 1500000001000  and ts < 1500000101000" ,
"select avg(c6) from test.meters;",
"select bottom(c6, 2) from test.t1;",
"select diff(c6) from test.t1;",
"select leastsquares(c6, 1, 1) from test.t1  ;",
"select max(c6) from test.meters;",
"select min(c6) from test.meters;",
"select c6 + c2 * c3 + c6 / c5 + c4 + c2 from test.t1;",
"select percentile(c6, 50) from test.t1;",
"select spread(c6) from test.t1  ;",
"select stddev(c6) from test.t1;",
"select sum(c6) from test.meters;",
"select top(c6, 2) from test.meters;",
L
liuyq-617 已提交
60 61 62 63 64 65
#all vnode
"select count(*) from test.meters where t5 >2500 and t5<7500",       
"select max(c0),avg(c1) from test.meters where t5 >2500 and t5<7500",
"select sum(c5),avg(c1) from test.meters where t5 >2500 and t5<7500",
"select max(c0),min(c6) from test.meters where t5 >2500 and t5<7500",
"select min(c0),avg(c6) from test.meters where t5 >2500 and t5<7500",
L
liuyq-617 已提交
66 67 68 69 70 71 72 73 74
# second supertable
"select count(*) from test.meters1 where c1 > 50;",
"select count(*) from test.meters1 where c2 >= 50 and c2 < 100;",
"select count(*) from test.meters1 where c3 != 5;",
"select count(*) from test.meters1 where t3 > 2;",
"select count(*) from test.meters1 where ts <> '2020-05-13 10:00:00.002';",
"select count(*) from test.meters1 where t7 like 'fi%';",
"select count(*) from test.meters1 where t7 like '_econd';",
"select count(*) from test.meters1 interval(1n) order by ts desc;",
L
liuyq-617 已提交
75
"select max(c0) from test.meters1 group by tbname",
L
liuyq-617 已提交
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
"select first(*)  from test.meters1;",
"select last(*)  from test.meters1;",
"select last_row(*)  from test.meters1;",
"select twa(c1) from test.m1 where ts > 1500000001000  and ts < 1500000101000" ,
"select avg(c1) from test.meters1;",
"select bottom(c1, 2) from test.m1;",
"select diff(c1) from test.m1;",
"select leastsquares(c1, 1, 1) from test.m1  ;",
"select max(c1) from test.meters1;",
"select min(c1) from test.meters1;",
"select c1 + c2 * c3 + c1 / c5 + c3 + c2 from test.m1;",
"select percentile(c1, 50) from test.m1;",
"select spread(c1) from test.m1  ;",
"select stddev(c1) from test.m1;",
"select sum(c1) from test.meters1;",
"select top(c1, 2) from test.meters1;",
"select twa(c6) from test.m1 where ts > 1500000001000  and ts < 1500000101000" ,
"select avg(c6) from test.meters1;",
"select bottom(c6, 2) from test.m1;",
"select diff(c6) from test.m1;",
"select leastsquares(c6, 1, 1) from test.m1  ;",
"select max(c6) from test.meters1;",
"select min(c6) from test.meters1;",
"select c6 + c2 * c3 + c6 / c5 + c3 + c2 from test.m1;",
"select percentile(c6, 50) from test.m1;",
"select spread(c6) from test.m1  ;",
"select stddev(c6) from test.m1;",
"select sum(c6) from test.meters1;",
L
liuyq-617 已提交
104 105 106 107 108 109 110 111 112 113 114 115 116
"select top(c6, 2) from test.meters1;",
"select count(*) from test.meters1 where t5 >2500 and t5<7500",
#all vnode
"select count(*) from test.meters1 where t5 >2500 and t5<7500",       
"select max(c0),avg(c1) from test.meters1 where t5 >2500 and t5<7500",
"select sum(c5),avg(c1) from test.meters1 where t5 >2500 and t5<7500",
"select max(c0),min(c6) from test.meters1 where t5 >2500 and t5<7500",
"select min(c0),avg(c6) from test.meters1 where t5 >2500 and t5<7500",
#join 
"select * from meters,meters1 where meters.ts = meters1.ts and meters.t5 = meters1.t5",
"select * from meters,meters1 where meters.ts = meters1.ts and meters.t7 = meters1.t7",
"select * from meters,meters1 where meters.ts = meters1.ts and meters.t8 = meters1.t8",
"select meters.ts,meters1.c2 from meters,meters1 where meters.ts = meters1.ts and meters.t8 = meters1.t8"
L
liuyq-617 已提交
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
]

class ConcurrentInquiry:
    def initConnection(self):  
        self.numOfTherads = 50
        self.ts=1500000001000
        

    def query_thread(self,threadID):
        host = "10.211.55.14"
        user = "root"
        password = "taosdata"
        conn = taos.connect(
            host,
            user,
            password,
            )
        cl = conn.cursor()
L
liuyq-617 已提交
135
        cl.execute("use test;")
L
liuyq-617 已提交
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
        
        print("Thread %d: starting" % threadID)
        
        while True:
            ran_query_sql=query_sql
            random.shuffle(ran_query_sql)
            for i in ran_query_sql:
                print("Thread %d : %s"% (threadID,i))
                try:
                    cl.execute(i)
                    cl.fetchall
                except Exception as e:
                    print(
                "Failure thread%d, sql: %s,exception: %s" %
                (threadID, str(i),str(e)))
                    
                
            print("Thread %d: finishing" % threadID)
          
        

    def run(self):
       
        threads = []
        for i in range(50):
            thread = threading.Thread(target=self.query_thread, args=(i,))
            threads.append(thread)
            thread.start()  
        
q = ConcurrentInquiry()
q.initConnection()
q.run()