Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/7986.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Reduced the memory overhead of the Redis worker `waiting_tasks` metric by streaming reserved-resource records instead of loading full `Task` objects.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would mark this as a misc. It's not really a feature and we can backport if need be.

15 changes: 14 additions & 1 deletion pulpcore/tasking/redis_locks.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,20 @@ def extract_task_resources(task):
exclusive_resources: List of exclusive resource names
shared_resources: List of shared resource names (with "shared:" prefix stripped)
"""
reserved_resources_record = task.reserved_resources_record or []
return _split_reserved_resources(task.reserved_resources_record)


def _split_reserved_resources(reserved_resources_record):
"""
Split a `reserved_resources_record` array into (exclusive, shared) resource names.

Args:
reserved_resources_record (list[str] | None): Raw reservation strings, or None.

Returns:
tuple[list[str], list[str]]: (exclusive_resources, shared_resources).
"""
reserved_resources_record = reserved_resources_record or []

exclusive_resources = [
resource for resource in reserved_resources_record if not resource.startswith("shared:")
Expand Down
10 changes: 6 additions & 4 deletions pulpcore/tasking/redis_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
IMMEDIATE_OWNER_PREFIX,
LEGACY_OWNER_SCAN_INTERVAL,
LEGACY_OWNER_SCAN_KEY,
_split_reserved_resources,
acquire_locks,
cleanup_locks_for_owner,
collect_lock_owners,
Expand Down Expand Up @@ -110,21 +111,22 @@ def count_waiting_tasks_for_metric():
"""
cutoff_time = timezone.now() - timedelta(seconds=5)

incomplete_tasks = (
resources_iter = (
Task.objects.filter(
state__in=[TASK_STATES.RUNNING, TASK_STATES.WAITING],
pulp_created__lt=cutoff_time,
)
.order_by("pulp_created")
.only("reserved_resources_record")
.values_list("reserved_resources_record", flat=True)
.iterator()
)

taken_exclusive = set()
taken_shared = set()
parallel_count = 0

for task in incomplete_tasks:
exclusive_resources, shared_resources = extract_task_resources(task)
for reserved in resources_iter:
exclusive_resources, shared_resources = _split_reserved_resources(reserved)
conflicts = False

for resource in exclusive_resources:
Expand Down
Loading