Repository navigation
Keep PDF CPU work off the worker event loop - #606
Merged
Merged
Conversation
Page-screen tiling and PNG encoding ran on the gevent hub and stalled every greenlet for 40-50 s on an 804-page PDF, starving lease renewal and the heartbeat. Tiling now runs in the PyMuPDF child process. - Skip the table search and drawing clustering in the asset probe once a page already has an asset; only has_asset reads that geometry. - Run PyMuPDF children at nice +10 so the event loop is scheduled first when the task's two CPUs are saturated. - Log event-loop stalls over 2 s with the blocking stack, keep the worst gevent delay between rate-limited pressure warnings, and report child CPU time. All observations are WARNING logs; no alerts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…has a side-effect' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Production v1.2.76 workers stalled the gevent loop for up to 20 s on large PDFs. The worst stall was page-screen tiling and PNG encoding on the hub thread. While it ran, every greenlet stopped: lease renewal (20 s), the heartbeat (45 s stale), and the other 9 tasks.
Observation stays in logs, at WARNING level, with no alerts:
worker.event_loop_blocked(newEventLoopMonitor)blocked_msand the blocking stackworker.runtime_pressuremax_gevent_delay_ms, the worst delay since the last rate-limited warningchild_cpu_msEvidence
Replayed locally on the original production PDFs, in a 2 vCPU / 4 GiB container with no network. Each scenario ran release code b0d6cab against this branch.
After: main-thread CPU 0.39–0.63 s, max gevent delay 0.23–0.37 s. VLM input sha256 identical across all runs.
worker.event_loop_blockedper stall (40,596 / 47,419 / 41,743 ms). The stack ended inPIL ImageFile._encode_tile → encoder.encode.After: 0 stall logs.
After: 107.4 / 135.2 / 139.5 s (−15 to −20 %). Per-page
has_assetresults are hash-identical.After: 0.97 of a core, children at niceness 10. A prod worker task reports
nproc=2with no CFS quota, so this matches production.Merge Danger
Door: two-way
No schema, queue, or message format changes. Reverting restores the previous behavior.
Blast Radius: worker
table_countis now 0 on pages that already have an image or table. It is serialized only and read by no decision.pymupdf_queue_wait_msshows a cross-worker imbalance.🤖 Generated with Claude Code