本文介紹用維基百科英語語料庫的資料做效能測試的結果,包含索引構建、單Term查詢、多Term查詢等多項效能測試結果。
測試執行個體規格
引擎版本:AnalyticDB PostgreSQL 7.0版。
核心小版本:v7.1.0.0。
執行個體系列:高可用版。
節點規格:4 C 32 GB。
節點數量:4 Segment。
節點儲存容量:200 GB。
儲存磁碟類型:ESSD雲端硬碟PL1。
Master資源:8 CU。
測試資料集
資料來源為維基百科英語語料庫的快照,包含500萬條資料。點擊GitHub - softhuafei/wiki-dataset下載資料(資料包為wiki-articles-500w-aa~az)。本次測試了1億條資料(將本次測試資料重複匯入20次)下的效能情況。
資料由url、title和body組成。
資料格式為JSON。
資料大小為2.34 GB。
您可以使用cat wiki-articles-500w* > wiki-articles-500w.json.bz2合并測試資料檔案,並使用bzip2 -dk wiki-articles-500w.json.bz2命令解壓合并後的檔案。
效能測試結果
BM25索引構建耗時約為Gin(tsvector)索引耗時的63%。
在單Term查詢方面,BM25索引的QPS效能為Gin(tsvector)索引的6-7倍。
在多Term查詢方面,BM25索引的QPS效能為Gin(tsvector)索引的6-11倍。
在單Term AND點查詢方面,BM25索引的QPS效能為Gin(tsvector)+btree索引的6-9倍。
在單Term AND範圍查詢方面,BM25索引的QPS效能為Gin(tsvector)+btree索引的1-9倍。
索引構建
索引 | 資料匯入耗時 | 構建索引耗時 | 帶索引流式匯入耗時 |
BM25 | 24 min | 36 min | 84 min |
Gin(tsvector) | 137 min | 57 min | - |
查詢單個Term
在body列上查詢包含某個Term的TOP 20結果,例如body:"Gabriel Basso"。這些Term的平均出現頻率為56685(單位:次)。結果取最大的QPS以及對應時間點的RT。
並發數 | BM25 | Gin(tsquery) | ||
QPS | RT (ms) | QPS | RT (ms) | |
1 | 158.86 | 6.45 | 25.97 | 38.35 |
5 | 544.43 | 9.19 | 73.92 | 64.35 |
10 | 738.21 | 12.63 | 89.90 | 128.65 |
20 | 863.07 | 20.69 | 172.83 | 262.89 |
30 | 925.02 | 31.05 | 239.74 | 378.18 |
40 | 1234.45 | 39.64 | 203.91 | 616.93 |
查詢多個Term
在body列上查詢包含多個Term中任意一個或多個的TOP20結果,例如body:handsworth OR body:cern。所有的Term都是從資料集中提取的,本次結果排除了罕見的Term(出現次數少於100次)。每個查詢所包含的Term數量符合權重分布[0.03, 0.15, 0.25, 0.25, 0.15, 0.08, 0.04, 0.03, 0.02]。即有3%的查詢包含1個Term、15%的查詢包含2個Term等。
並發數 | BM25 | GIN(tsvector) | ||
QPS | RT (ms) | QPS | RT (ms) | |
1 | 216.88 | 4.54 | 31.97 | 31.49 |
5 | 842.12 | 5.86 | 104.89 | 47.27 |
10 | 1161.79 | 8.58 | 112.89 | 87.40 |
20 | 1332.61 | 15.03 | 118.87 | 159.25 |
30 | 1380.56 | 21.66 | 120.93 | 264.10 |
40 | 1470.47 | 26.73 | 131.87 | 341.69 |
查詢單Term AND點查
點查條件只命中一條資料。
SELECT * FROM articles ORDER BY body @@@ pgsearch.config('body:"David" AND id:80000000');
SELECT * FROM articles_gin WHERE body_ts @@ to_tsquery('David') AND id = '80000000';並發數 | BM25 | GIN(tsvector)+Btree | ||
QPS | RT (ms) | QPS | RT (ms) | |
1 | 342.92 | 2.81 | 2.00 | 985.66 |
5 | 1434.90 | 3.30 | 4.99 | 2401.95 |
10 | 2293.54 | 4.21 | 6.99 | 4306.61 |
20 | 3084.70 | 6.32 | 13.98 | 8536.26 |
30 | 2835.97 | 10.38 | 19.98 | 12565.44 |
40 | 3081.71 | 12.78 | 24.97 | 17342.22 |
查詢單Term AND範圍查詢
範圍查詢過濾掉99.99%的資料,命中1萬條資料。
SELECT * FROM articles WHERE body @@ pgsearch.config('body:"David" AND id:[110000 TO 120000]');
SELECT * FROM articles_gin WHERE body_ts @@ to_tsquery('David') AND id >= '110000' AND id <= '120000';並發數 | BM25 | GIN(tsvector)+Btree | ||
QPS | RT (ms) | QPS | RT (ms) | |
1 | 9.99 | 110.55 | 1.00 | 1189.95 |
5 | 22.97 | 229.57 | 4.99 | 2074.63 |
10 | 25.97 | 451.81 | 8.99 | 4236.33 |
20 | 32.97 | 951.86 | 14.99 | 8674.06 |
30 | 29.97 | 1366.22 | 19.98 | 13458.88 |
40 | 39.97 | 2071.66 | 32.96 | 18251.81 |