mysql Pythonによるclickhouse行数の導入による完了速度への影響(データファイル圧縮なし)
3170 ワード
ステップ1:Mysql Pythonにデータをインポート
ステップ2:pythonはclickhouseでテーブルとデータ処理を構築し、インポートの準備をする
ステップ3:データインポート(データファイル圧縮なし)
時間統計(mysqlのデータ取得時間、clickhouseの挿入時間、mysqlの挿入時間、clickhouseのバーごとの挿入時間):
1000行:クエリー時間:0.07 s clickhouse:0.04 s mysql:0.84 s clickhouse:4.83 s
2000行:クエリー時間:0.13 s clickhouse:0.06 s mysql:1.70 s clickhouse:9.68 s
4000行:クエリー時間:0.26 s clickhouse:0.11 s mysql:4.08 s clickhouse:19.86 s
8000行:クエリー時間:0.55 s clickhouse:0.23 s mysql:8.06 s............
1.6万行:照会時間:1.14 s clickhouse:0.49 s mysql:15.75 s............
3.2万行:照会時間:2.13 s clickhouse:0.80 s mysql:31.51 s............
6.4万行:照会時間:4.29 s clickhouse:1.65 s mysql:63.51 s............
12.8万行:照会時間:8.87 s clickhouse:3.16 s mysql:126 s............
25.6万行:照会時間:17.01 s clickhouse:6.46 s mysql:252 s............
51.2万行:照会時間:33.58 s clickhouse:12.76 s mysql:504 s............
102万行:照会時間:67.16 s clickhouse:25.65 s mysql:1008 s............
204万行:照会時間:135.94 s clickhouse:50.67 s mysql:2016 s............
308万行:照会時間:200 s clickhouse:95 s
基本的には線形成長であり、pythonがデータを処理する時間も増加します.
100万行程度になるとCPUの占有率が急激に上昇する
————————————————————————————
現在の速度比拼の結果は:
mysql pythonによるclickhouseへの直接挿入(大量のデータとともに):360 sの時間がかかる
mysqlはcsvに保存され、csvはclickhouse:530 sにインポートされます.
バーをクリックハウスに挿入するのは遅すぎて、考えません.
ステップ2:pythonはclickhouseでテーブルとデータ処理を構築し、インポートの準備をする
ステップ3:データインポート(データファイル圧縮なし)
from clickhouse_driver import Client
import types
import time,datetime
from datetime import date
import pymysql
import warnings
import csv
warnings.filterwarnings('ignore')
pos1 = pymysql.connect(host='192.168.1.235',port=3306,user='root',password='123456',db='0001790455_pos',charset="utf8")
pos = pos1.cursor()
client = Client(host='192.168.1.231',database='test6',user='default',password='')
x=1000
while (x <=1000) :
client.execute('DROP TABLE IF EXISTS test')
creattable="""CREATE TABLE test (\
consumption_id UInt64,\
member_id UInt64,\
fans_id UInt64,\
bill_date Date,\
money Float32,\
people_num UInt8,\
dish_name String,\
created_org UInt8,\
open_id String,\
subscribed_time DateTime,\
unsubscribed_time DateTime,\
source_type UInt8,\
sns_type UInt8,\
is_subscribed UInt8\
)ENGINE=MergeTree(bill_date,(consumption_id,created_org),8192)"""
data=[]
start = time.time()
pos.execute("select *from bigtable ")
end = time.time()
print(str(x)+' mysql ',end-start)
readcsv=pos.fetchall()
readcsv=list(readcsv)
for row in readcsv:
row=list(row)
data.append(row)
try:
client.execute(creattable)
start = time.time()
client.execute('INSERT INTO test VALUES', data,types_check=True)
end = time.time()
print(str(x)+'clickhouse ',end-start)
print('')
except Exception as e:
print(e)
x=x*2
時間統計(mysqlのデータ取得時間、clickhouseの挿入時間、mysqlの挿入時間、clickhouseのバーごとの挿入時間):
1000行:クエリー時間:0.07 s clickhouse:0.04 s mysql:0.84 s clickhouse:4.83 s
2000行:クエリー時間:0.13 s clickhouse:0.06 s mysql:1.70 s clickhouse:9.68 s
4000行:クエリー時間:0.26 s clickhouse:0.11 s mysql:4.08 s clickhouse:19.86 s
8000行:クエリー時間:0.55 s clickhouse:0.23 s mysql:8.06 s............
1.6万行:照会時間:1.14 s clickhouse:0.49 s mysql:15.75 s............
3.2万行:照会時間:2.13 s clickhouse:0.80 s mysql:31.51 s............
6.4万行:照会時間:4.29 s clickhouse:1.65 s mysql:63.51 s............
12.8万行:照会時間:8.87 s clickhouse:3.16 s mysql:126 s............
25.6万行:照会時間:17.01 s clickhouse:6.46 s mysql:252 s............
51.2万行:照会時間:33.58 s clickhouse:12.76 s mysql:504 s............
102万行:照会時間:67.16 s clickhouse:25.65 s mysql:1008 s............
204万行:照会時間:135.94 s clickhouse:50.67 s mysql:2016 s............
308万行:照会時間:200 s clickhouse:95 s
基本的には線形成長であり、pythonがデータを処理する時間も増加します.
100万行程度になるとCPUの占有率が急激に上昇する
————————————————————————————
現在の速度比拼の結果は:
mysql pythonによるclickhouseへの直接挿入(大量のデータとともに):360 sの時間がかかる
mysqlはcsvに保存され、csvはclickhouse:530 sにインポートされます.
バーをクリックハウスに挿入するのは遅すぎて、考えません.