当前位置:   article > 正文

Python 压测Mysql、Doris_python 查询doris

python 查询doris
import pymysql
from dbutils.pooled_db import PooledDB
import time
from concurrent.futures import ThreadPoolExecutor

pool = PooledDB(
    creator=pymysql,
    host='',
    # host='172.18.1.16',
    user='root',
    password='',
    port=9030,
    connect_timeout=3880000,
    read_timeout=3880000,
    maxconnections=100,
    mincached=2,
    maxcached=5,
    maxshared=3,
    blocking=True,
    cursorclass=pymysql.cursors.DictCursor
)

count_z =0

def insert_data(thread_id, count):
    conn = pool.connection()
    with conn.cursor() as cursor:
        for i in range(count):
            start_time = time.time()  # 获取开始时间
            data_id = thread_id * count + i + 1
            cursor.execute(f"""
            insert into test.tbl_point_query1 (`key`,table_name,column_name,data_type) values ({data_id},'value1', 'value2', 'value3')
            """)
            conn.commit()
            end_time = time.time()  # 获取结束时间
            duration = end_time - start_time  # 计算执行时间

            print(f"Inserted data: {cursor.rowcount}, duration: {duration:.3f}s")  # 输出插入结果和执行时间
    conn.close()
    # return duration



start_time_z = time.time()
# 并发插入数据
with ThreadPoolExecutor(max_workers=2) as executor:
    futures = []
    for i in range(50):
        future = executor.submit(insert_data, i, 20)
        futures.append(future)
    for future in futures:
        future.result()
end_time_z = time.time()
duration = end_time_z - start_time_z  # 计算执行时间

print("All data inserted.")
print(duration)
# print(count_z)

  • 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
  • 30
  • 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
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/寸_铁/article/detail/973205
推荐阅读
相关标签
  

闽ICP备14008679号