pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
From: wahajali (@wahajali) <noreply+wahajali@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: [pgvector/pgvector] issue #700: HNSW QPS Degradation as Index Size Grows Beyond Memory
Date: Fri, 25 Oct 2024 19:39:47 +0000
Message-ID: <gh-pgvector-pgvector-700@github.com> (raw)

I'm trying to benchmark how HNSW performs as datasizes grows on a single DB instance, going beyond the available shared_buffers. To do this, I run multiple test with a modified version of [VectorDBBench](https://github.com/zilliztech/VectorDBBench) with datasize increasing in increments of 500K all the way to 5M. I'm using OpenAI 1536 embeddings for this test, with following configurations:
ef-search: 40
ef-construction: 128
m: 32

I am capturing the buffer hit ratio (for indexes only) computed using the following query after each test run:
```
SELECT
SUM(idx_blks_read) as idx_read,
SUM(idx_blks_hit) as idx_hit,
(SUM(idx_blks_hit) - SUM(idx_blks_read)) / SUM(idx_blks_hit) as ratio
FROM
pg_statio_user_indexes;
``` 

The key observation I have is that the QPS goes down drastically once the index size is > the shared_buffer size, while the decrease in buffer hit ratio is initially not that significant. Before running the test I prewarm the buffers. Sharing some numbers of running this on m6i.2xlarge (8 core, 32 GB memory, shared_buffers=16 GB) instance:

| Dataset Size   | Index Size | QPS        | Buffer Hit Ratio |
|----------------|------------|------------|-----------------|
| OpenAI 500K    | 4 GB       | 2250.8908  | 1               |
| OpenAI 1M      | 8 GB       | 2115.2407  | 1               |
| OpenAI 1.5M    | 11 GB      | 2147.19355 | 0.99995         |
| OpenAI 2M      | 15 GB      | 2110.7287  | 0.99995         |
| OpenAI 2.5M    | 19 GB      | 1225.2465  | 0.98895         |
| OpenAI 3M      | 23 GB      | 102.3127   | 0.9288          |
| OpenAI 3.5M    | 27 GB      | 279.39445  | 0.9718          |
| OpenAI 4M      | 31 GB      | 101.65025  | 0.8922          |
| OpenAI 4.5M    | 34 GB      | 67.86625   | 0.84395         |
| OpenAI 5M      | 38 GB      | 12.91095   | 0.5444          |

I would have expected the decrease in QPS to be gradual, or at best proportional to the decrease in hit ratio. Is it expected that the index always reside fully in memory for reasonable performance? 

**Edit:** What I've termed previously as "index hit ratio" should be more appropriately termed as "buffer hit ratio" - i.e the ratio of queries being served by buffer vs going to disk. I've updated it accordingly.

view thread (8+ messages)  latest in thread

Message-ID: <gh-pgvector-pgvector-700@github.com>
Permalink:  ../gh-pgvector-pgvector-700@github.com/

 · 


This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox