MagicStack / MagicStack/asyncpg

Memory leak with Pool usage

Đang mở
#1,024 3 bình luận 4 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
Python
Star
8.1k
Fork
468
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

  • asyncpg version: 0.27
  • PostgreSQL version: 14
  • Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
    the issue with a local PostgreSQL install?
    : no
  • Python version: 3.8, 3.10 and 3.11
  • Platform: docker images python:3.x-slim-buster
  • Do you use pgbouncer?: no
  • Did you install asyncpg with pip?: yes
  • Can the issue be reproduced under both asyncio and
    uvloop?
    : only asyncio

When we use a Pool, the memory usage of our process keeps increasing slowly with the number of queries. After 1000 queries, it is ~10MB and this increases with the number of queries executed on connections acquired from the pool. This remains after the max_inactive_connection_lifetime has passed with no activity, with explicit garbage collection and even after we close the pool. We can reproduce this with a psutil measurement and observe it in production. When we replace the usage of Pool with our own creation/cleanup of asynpg Connections, the issue dissapears.

Pool created with the following arguments:

asyncpg.create_pool(
    max_inactive_connection_lifetime=300,
    command_timeout=30,
    min_size=0,
    max_size=5
)

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu tại điểm vào asyncpg.create_pool với các đối số pool được nêu và tái hiện mức tăng bộ nhớ dần dần bằng phép đo psutil đã mô tả. So sánh các kết nối trong pool với các kết nối asyncpg trực tiếp, bao gồm cả sau max_inactive_connection_lifetime, sau khi thực hiện thu gom rác rõ ràng và sau khi đóng pool. Hoàn tất khi bản tái hiện không còn cho thấy mức tăng liên quan đến số lượng truy vấn.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
postgresql, python
Lĩnh vực
databases
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.