Skip to content

app/: fingerprint new images 8 at a time off the runtime's threads; a finished render wakes only the builds waiting on it (incident 4 Dec 2026) - #171

Merged
ndbroadbent merged 1 commit into
mainfrom
app-fast-fingerprints
Dec 4, 2026
Merged

ndbroadbent merged 1 commit into
mainfrom
app-fast-fingerprints

Conversation

@ndbroadbent

@ndbroadbent ndbroadbent commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Incident fix: builds stuck in processing behind one slow builds.process run.

Incident 4 Dec 2026

What changed

  • domain::blobs::fingerprint_files / image_infos: new image files are downloaded VISUALCI_FINGERPRINT_CONCURRENCY at a time (default 8, a new "Build processing" config section), with buffer_unordered in the calling task. Nothing is spawned that touches the database, the cache or laravel::now(). Each file is decoded and fingerprinted in spawn_blocking, which receives only the bytes. The results are written back with one UPDATE blobs … FROM (VALUES …) per 5,000 rows, not one update! per blob. A fingerprint already on a row is kept; only a missing size is added. Each file that can't be read logs a warning. Its snapshots fail with the same message as before ("the image couldn't be read: : …").

  • fill_image_fingerprints uses this. image_info (compare's per-snapshot path) now goes through the same code, so its decode also runs off the runtime. With the runtime thread free, the processing lock's heartbeat keeps renewing during long fills.

  • renders::wake_waiting dispatches ProcessBuild only for:

    • processing builds with a snapshot drawn by the render (s.render_id);
    • the project's processing builds with a document of the same name and platform as a snapshot of the render's file. This is the redraw_base case: a base's PDF drawn again with the head's renderer settings.

    Head documents always have their render_id set before a build waits (queue_render), so no other build can be waiting on the render.

  • Per-phase timing log for each processing run: processed a build with fingerprints_ms, compare_ms, finish_ms, total_ms and snapshots.

Expected time for a 3,600-image build

The old path took about 110 ms per new image, in sequence (6m42s / 3,634). Eight downloads at a time, with decoding on the blocking pool, should bring the fingerprint phase to about 3,634 / 8 × 110 ms ≈ 50 s. The worker's cores and R2 latency set the real figure. Fingerprinting stays ahead of comparing because comparison matches on the fingerprints (exact baseline matches, known-by-hash files in later builds), so it can't be split into a step after comparison. The new timing line will show the real split on the next big build.

The 202 blobs with a NULL pixel_fingerprint (builds 625, 639, 642)

Only the server's own decode (image_info) ever sets pixel_fingerprint. These blobs are NULL by design:

  • PDF sources (they get pdf_fingerprint from the renderer);
  • text sources (their fingerprint is their SHA-256);
  • images whose decode failed (their snapshots are failed, which used to happen silently and is now logged).

A completed build runs every non-failed image snapshot through compare → snapshot_pages → image_info, which fills the blob, and a fill cut short is redone on the next run because the snapshot's source_fingerprint is still empty. So a NULL image blob in a completed build means its snapshot failed, or its group was sourced from another build. This query confirms which applies:

SELECT s.kind, s.state, count(DISTINCT b.sha256) FROM snapshots s JOIN blobs b ON b.sha256 = s.source_blob
WHERE s.build_id IN (SELECT id FROM builds WHERE project_id = 3 AND number IN (625, 639, 642)) -- or by id
  AND b.pixel_fingerprint IS NULL GROUP BY 1, 2;

A client-sent fingerprint is deliberately not copied to the shared blob row, because blobs are global across organizations.

Tests (app/tests/fingerprints.rs)

  • three_hundred_new_images_are_fingerprinted_while_requests_still_answer: 300 new images sent by hash. While the build processes inline, a GET /up every 20 ms answers in under 1 s. Every blob gets the right fingerprint, width and height, every snapshot is added with its fingerprint, and the whole test runs in under 30 s.
  • fingerprinting_downloads_no_more_files_at_once_than_its_concurrency: 40 slow fake downloads (100 ms each) at concurrency 8. At most 8 run at once, the run takes under 2 s, and the fingerprints are correct.
  • fingerprinting_decodes_off_the_runtime_thread: on a one-thread runtime, a ticker runs while 3000×3000 PNGs are decoded. It never stalls for even half of one decode.
  • a_finished_render_wakes_only_the_processing_builds_that_wait_on_it: counts the ProcessBuild jobs queued. They go to the build drawn by the render and the build waiting on a redraw of its file, and not to an unrelated processing build or a completed one.

Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…me's threads and written back in batches; a finished render wakes only the builds waiting on it (incident 4 Dec 2026)
@ndbroadbent
ndbroadbent force-pushed the app-fast-fingerprints branch from 39be2e0 to 21e4979 Compare December 4, 2026 05:42
@ndbroadbent
ndbroadbent merged commit cd4bf50 into main Dec 4, 2026
16 checks passed
@ndbroadbent
ndbroadbent deleted the app-fast-fingerprints branch December 4, 2026 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant