全部產品
Search
文件中心

PolarDB:使用VectorDBBench測試MySQL協議向量檢索效能

更新時間:Apr 24, 2026

本文介紹如何使用VectorDBBench對PolarDB的MySQL協議向量檢索能力進行效能測試,並展示在不同資料集和並發條件下的測試結果。

測試環境

PolarDB叢集規格

節點角色

規格

配置

數量

讀寫節點(RW)

polar.mysql.x4.large

4核16 GB

1

唯讀節點(熱備)

polar.mysql.x4.large

4核16 GB

1

列存索引唯讀節點

polar.mysql.x4.4xlarge

32核128 GB

1

說明

向量資料通過COMMENT 'COLUMNAR=1'建立在InnoDB表上,列存索引唯讀節點會自動同步並構建FAISS_HNSW_FLAT向量索引,向量檢索請求發送至列存索引唯讀節點執行。

測試用戶端(ECS)

ECS執行個體規格:ecs.g9i.4xlarge(16 vCPU / 64 GB記憶體),與PolarDB叢集位於同一可用性區域。

測試載入器與資料集

VectorDBBench是由Zilliz開源的向量資料庫基準測試載入器,支援對主流向量資料庫進行端到端的效能評測,涵蓋資料寫入、索引構建和向量檢索等環節。VectorDBBench針對PolarDB提供以下子命令,對應不同的向量索引類型:

  • polardbhnswflat:使用HNSW_FLAT索引類型進行測試。

  • polardbhnswpq:使用HNSW_PQ索引類型進行測試。

  • polardbhnswsq:使用HNSW_SQ索引類型進行測試。

本文使用polardbhnswflat(HNSW_FLAT索引)進行測試,選用以下三個資料集:

資料集

向量數量

維度

case-type參數

Cohere 768D 1M

1,000,000

768

Performance768D1M

Cohere 768D 10M

10,000,000

768

Performance768D10M

OpenAI 1536D 5M

5,000,000

1536

Performance1536D5M

測試步驟

安裝VectorDBBench

在測試用戶端上執行以下命令安裝VectorDBBench:

git clone https://github.com/zilliztech/VectorDBBench.git
cd VectorDBBench

# 建立並啟動 venv
python3 -m venv .venv
source .venv/bin/activate

# 升級 pip
pip install --upgrade pip

# 安裝 VectorDBBench 及 PolarDB 依賴
pip install -e '.[polardb]'

執行測試

以Cohere 768D 1M資料集為例,執行以下命令:

DATASET_LOCAL_DIR=/root/ \
DATASET_SOURCE=AliyunOSS \
NUM_PER_BATCH=64 \
vectordbbench polardbhnswflat \
    --case-type Performance768D1M \
    --username <user_name> \
    --password <password> \
    --host <host> \
    --port 3306 \
    --m 16 \
    --ef-construction 256 \
    --ef-search 256 \
    --insert-workers 64 \
    --num-concurrency '20,40,60,80,100' \
    --concurrency-duration 60 \
    --task-label test_ecs \
    --db-label ecs_test \
    --post-load-index

參數說明

參數

說明

NUM_PER_BATCH

寫入資料時單次INSERT語句的batch size。

--case-type

選擇測試資料集。可選值:Performance768D1M、Performance768D10M、Performance1536D5M。

--m / --ef-construction

HNSW索引構圖參數。--m控制每個節點的最大鄰居數,--ef-construction控制索引構建時的搜尋寬度。

--ef-search

檢索時的搜尋寬度,值越大召回率越高,但延遲也會增加。

--insert-workers

並發匯入線程數。

--num-concurrency

檢索階段使用的並發檔位列表,以英文逗號分隔。

--concurrency-duration

每個並發檔位的期間,單位為秒。

--post-load-index

先全量匯入資料,再一次性構建向量索引。

說明

測試其他資料集時,將--case-type修改為對應的值,並根據資料集特點調整--m、--ef-construction和--ef-search參數。

測試結果

