register_vector leaks dumper classes on every call
還沒有人認領這個 Issue。
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 55/100
研究方向
Start with register_vector_info and the dumper classes in pgvector/psycopg/vector.py, then compare their registration with psycopg’s hstore.py example linked in the issue. Use the supplied reproduction with psycopg’s C extension to check class counts before and after repeated calls; done means the dumper classes are no longer retained after contexts are deleted.
由索引模型根據 Issue 內容生成。
描述
Hi!
Investigating a memory leak in our API, we found out that register_vector (and register_vector_async) creates 8 classes on every call that are never garbage collected if psycopg's C extension is in use, even after the connection is closed.
This is because these classes are stored by psycopg in a dict shared by the whole python process, and never cleared.
pgvector python 0.4.2 (but the code has not been updated on master) and psycopg 3.3.2
To reproduce:
import gc
from types import SimpleNamespace
import psycopg
from pgvector.psycopg.vector import (
VectorBinaryDumper,
VectorDumper,
register_vector_info,
)
from psycopg.adapt import AdaptersMap
from psycopg.types import TypeInfo
def count() -> int:
gc.collect()
return sum(
1
for base in (VectorDumper, VectorBinaryDumper)
for c in base.__subclasses__()
if c.__name__ == ""
)
print(psycopg.__version__, psycopg.pq.__impl__)
before = count()
for _ in range(1000):
ctx = SimpleNamespace(adapters=AdaptersMap(psycopg.adapters))
register_vector_info(ctx, TypeInfo("vector", 16385, 16386))
del ctx
print("leaked dumper classes:", count() - before) # expected 0, prints 2000
Caching these classes as done by psycopg could fix the issue : https://github.com/psycopg/psycopg/blob/99356800e90aa0e7b604f652d714ef0f33422b47/psycopg/psycopg/types/hstore.py#L225
- 主要語言
- Python
- 星號
- 1.5k
- 分支
- 100
- 平均合併
- 13 分鐘
- 30 天內合併 PR
- 1
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
pgvector/pgvector-python 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 72/100
pgvector/pgvector-python#169 ·
查看 pgvector/pgvector-python 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 74/100
zach-blumenfeld/aip#13 ·
-
難度 2/5 1-3 小時 新手友好度 80/100
nathanmarlor/foxess_modbus#1287 ·
維護者通常 4 天內回覆
-
bug good first issue help wanted
難度 2/5 1-3 小時 新手友好度 84/100
OpenLakeForge/openlakeforge#498 ·
維護者通常 1 天內回覆
-
good first issue hacktoberfest help wanted python
難度 2/5 1-3 小時 新手友好度 73/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 69/100
pollen-robotics/reachy_mini#1493 ·
維護者通常 1 天內回覆