はじめに
parquetが出て十年以上でしょうか。オープンソースのビッグデータ用ファイルフォーマットといえばparquetですね。ですが、あたらしいファイルフォーマットのVortexが登場しました。parquetより高性能らしいので、これを試してみたいと思います。
データの準備
duckdbにベンチマーク用データ生成機能があるので利用します。ベンチマーク用データをparquetとvortex両方で生成します。
import duckdb
from pyarrow import parquet as pqimport duckdb
from pyarrow import parquet as pq
con = duckdb.connect("/home/mydir/Documents/20261811_vortex_benchmark/bench.duckdb")
con.execute("""
INSTALL tpch; LOAD tpch;
INSTALL vortex; LOAD vortex;
-- これがないとメモリーあふれる
SET threads = 4;
SET memory_limit = '8GB';
SET temp_directory = '/home/mydir/Documents/20261811_vortex_benchmark/duckdb_tmp';
SET max_temp_directory_size = '200GB';
""")
con.execute("CALL dbgen(sf=100)")
print(con.execute("show tables").fetchall())
tables = ["customer", "lineitem", "nation", "orders", "part", "partsupp", "region", "supplier"]
for t in tables:
con.execute("COPY {} TO 'data/{}.parquet' (FORMAT PARQUET);".format(t, t))
con.execute("COPY {} TO 'data/{}.vortex' (FORMAT VORTEX);".format(t, t))
parquetのベンチマーク
con = duckdb.connect("/home/mydir/Documents/20261811_vortex_benchmark/bench_parquet.duckdb")
duckdb.sql("""
SET threads = 4;
SET memory_limit = '8GB';
SET temp_directory = '/home/shumpei/Documents/20261811_vortex_benchmark/duckdb_tmp';
SET max_temp_directory_size = '200GB';
""")
duckdb.sql("FROM tpch_queries();")
duckdb.sql(
"""--sql
-- ====== 読み込みVIEW(ファイル名はあなたのパスに合わせて) ======
CREATE OR REPLACE VIEW customer AS SELECT * FROM read_parquet('data/customer.parquet');
CREATE OR REPLACE VIEW orders AS SELECT * FROM read_parquet('data/orders.parquet');
CREATE OR REPLACE VIEW lineitem AS SELECT * FROM read_parquet('data/lineitem.parquet');
CREATE OR REPLACE VIEW part AS SELECT * FROM read_parquet('data/part.parquet');
CREATE OR REPLACE VIEW partsupp AS SELECT * FROM read_parquet('data/partsupp.parquet');
CREATE OR REPLACE VIEW supplier AS SELECT * FROM read_parquet('data/supplier.parquet');
CREATE OR REPLACE VIEW nation AS SELECT * FROM read_parquet('data/nation.parquet');
CREATE OR REPLACE VIEW region AS SELECT * FROM read_parquet('data/region.parquet');
""")
import time
import pandas as pd
results = []
for query_num in range(1, 23):
start_time = time.time()
result = duckdb.sql(f"PRAGMA tpch({query_num});")
_ = result.fetchall() # 結果を実際にフェッチ
execution_time = time.time() - start_time
results.append({
'query_number': query_num,
'execution_time_seconds': execution_time
})
print(f"Query {query_num}: {execution_time:.3f}s")
df_results = pd.DataFrame(results)
df_results.to_csv('vortex_result.csv', index=False)
print(f"\nSaved to vortex_result.csv")
df_results
Query 1: 8.828s
Query 2: 1.909s
Query 3: 10.117s
Query 4: 5.122s
Query 5: 9.747s
Query 6: 3.532s
Query 7: 11.157s
Query 8: 13.741s
Query 9: 56.882s
Query 10: 10.615s
Query 11: 1.652s
Query 12: 6.407s
Query 13: 10.623s
Query 14: 8.732s
Query 15: 6.862s
Query 16: 2.164s
Query 17: 11.843s
Query 18: 13.517s
Query 19: 10.368s
Query 20: 8.788s
Query 21: 26.308s
Query 22: 3.358s
vortexのベンチマーク
import duckdb
con = duckdb.connect("/home/shumpei/Documents/20261811_vortex_benchmark/bench_vortex.duckdb")
duckdb.sql("""
INSTALL vortex;
LOAD vortex;
SET threads = 4;
SET memory_limit = '8GB';
SET temp_directory = '/home/shumpei/Documents/20261811_vortex_benchmark/duckdb_tmp';
SET max_temp_directory_size = '200GB';
duckdb.sql("FROM tpch_queries();")
""")
duckdb.sql(
"""--sql
-- ====== 読み込みVIEW(ファイル名はあなたのパスに合わせて) ======
CREATE OR REPLACE VIEW customer AS SELECT * FROM read_vortex('data/customer.vortex');
CREATE OR REPLACE VIEW orders AS SELECT * FROM read_vortex('data/orders.vortex');
CREATE OR REPLACE VIEW lineitem AS SELECT * FROM read_vortex('data/lineitem.vortex');
CREATE OR REPLACE VIEW part AS SELECT * FROM read_vortex('data/part.vortex');
CREATE OR REPLACE VIEW partsupp AS SELECT * FROM read_vortex('data/partsupp.vortex');
CREATE OR REPLACE VIEW supplier AS SELECT * FROM read_vortex('data/supplier.vortex');
CREATE OR REPLACE VIEW nation AS SELECT * FROM read_vortex('data/nation.vortex');
CREATE OR REPLACE VIEW region AS SELECT * FROM read_vortex('data/region.vortex');
""")
import time
import pandas as pd
results = []
for query_num in range(1, 23):
start_time = time.time()
result = duckdb.sql(f"PRAGMA tpch({query_num});")
_ = result.fetchall() # 結果を実際にフェッチ
execution_time = time.time() - start_time
results.append({
'query_number': query_num,
'execution_time_seconds': execution_time
})
print(f"Query {query_num}: {execution_time:.3f}s")
df_results = pd.DataFrame(results)
df_results.to_csv('vortex_result.csv', index=False)
print(f"\nSaved to vortex_result.csv")
df_results
4. ベンチマーク結果
| Query | Vortex (sec) | Parquet (sec) | Comparative (Vortex/Parquet) |
|---|---|---|---|
| 1 | 5.167 | 8.828 | 59% |
| 2 | 0.800 | 1.909 | 42% |
| 3 | 5.205 | 10.117 | 51% |
| 4 | 5.064 | 5.122 | 99% |
| 5 | 5.280 | 9.747 | 54% |
| 6 | 1.281 | 3.532 | 36% |
| 7 | 5.624 | 11.157 | 50% |
| 8 | 9.969 | 13.741 | 73% |
| 9 | 26.833 | 56.882 | 47% |
| 10 | 5.160 | 10.615 | 49% |
| 11 | 1.023 | 1.652 | 62% |
| 12 | 3.843 | 6.407 | 60% |
| 13 | 9.216 | 10.623 | 87% |
| 14 | 2.901 | 8.732 | 33% |
| 15 | 1.811 | 6.862 | 26% |
| 16 | 1.775 | 2.164 | 82% |
| 17 | 5.551 | 11.843 | 47% |
| 18 | 11.823 | 13.517 | 87% |
| 19 | 3.679 | 10.368 | 35% |
| 20 | 4.325 | 8.788 | 49% |
| 21 | 20.860 | 26.308 | 79% |
| 22 | 2.422 | 3.358 | 72% |
| Total | 139.612 | 242.269 | 58% |
まとめ
parquetに比べ、vortexは60%ぐらいの時間(40%の短縮)になった。
もっと大規模データでどうなるか気になる。
databricksやbigqueryなどで採用されてほしい。