Creating a repository version from a large base_version uses excessive memory (can OOM the worker)

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

Maintainer thường phản hồi trong vòng 1 ngày

@dkliban đang làm issue này rồi.

Từ ngày 24/11/2026.

  • #1721 của @dkliban — đang mở

Đánh giá

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

Hướng nghiên cứu

Start with RepositoryVersion.add_content in pulpcore/app/models/repository.py, where the RepositoryContent list is built and passed to bulk_create without a batch size, and check how new_version(base_version=...) calls it. Linked pull request #1721 is already open against this work, so read it and its discussion before starting. Done means the copy builds and inserts RepositoryContent in bounded chunks, so peak memory does not grow with the number of content units.

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

Mô tả

Issue Triage-Needed

Describe the bug

Creating a new RepositoryVersion from a base_version that contains a large number of content units (~2M) consumes several GB of RAM in a single task and can get the worker OOM-killed (observed as container exit code 137 against an 8 GiB limit).

Root cause

RepositoryVersion.new_version(base_version=…) resolves the copy into a single add_content() call with the entire base content set. In RepositoryVersion.add_content (pulpcore/app/models/repository.py):

  • all content pks are materialized into a Python set;
  • a Python list with one RepositoryContent instance per unit is built (~2M objects);
  • RepositoryContent.objects.bulk_create(repo_content) is called with no batch_size.

The per-instance list dominates (~1.5–3 GB for ~2M units at ~0.7–1.5 KB/instance), and the unbounded bulk_create adds a large transient on top (Django/psycopg build the full INSERT while the list is still alive). Peak scales linearly with repo size, so sufficiently large repositories cannot be copied on a memory-constrained worker.

To Reproduce

  1. Create a repository whose latest version holds ~1–2M content units (any plugin, e.g. pulp_file).
  2. Create a second repository and create a new version from the first via base_version (e.g. the modify/ endpoint with base_version, or new_version(base_version=…) directly).
  3. Watch worker RSS climb to multiple GB; on a memory-limited worker the task fails with the worker going missing (OOM kill).

Expected behavior

Copying a large base_version should complete with bounded memory, independent (or nearly so) of the number of content units.

Proposed fix

Chunk the RepositoryContent construction + insert in add_content() in explicit batches. Note that bulk_create(objs, batch_size=N) alone is not sufficient, because Django does list(objs) internally before chunking the SQL — the calls themselves must be chunked to bound Python-object memory. A fully DB-side INSERT … SELECT copy path for base_version would make memory independent of size but needs to handle pulp_id/timestamp generation server-side.

Ngôn ngữ chính
Python
Star
641
Fork
178
Merge trung bình
17 giờ 36 phút
Pull request đã merge (30 ngày)
76

Chuẩn bị môi trường

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.

Issue khác của pulp/pulpcore

Tất cả issue của pulp/pulpcore

Issue tương tự

Thêm issue về Python

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.