Skip to content

fix: prevent head-of-line blocking in RedisWorker fetch_task() - #7977

Closed
dkliban wants to merge 3 commits into
pulp:mainfrom
dkliban:fix/7900-fetch-task-hol-blocking
Closed

fix: prevent head-of-line blocking in RedisWorker fetch_task()#7977
dkliban wants to merge 3 commits into
pulp:mainfrom
dkliban:fix/7900-fetch-task-hol-blocking

Conversation

@dkliban

@dkliban dkliban commented Aug 16, 2026

Copy link
Copy Markdown
Member

Summary

Fixes head-of-line blocking in RedisWorker.fetch_task() when thousands of
tasks need the same blocked resource (#7900).

After acquire_locks reports a resource as blocked, tasks needing that resource
are excluded from subsequent DB queries using reserved_resources_record overlap,
leveraging the existing partial GIN index. Both raw and shared: prefixed
variants are excluded.

Tests

Two test files:

  1. Reproduction test (test_fetch_task_hol_blocking.py): 200 blocked tasks + 1 free task, asserts acquire_locks called <= 3 times. Fails on buggy code (6 calls), passes on fix (2 calls).

  2. Scale test (test_fetch_task_scale.py): 2000 tasks across 50 resources with DB query assertions:

    • Overlap operator present in captured SQL
    • auto_explain logs show Index Scan / Bitmap usage (not Seq Scan)
    • Query count <= 10
    • acquire_locks proportional to distinct resources

Fixes #7900

Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com

dkliban and others added 3 commits August 15, 2026 22:08
Track blocked resources across fetch_task() iterations and exclude them
at the DB level using reserved_resources_record__overlap, leveraging
the existing partial GIN index. This prevents workers from re-scanning
thousands of blocked tasks when free resources exist further in the queue.

Closes: pulp#7900

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RedisWorker fetch_task() head-of-line blocking: workers starved when queue head is serialized on one resource (WORKER_TYPE=redis)

1 participant