queryPerformance.py 5.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
###################################################################
#           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 -*-

R
root 已提交
14

15 16 17 18 19 20 21 22 23 24 25
import sys
import os
import taos
import time


class taosdemoQueryPerformace:
    def initConnection(self):
        self.host = "127.0.0.1"
        self.user = "root"
        self.password = "taosdata"
P
Ping Xiao 已提交
26
        self.config = "/etc/taosperf"
27 28 29 30 31 32 33 34 35
        self.conn = taos.connect(
            self.host,
            self.user,
            self.password,
            self.config)


    def query(self): 
        cursor = self.conn.cursor()                  
R
root 已提交
36
        cursor.execute("use test")
37 38

        totalTime = 0
R
root 已提交
39 40 41 42 43
        for i in range(100):       
            if(sys.argv[1] == '1'):
                # root permission is required
                os.system("echo 3 > /proc/sys/vm/drop_caches")  
            startTime = time.time()            
44 45 46 47 48 49
            cursor.execute("select count(*) from test.meters")
            totalTime += time.time() - startTime
        print("query time for: select count(*) from test.meters %f seconds" % (totalTime / 100))

        totalTime = 0
        for i in range(100):
R
root 已提交
50 51 52
            if(sys.argv[1] == '1'):  
                # root permission is required              
                os.system("echo 3 > /proc/sys/vm/drop_caches")
53 54 55 56 57 58 59
            startTime = time.time()
            cursor.execute("select avg(f1), max(f2), min(f3) from test.meters")
            totalTime += time.time() - startTime
        print("query time for: select avg(f1), max(f2), min(f3) from test.meters %f seconds" % (totalTime / 100))

        totalTime = 0
        for i in range(100):
R
root 已提交
60 61 62
            if(sys.argv[1] == '1'):
                # root permission is required
                os.system("echo 3 > /proc/sys/vm/drop_caches")
63 64 65 66 67 68 69
            startTime = time.time()
            cursor.execute("select count(*) from test.meters where loc='beijing'")
            totalTime += time.time() - startTime
        print("query time for: select count(*) from test.meters where loc='beijing' %f seconds" % (totalTime / 100))

        totalTime = 0
        for i in range(100):
R
root 已提交
70 71 72
            if(sys.argv[1] == '1'):
                # root permission is required              
                os.system("echo 3 > /proc/sys/vm/drop_caches")
73 74 75 76 77 78 79
            startTime = time.time()
            cursor.execute("select avg(f1), max(f2), min(f3) from test.meters where areaid=10")
            totalTime += time.time() - startTime
        print("query time for: select avg(f1), max(f2), min(f3) from test.meters where areaid=10 %f seconds" % (totalTime / 100))

        totalTime = 0
        for i in range(100):
R
root 已提交
80 81 82
            if(sys.argv[1] == '1'):                
                # root permission is required
                os.system("echo 3 > /proc/sys/vm/drop_caches")
83 84 85 86 87 88 89
            startTime = time.time()
            cursor.execute("select avg(f1), max(f2), min(f3) from test.t10 interval(10s)")
            totalTime += time.time() - startTime
        print("query time for: select avg(f1), max(f2), min(f3) from test.t10 interval(10s) %f seconds" % (totalTime / 100))

        totalTime = 0
        for i in range(100):
R
root 已提交
90 91 92
            if(sys.argv[1] == '1'):
                # root permission is required           
                os.system("echo 3 > /proc/sys/vm/drop_caches")
93 94 95 96 97
            startTime = time.time()
            cursor.execute("select last_row(*) from meters")
            totalTime += time.time() - startTime
        print("query time for: select last_row(*) from meters %f seconds" % (totalTime / 100))

R
root 已提交
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
        totalTime = 0
        for i in range(100):
            if(sys.argv[1] == '1'):
                # root permission is required           
                os.system("echo 3 > /proc/sys/vm/drop_caches")
            startTime = time.time()
            cursor.execute("select * from meters")
            totalTime += time.time() - startTime
        print("query time for: select * from meters %f seconds" % (totalTime / 100))

        totalTime = 0
        for i in range(100):
            if(sys.argv[1] == '1'):
                # root permission is required        
                os.system("echo 3 > /proc/sys/vm/drop_caches")
            startTime = time.time()
            cursor.execute("select avg(f1), max(f2), min(f3) from meters where ts <= '2017-07-15 10:40:01.000' and ts <= '2017-07-15 14:00:40.000'")
            totalTime += time.time() - startTime
        print("query time for: select avg(f1), max(f2), min(f3) from meters where ts <= '2017-07-15 10:40:01.000' and ts <= '2017-07-15 14:00:40.000' %f seconds" % (totalTime / 100))

118 119 120 121
if __name__ == '__main__':
    perftest = taosdemoQueryPerformace()
    perftest.initConnection()
    perftest.query()