register_vector leaks dumper classes on every call
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 55/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Python
- Star
- 1.5k
- Fork
- 100
- Merge trung bình
- 13 phút
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của pgvector/pgvector-python
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
pgvector/pgvector-python#169 ·
Tất cả issue của pgvector/pgvector-python
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
Maintainer thường phản hồi trong vòng 1 ngày
-
ChaosEngine: backup-remote doctor row passes while consumer mode hides bot memory from gitCó thể đã có người làm @MohabMohie đã nhận hôm nay. Đang mởagentic
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
ShaftHQ/SHAFT_ENGINE#7263 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 87/100
huggingface/smolagents#3045 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày