Skip to content

perf: reduce lock contention#347

Merged
usamoi merged 1 commit into
supervc-stack:mainfrom
usamoi:less-lock
Sep 25, 2025
Merged

perf: reduce lock contention#347
usamoi merged 1 commit into
supervc-stack:mainfrom
usamoi:less-lock

Conversation

@usamoi

@usamoi usamoi commented Sep 19, 2025

Copy link
Copy Markdown
Contributor
create index on laion1m768_train using vchordrq (embedding vector_ip_ops) with (options = $$
build.pin = 2
build.internal.lists = [256, 4096]
build.internal.build_threads = 20
build.internal.spherical_centroids = true
degree_of_parallelism = 40
$$);

degree_of_parallelism is 32 by default. It reduces lock contention during insertion, especially, in a build where lists.len() != 1.

build.pin is -1 by default. build.pin = 2 caches almost everything in memory, which speeds build but spends more memory. build.pin = false and build.pin = true still works, and they're mapped to build.pin = -1 and build.pin = 1.

@VoVAllen

Copy link
Copy Markdown
Contributor

What is vector_tapes? It should be a hidden config named like _vector_tapes

@usamoi

usamoi commented Sep 19, 2025

Copy link
Copy Markdown
Contributor Author

What is vector_tapes? It should be a hidden config named like _vector_tapes

It's an experimental trick to speed parallel build, and won't be merged as-is.

@cutecutecat

cutecutecat commented Sep 19, 2025

Copy link
Copy Markdown
Contributor

With vector_tapes = 32 and 16 workers, the assignment of LAION-100M can be accerated from 3300s to 1800s.

storage worker assign time CPU util
1x3000G 32 1993.03s 60%
1x3000G 16 1848.54 s 54%
1x3000G 8 3104.53 s 42%

@usamoi usamoi force-pushed the less-lock branch 2 times, most recently from fd3da73 to dc53de2 Compare September 19, 2025 09:42
@usamoi usamoi changed the title feat: add vector_tapes to reduce lock contention feat: add degree_of_parallelism to reduce lock contention Sep 19, 2025
@usamoi

usamoi commented Sep 19, 2025

Copy link
Copy Markdown
Contributor Author

What is vector_tapes? It should be a hidden config named like _vector_tapes

It's renamed to degree_of_parallelism now. It's hint that the index takes advantage of it, creates multiple vector linked lists, and randomly chooses one to insert, in order to reduce lock contention.

Its default is 32 and users don't need change it except if they have a very very large machine.

@VoVAllen

Copy link
Copy Markdown
Contributor

Is there any downside to have degree_of_parallelism as 32? Shall we prefix it with _ ?

@usamoi

usamoi commented Sep 19, 2025

Copy link
Copy Markdown
Contributor Author

Is there any downside to have degree_of_parallelism as 32?

I don't think so.

Shall we prefix it with _ ?

I don't think it's necessary. rerank_in_table is much more bugful and we don't make it prefixed with _.

@usamoi

usamoi commented Sep 19, 2025

Copy link
Copy Markdown
Contributor Author

This feature modified the layout of storage, so it should be in 0.6.0. We could not pick it to 0.5.

@cutecutecat

cutecutecat commented Sep 22, 2025

Copy link
Copy Markdown
Contributor

To be noticed, the 8w build time is slower than before, from 2400s -> 3100s .

storage worker assign time CPU util
1x3000G 32 1993.03s 60%
1x3000G 16 1848.54 s 54%
1x3000G 8 3104.53 s 42%

@usamoi usamoi force-pushed the less-lock branch 3 times, most recently from 69c6415 to 8401732 Compare September 23, 2025 05:59
@usamoi usamoi changed the title feat: add degree_of_parallelism to reduce lock contention feat: add degree_of_parallelism and pin_level Sep 23, 2025
@usamoi usamoi force-pushed the less-lock branch 3 times, most recently from fcbbd9a to 7d7b0e5 Compare September 23, 2025 09:31
@usamoi usamoi changed the title feat: add degree_of_parallelism and pin_level feat: add degree_of_parallelism and more levels to pin Sep 23, 2025
@usamoi usamoi force-pushed the less-lock branch 2 times, most recently from 1aeae77 to b865fc4 Compare September 24, 2025 12:33
@usamoi usamoi changed the title feat: add degree_of_parallelism and more levels to pin feat: reduce lock contention Sep 24, 2025
@usamoi usamoi changed the title feat: reduce lock contention perf: reduce lock contention Sep 24, 2025
@usamoi usamoi marked this pull request as ready for review September 24, 2025 13:46
Signed-off-by: usamoi <usamoi@outlook.com>
@usamoi usamoi merged commit 1ec1fc7 into supervc-stack:main Sep 25, 2025
21 checks passed
@usamoi usamoi deleted the less-lock branch September 25, 2025 07:23
spenc-r pushed a commit to spenc-r/VectorChord that referenced this pull request May 22, 2026
```sql
create index on laion1m768_train using vchordrq (embedding vector_ip_ops) with (options = $$
build.pin = 2
build.internal.lists = [256, 4096]
build.internal.build_threads = 20
build.internal.spherical_centroids = true
degree_of_parallelism = 40
$$);
```

`degree_of_parallelism` is 32 by default. It reduces lock contention
during insertion, especially, in a build where `lists.len() != 1`.

`build.pin` is `-1` by default. `build.pin = 2` caches almost everything
in memory, which speeds build but spends more memory. `build.pin =
false` and `build.pin = true` still works, and they're mapped to
`build.pin = -1` and `build.pin = 1`.

Signed-off-by: usamoi <usamoi@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants