pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
[pgvector/pgvector] issue #738: Workers assigned for IVFFlat bottlenecked at 8
4+ messages / 2 participants
[nested] [flat]

* [pgvector/pgvector] issue #738: Workers assigned for IVFFlat bottlenecked at 8
@ 2024-12-24 22:53 "huafen17 (@huafen17)" <noreply+huafen17@github.com>
  0 siblings, 0 replies; 4+ messages in thread

From: huafen17 (@huafen17) @ 2024-12-24 22:53 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

I'm trying to set max_parallel_workers to values like 15, 31 to observe IVFFlat's indexing speed regarding to this factor. I notice on the dbhost side, the peak CPU utilization during indexing stayed at the level where 8 CPUs are in use. Did I miss out on any other parameters? I checked max_worker_processes already, that's 64 for my runs, so it won't limit max_parallel_maintenance_workers.

Code snippet, there's ~16MM records in my test dataset, so I set lists to 4000 as recommended:
```
table_name = sql.Identifier("test")
num_workers = sql.Identifier("31")
max_num_workers = sql.Identifier("64")
dbconn = establish_conn() # some customized function to create the connection
with dbconn.cursor() as cur:
    cur.execute("SET maintenance_work_mem = '16GB';")
    cur.execute(sql.SQL("SET max_parallel_workers = {};").format(max_num_workers))
    cur.execute(sql.SQL("SET max_parallel_maintenance_workers = {};").format(num_workers)) 
    cur.execute(sql.SQL("""CREATE INDEX ON {} USING ivfflat (embedding vector_cosine_ops) WITH (lists = 4000);""").format(table_name))   
```


^ permalink  raw  [nested|flat] 4+ messages in thread

* Re: [pgvector/pgvector] issue #738: Workers assigned for IVFFlat bottlenecked at 8
@ 2024-12-26 15:19 ` "ankane (@ankane)" <noreply+ankane@github.com>
  2 siblings, 0 replies; 4+ messages in thread

From: ankane (@ankane) @ 2024-12-26 15:19 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hi @huafen17, those settings determine the max number of workers. IVFFlat uses the [default worker calculation](https://github.com/postgres/postgres/blob/REL_17_2/src/backend/optimizer/path/allpaths.c#L4234-L4250) in Postgres, which uses an exponential scale. There's [a branch](https://github.com/pgvector/pgvector/compare/ivfflat-parallel-workers) to change it to match HNSW, but from what I've seen, more workers may not significantly improve build time (so I think the current method is better right now, but happy to see more data).

You can set the exact value with:

```sql
ALTER TABLE test SET (parallel_workers = 31);
CREATE INDEX ...
ALTER TABLE test RESET (parallel_workers);
```

However, this can affect other operations, not just the index build, so I probably wouldn't recommend it outside of testing.

^ permalink  raw  [nested|flat] 4+ messages in thread

* Re: [pgvector/pgvector] issue #738: Workers assigned for IVFFlat bottlenecked at 8
@ 2024-12-26 15:19 ` "ankane (@ankane)" <noreply+ankane@github.com>
  2 siblings, 0 replies; 4+ messages in thread

From: ankane (@ankane) @ 2024-12-26 15:19 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@ankane closed this.

^ permalink  raw  [nested|flat] 4+ messages in thread

* Re: [pgvector/pgvector] issue #738: Workers assigned for IVFFlat bottlenecked at 8
@ 2025-01-06 21:37 ` "huafen17 (@huafen17)" <noreply+huafen17@github.com>
  2 siblings, 0 replies; 4+ messages in thread

From: huafen17 (@huafen17) @ 2025-01-06 21:37 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Thanks, this setting does allow me to use more CPUs during some part of the index building (I think it was either assigning or loading tuple, but they were a really small part of the index building). A good chunk of the time for IVFFlat was spent on performing k-means from my observation, and during that time the CPU util remain the same for different number of workers. So you are right, this doesn't improve build time much.

^ permalink  raw  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2025-01-06 21:37 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-12-24 22:53 [pgvector/pgvector] issue #738: Workers assigned for IVFFlat bottlenecked at 8 "huafen17 (@huafen17)" <noreply+huafen17@github.com>
2024-12-26 15:19 ` "ankane (@ankane)" <noreply+ankane@github.com>
2024-12-26 15:19 ` "ankane (@ankane)" <noreply+ankane@github.com>
2025-01-06 21:37 ` "huafen17 (@huafen17)" <noreply+huafen17@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