Reduce memory usage during collection deletion#2492
Conversation
|
This will need to be backported for 0.25 (AAP 2.4/2.5/2.6) and 0.28 (AAP upstream/2.7) please. |
gerrod3
left a comment
There was a problem hiding this comment.
set_collection_deferred_fields is a blunt instrument used to work around having to change multiple spots in our collection sync code (some of them being in pulpcore!) and as such we shouldn't overuse when trying to optimize pulp-ansible. For this case we can easily fix the issues by being smarter with the querysets we write.
Backport to 0.21: 💔 cherry-picking failed — conflicts found❌ Failed to cleanly apply fca4331 on top of patchback/backports/0.21/fca4331513d9d85b0580873555a48efbbc7c2d57/pr-2492 Backporting merged PR #2492 into main
🤖 @patchback |
Backport to 0.22: 💔 cherry-picking failed — conflicts found❌ Failed to cleanly apply fca4331 on top of patchback/backports/0.22/fca4331513d9d85b0580873555a48efbbc7c2d57/pr-2492 Backporting merged PR #2492 into main
🤖 @patchback |
Backport to 0.24: 💔 cherry-picking failed — conflicts found❌ Failed to cleanly apply fca4331 on top of patchback/backports/0.24/fca4331513d9d85b0580873555a48efbbc7c2d57/pr-2492 Backporting merged PR #2492 into main
🤖 @patchback |
Backport to 0.29: 💔 cherry-picking failed — conflicts found❌ Failed to cleanly apply fca4331 on top of patchback/backports/0.29/fca4331513d9d85b0580873555a48efbbc7c2d57/pr-2492 Backporting merged PR #2492 into main
🤖 @patchback |
Backport to 0.25: 💔 cherry-picking failed — conflicts found❌ Failed to cleanly apply fca4331 on top of patchback/backports/0.25/fca4331513d9d85b0580873555a48efbbc7c2d57/pr-2492 Backporting merged PR #2492 into main
🤖 @patchback |
Backport to 0.28: 💔 cherry-picking failed — conflicts found❌ Failed to cleanly apply fca4331 on top of patchback/backports/0.28/fca4331513d9d85b0580873555a48efbbc7c2d57/pr-2492 Backporting merged PR #2492 into main
🤖 @patchback |
Made-with: Cursor
Made-with: Cursor
Made-with: Cursor
Made-with: Cursor
Made-with: Cursor
Made-with: Cursor
Made-with: Cursor
Reduce memory usage during collection deletion
Problem
Deleting collections with many versions causes worker processes to consume excessive memory and get killed with SIGKILL. This occurs because Django loads all fields (including large JSON fields) for each CollectionVersion into memory. When multiplied across many versions, this causes the worker process to be terminated.
Solution
This PR applies targeted QuerySet field selection using
.only()to load only the fields needed for deletion operations, avoiding the large JSON fields that aren't required.Changes:
pulp_ansible/app/galaxy/v3/views.py:.only("pk")when iterating collection versions and their repositories inCollectionViewSet.destroy()AnsibleRepositorylookup withfilter(pk__in=...)to prevent N+1 queries.only("namespace", "name", "version")when loading collection dependentspulp_ansible/app/tasks/deletion.py:.only("pk")when loading collection versions and iterating their repositories indelete_collection()taskBy loading only the required fields, we avoid pulling large JSON blobs (
docs_blob,metadata,dependencies, etc.) into memory when they're not needed for the deletion operation.Related Work