Cohere 768D 1M 資料集

  • 測試參數:--m 16 --ef-construction 256 --ef-search 256。

  • 關鍵計量:

    指標

    數值

    Recall@100

    0.9612

    單線程-平均延遲

    2.6 ms

    單線程-p95延遲

    3.0 ms

    單線程-p99延遲

    3.3 ms

    構建索引耗時(optimize)

    76.80 s

    峰值 QPS(concurrency=100)

    13060.41

  • 不同並發度下的效能表現如下:

    並發數

    QPS

    平均延遲(ms)

    P95 延遲(ms)

    P99 延遲(ms)

    20

    5771.52

    3.46

    4.80

    6.48

    40

    8901.77

    4.48

    7.29

    9.55

    60

    11932.17

    5.01

    9.19

    12.51

    80

    12589.50

    6.33

    11.97

    15.96

    100

    13060.41

    7.62

    14.33

    19.50

Cohere 768D 10M 資料集

  • 測試參數:--m 16 --ef-construction 500 --ef-search 300。

  • 關鍵計量:

    指標

    數值

    Recall@100

    0.9551

    單線程-平均延遲

    3.1 ms

    單線程-p95延遲

    3.7 ms

    單線程-p99延遲

    4.2 ms

    構建索引耗時(optimize)

    1625.95 s

    峰值 QPS

    10174.35

  • 不同並發度下的效能表現如下:

    並發數

    QPS

    平均延遲(ms)

    P95 延遲(ms)

    P99 延遲(ms)

    20

    4859.82

    4.11

    5.78

    7.72

    40

    6556.74

    6.09

    9.95

    12.55

    60

    9293.53

    6.44

    12.25

    16.45

    80

    10063.69

    7.93

    15.65

    21.15

    100

    10174.35

    9.80

    18.99

    26.17

OpenAI 1536D 5M 資料集

  • 測試參數:--m 16 --ef-construction 256 --ef-search 256

  • 關鍵計量:

    指標

    數值

    Recall@100

    0.9676

    單線程-平均延遲

    3.4 ms

    單線程-p95延遲

    3.9 ms

    單線程-p99延遲

    4.4 ms

    構建索引耗時(optimize)

    1508.41 s

    峰值 QPS(concurrency=100)

    9130.94

  • 不同並發度下的效能表現如下:

    並發數

    QPS

    平均延遲(ms)

    P95 延遲(ms)

    P99 延遲(ms)

    20

    4597.60

    4.34

    5.84

    7.49

    40

    6539.36

    6.11

    9.70

    12.34

    60

    8438.65

    7.09

    13.17

    17.72

    80

    8996.89

    8.86

    17.42

    23.38

    100

    9130.94

    10.91

    21.08

    28.63

匯總對比

資料集

向量數量

向量維度

Recall@100

P99 延遲(ms)

峰值 QPS

索引構建耗時(s)

Cohere 768D 1M

1,000,000

768

0.9612

3.3

13060

76.80

Cohere 768D 10M

10,000,000

768

0.9551

4.2

10174

1625.95

OpenAI 1536D 5M

5,000,000

1536

0.9676

4.4

9131

1508.41

效能結論分析

  • 高召回率與低延遲兼得

    三組資料集的Recall@100 均超過0.95,單線程 P99 延遲控制在3.3 ~ 4.4 ms,在保證高召回的同時實現了毫秒級響應。

  • 極強的並發擴充性

    隨著並發數從20提升到100,QPS近乎線性增長。Cohere 768D 1M資料集在100並發下達到13060 QPS,P99延遲僅19.50 ms,展現出優異的吞吐擴充能力。

  • 高維大表下依然保持高吞吐

    OpenAI 1536D 5M資料集(1536 維、500 萬向量)在100並發下仍可達到9130 QPS,P99延遲 28.63 ms,說明PolarVector在高維大規模情境下具備穩定的檢索效能。

  • 索引構建效率高

    100萬向量索引構建僅需76.80 s;1000萬向量索引構建耗時1625.95 s(約 27 分鐘),構建速度滿足生產環境需求。

  • 工程友好性

    PolarVector基於列存索引唯讀節點自動同步並構建向量索引,無需額外部署獨立的向量資料庫,通過標準MySQL協議即可完成向量檢索,降低了營運和接入成本。