本文展示了 PolarDB PostgreSQL 版集群向量索引在特定软硬件配置下,基于 HNSW 与 RaBitQ 8-bit 量化技术处理亿级千维向量(约 1.135 亿条、1024 维)的写入与查询性能。内容涵盖测试环境、数据集、关键配置参数、测试方法及性能结果分析,为技术选型、容量规划和性能调优提供数据参考。
测试结果
吞吐优先:Recall@10 为 94.48% 时,100 并发下达到 25,325.6 QPS,P99 延迟为 8.09 ms。
召回率达到 95% 以上:Recall@10 为 95.35% 时,100 并发下达到 18,291.5 QPS,P99 延迟为 11.26 ms。
本文结果基于所述测试环境与参数,实际性能随数据分布、缓存状态、查询条件和并发负载变化。
测试环境
项目 | 配置 |
数据库版本 | PostgreSQL 16.14(PolarDB 2.0.16.14.21.0) |
向量扩展 | PolarDB PostgreSQL 版 |
读写节点规格 | 64 核、512 GB |
测试客户端 | ECS |
测试工具 | VectorDBBench, |
网络 | 客户端与数据库位于同一可用区 |
数据集
项目 | 配置 |
数据集 | |
数据量 | 113,520,750 条向量 |
向量维度与存储精度 | 1024 维,数据库中以 FP32 存储 |
距离度量 | 内积,使用 |
查询集 | 1,677 条查询向量 |
TopK | 10 |
准备工作
本次测试依赖以下资源与环境条件:
存储容量:全量数据写入与索引构建完成后,表与索引合计约 1,012 GiB,其中向量索引 145.8 GiB、堆表 866.1 GiB。
向量扩展:PolarDB PostgreSQL 版
vector扩展,本次测试版本为 0.8.3.1。测试客户端:ECS
ecs.g9i.12xlarge,48 vCPU、192 GiB,与数据库位于同一可用区。压测工具:VectorDBBench 与
polardbpghnsw驱动,导入模块经并发改造。
测试方法
以下 SQL 语句与压测命令为本次测试的实际配置,用于说明测试口径与参数取值。
表结构与数据写入
CREATE TABLE vdbbench_table_test (
id bigint,
embedding vector(1024)
);VectorDBBench 原生导入对非线程安全的客户端会退化为单线程,1.135 亿条无法在可接受时间内导完。改造导入路径后,48 个 worker 各持一条独立连接、各读自己的 parquet 分片并行写入。
向量索引配置
CREATE INDEX pgvector_index ON public.vdbbench_table_test
USING hnsw (embedding vector_ip_ops)
WITH (m = 16, ef_construction = 256,
quantization = rabitq, quantization_nbits = 8);构建会话参数:maintenance_work_mem = 120GB、max_parallel_maintenance_workers = 64。
查询性能测试
检索参数
参数 | 取值 |
| 200、300、450、600 四档 |
| off |
| off(默认) |
| 10 |
压测命令
第一条命令测试串行检索延迟:
export DATASET_LOCAL_DIR=/data/dataset/ vectordbbench polardbpghnsw \ --case-type PerformanceCustomDataset \ --custom-case-name msmarco1024d113m \ --custom-dataset-name msmarco --custom-dataset-dir msmarco_v21_vector_bench \ --custom-dataset-size 113520750 --custom-dataset-dim 1024 \ --custom-dataset-file-count 60 --custom-dataset-metric-type IP \ --skip-custom-dataset-use-shuffled --custom-dataset-with-gt \ --k 10 --m 16 --ef-construction 256 \ --quantization rabitq --quantization-nbits 8 \ --skip-graph-cache --iterative-scan off \ --maintenance-work-mem 120GB --max-parallel-workers 64 \ --user-name <user> --password <password> \ --host <host> --port 5432 --db-name vec \ --db-label msmarco-ef300 --ef-search 300 \ --skip-drop-old --skip-load --search-serial --skip-search-concurrent第二条命令测试并发吞吐。
--search-serial与--search-concurrent为互斥开关,需将第一条命令中的--search-serial --skip-search-concurrent替换为--skip-search-serial --search-concurrent,并指定并发档位与各档位的持续时间:vectordbbench polardbpghnsw \ --case-type PerformanceCustomDataset \ --custom-case-name msmarco1024d113m \ --custom-dataset-name msmarco --custom-dataset-dir msmarco_v21_vector_bench \ --custom-dataset-size 113520750 --custom-dataset-dim 1024 \ --custom-dataset-file-count 60 --custom-dataset-metric-type IP \ --skip-custom-dataset-use-shuffled --custom-dataset-with-gt \ --k 10 --m 16 --ef-construction 256 \ --quantization rabitq --quantization-nbits 8 \ --skip-graph-cache --iterative-scan off \ --maintenance-work-mem 120GB --max-parallel-workers 64 \ --user-name <user> --password <password> \ --host <host> --port 5432 --db-name vec \ --db-label msmarco-conc-ef300 --ef-search 300 \ --skip-drop-old --skip-load --skip-search-serial --search-concurrent \ --num-concurrency 20,40,60,80,100,128,156,200 --concurrency-duration 60
性能测试结果
指标说明
指标 | 含义 |
Recall@10 | 返回结果前 10 条与官方 Ground Truth (GT) 前 10 条的重合率。结果表中以小数表示,正文叙述中以百分比表示 |
QPS | 并发检索每秒完成的查询数 |
平均延迟 | 查询延迟的平均值,单位为 ms |
P95 延迟 / P99 延迟 | 延迟分位数,单位为 ms |
写入、索引构建与存储
以下写入耗时与吞吐为导入路径并发改造后的实测值。
指标 | 结果 |
全量数据写入耗时 | 6,319.90 秒,约 1 小时 45 分钟 |
平均写入吞吐 | 17,962 行/秒 |
索引构建耗时 | 约 2 小时 33 分钟 |
向量索引大小 | 145.8 GiB |
堆表大小 | 866.1 GiB |
表与索引合计 | 约 1,012 GiB |
查询性能
下表摘录了 1、20、60、80、100、156 六个并发档位的实测结果,压测命令中声明的 40、128、200 三档未列入。
| 并发数 | Recall@10 | QPS | 平均延迟 (ms) | P95 延迟 (ms) | P99 延迟 (ms) |
200 | 1 | 0.9448 | 535.4 | 1.87 | 2.54 | 3.00 |
200 | 20 | 0.9448 | 10,079.6 | 1.98 | 2.80 | 3.37 |
200 | 60 | 0.9448 | 23,354.5 | 2.55 | 3.64 | 4.44 |
200 | 80 | 0.9448 | 25,084.7 | 3.16 | 5.17 | 6.35 |
200 | 100 | 0.9448 | 25,325.6 | 3.91 | 6.30 | 8.09 |
200 | 156 | 0.9448 | 24,828.5 | 6.19 | 12.84 | 22.74 |
300 | 1 | 0.9535 | 407.1 | 2.46 | 3.34 | 3.82 |
300 | 20 | 0.9535 | 7,643.6 | 2.61 | 3.71 | 4.36 |
300 | 60 | 0.9535 | 17,270.9 | 3.46 | 4.95 | 5.93 |
300 | 80 | 0.9535 | 18,264.2 | 4.35 | 7.29 | 8.85 |
300 | 100 | 0.9535 | 18,291.5 | 5.43 | 8.77 | 11.26 |
300 | 156 | 0.9535 | 17,856.3 | 8.64 | 17.95 | 28.72 |
450 | 1 | 0.9606 | 298.6 | 3.36 | 4.64 | 5.36 |
450 | 20 | 0.9606 | 5,546.2 | 3.60 | 5.15 | 6.06 |
450 | 60 | 0.9606 | 12,549.7 | 4.76 | 6.90 | 8.29 |
450 | 80 | 0.9606 | 12,891.9 | 6.18 | 10.58 | 12.89 |
450 | 100 | 0.9606 | 12,851.9 | 7.74 | 12.68 | 16.57 |
450 | 156 | 0.9606 | 12,462.5 | 12.32 | 25.89 | 43.80 |
600 | 1 | 0.9654 | 237.8 | 4.22 | 5.91 | 6.79 |
600 | 20 | 0.9654 | 4,206.7 | 4.75 | 6.89 | 8.05 |
600 | 60 | 0.9654 | 9,235.0 | 6.48 | 9.52 | 11.34 |
600 | 80 | 0.9654 | 9,721.0 | 8.20 | 14.39 | 17.74 |
600 | 100 | 0.9654 | 9,548.7 | 10.42 | 17.24 | 22.44 |
600 | 156 | 0.9654 | 9,236.7 | 16.63 | 37.88 | 51.20 |
结果分析与选型建议
ef_search=300 是本次测试中召回率跨过 95% 后仍保持万级吞吐的档位:Recall@10 为 95.35%,80 并发下吞吐约为 1.83 万 QPS,P99 延迟为 8.85 ms。同为 80 并发,ef_search 从 200 提高至 600,Recall@10 从 94.48% 提升至 96.54%,吞吐从约 2.51 万降至 0.97 万 QPS,P99 延迟从 6.35 ms 升至 17.74 ms,应根据业务召回目标选择档位。四档 ef_search 在 80 并发下的对照如下:
| Recall@10 | QPS | P99 延迟 (ms) |
200 | 0.9448 | 25,084.7 | 6.35 |
300 | 0.9535 | 18,264.2 | 8.85 |
450 | 0.9606 | 12,891.9 | 12.89 |
600 | 0.9654 | 9,721.0 | 17.74 |
并发配置建议:
ef_search=300时,并发从 80 增至 100,吞吐提升不足 0.2%,P99 延迟升至 11.26 ms。以召回率达到 95% 为目标时,可从ef_search=300、80 并发开始评估。吞吐随并发的变化形态:四档
ef_search的吞吐均在 80~100 并发附近见顶,156 并发时回落。以ef_search=200为例,QPS 由 100 并发的 25,325.6 降至 156 并发的 24,828.5。