微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

通过python脚本每秒测量clickhouse查询

如何解决通过python脚本每秒测量clickhouse查询

查询有两部分 -

  1. 为什么 cli 查询客户端执行速度比 python 驱动客户端快?

    我使用 Clickhouse 数据库driver 来触发 Python 中的查询。我正在运行超过 170K+ 行的查询 select * from <table> where id = <some_id> and trans_date < <some date>。因此,当我使用 clickhouse-client(类似于 Postgres 中的 psql)cli 来触发查询时,它需要 60 milliseconds。当我使用上面的驱动程序通过 python 触发时相同的查询,如下所示 -

from clickhouse_driver import Client
from time import time
...

client = Client({server_configurations})
...

start = time()
client.execute(select * from <table> where id = "some_id" and trans_date < "some date")

print(time() - start) // 150 milliseconds

它大约是 150 milliseconds为什么差别这么大?

  1. 如何在python中测量每秒查询次数

    假设我必须衡量我可以在 1 中运行多少个 select * 查询 第二。我做了什么来衡量它 -

start = time()
count = 0

while time() - start <= 1:

   client.execute(("SELECT * FROM <table> WHERE id = 'some_id' AND trans_date < 'some_date' LIMIT 100"))
   count += 1


print("count--->",count) // Number of queries ran

有没有更好的方法来衡量它? python 中的任何工具或模块可以帮助我吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。