Repository navigation
Packet job: read only the reusable forced rows, stage the window as it is measured - #670
Merged
Merged
Conversation
…t is measured Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.
What and why
Run 277 lost 1,231 packet jobs: 813 ran out of disk, 400 were killed at 5,120 MiB and 18 could not start on a full node. Both causes are in
rapidpipe/stages/packet.py, and this PR fixes both without any Batch change.reuse_rowsnow reads each field child offorcedfor the triggers' objects only (REUSE_SQL,aid = ANY … AND pid = ANY …, served by the child's existingaidindex) and builds the reuse dict one row at a time. A pair'sforced_idhashes its object, so no reusable row is lost. Thepacketsreads the manifest has always recorded (every official set with any row on the window's images) come from a second query,REUSE_SETS_SQL, which returns one row per set. The manifest'sreadsare therefore unchanged. No schema function is added; thepacket_reuse_rowsfunction stays in the schema, now unused by the stage._readdownloaded every window image before measuring anything, and_plainkept a decompressed copy of each until exit (about 191 MiB per image).WindowImage's file fields are now URLs.measure_forcedfetches an image's files in fetch threads while theLOOKAHEADimages before it are measured. It removes each staged file once the last image measured on it is done: a file several images share, such as a science PSF, is reference-counted by URL. The trigger's three cutout images are fetched by_readand kept. Afile://product is never removed, and an image whose pairs are all reused is never fetched. The fetch threads download without entering a step (stepsis single-threaded); the measuring thread's wait is charged tos3_read, ands3_read_bytesstill counts every download.LOOKAHEAD = 1, chosen from the measurement below.forced_id(sets that measured the same pair at the same time), the reuse read keeps the row last in the child's storage order (ORDER BY f.ctid). The copies differ only in their owntime_proc. The old whole-field read took whichever row its scan met last, and that varied from run to run (see Identity).No rapid_docs page states how the window is staged or what the reuse read scans, so no page needed correcting first. The module docstring carries the rule.
Files:
rapidpipe/stages/packet.py;tests/unit/test_packet.py(WindowImage takes URLs; two new tests);tests/db/test_field_children.py(the reuse read compared with the shipped read for every case, and the new contract test);tests/db/test_packet_inputs.py(the statement probe now looks for the children check instead ofpacket_reuse_rows).Contract tests:
test_the_reuse_read_returns_a_trigger_object_s_row_and_not_another_object_s(tests/db): one official set holds two rows on one image, one of the job's object and one of another object. The read returns the first, not the second, and records the set.test_a_window_image_s_files_leave_the_cache_once_it_is_measured(tests/unit, lookahead 0, 1 and 2): before each measurement, the images already measured have no files left in the download cache, except the trigger's cutout images and the PSF a later image still reads. After the call returns, and before the job's cleanup, only the cutout images remain.test_an_image_whose_pairs_are_all_reused_is_never_fetched.Measurements
These come from the replay harness, read-only against the deployed database through its
ro.pyguard. Each job is rebuilt from itsjobsrow and launch inputs and run through_readandwrite_set, as of the job's start (--asof started). The process is pinned to one CPU to match Batch's 1 vCPU, with its temp directory on/scratch. Peak RSS isgetrusage. Peak temp is a high-water byte count: the harness walks the temp directory before every unlink and at the end, and bytes there only fall at an unlink, so this is the true peak. The 3 s sampler's figure agrees with it on every run.Baseline: unchanged code at the parent 8a5395c;
rapidpipe/is unchanged from the replay ledger's ce36bb4.Lookahead on job 160585 (83 window images, 164,186 forced rows, 19,650 reused), one arm at a time:
The rule is the smallest lookahead whose wall time is within 5 % of the fastest arm's, with peak temp under 4 GiB. That is lookahead 1 (0.4 % slower than lookahead 2).
In-memory decompression (astropy reads each
.gzitself, no plain copy written) at lookahead 1: 619.9 s, 2.66 GiB, 0.532 GiB. It is slower, so it is not taken. Two dry reads overlapped its first two minutes, which may have slowed it a little.The nine jobs on the changed code. 158509 and 160585 ran alone at the PR head d9f7f17. The other seven ran after the merge of
rebuildat ba779cb, in parallel, each pinned to its own CPU.All nine are under 5,120 MiB and under the 4 GiB temp ceiling. Wall time: the control 391.5 → 306.8 s and 160585 910.4 → 581.2 s.
Both reuse queries ran under
EXPLAIN (ANALYZE, BUFFERS)throughro.pyon 160585's fields. On the large child, the rows query is an index scan onforced_862362_aid_idx(1,013 rows, under 1 ms); on the small one the planner chose a 0.7 ms seq scan. The sets query is a 37 ms scan of the large child, withofficial_open_product_jobserving the join. 160585's read took 7.8 s, against 212.4 s before (which included the downloads).Identity. Same cutoff, record by record. Equal inputs are shown by the same as-of passed to both reads; the same window (pid hash), triggers (sid hash), members (hash) and reused pair ids (hash); and reused counts 19,650 = 19,650.
reads: 930 identical in order.byte_offset/byte_length, which shift by single bytes because each record's deflated block holds the set's write time (timeProcessedMjd).reads: 1,062 identical in order.time_proc(3 records'prvDiaForcedSources[].timeProcessedMjd, and the index offsets that follow from them).forced_ids that up to a dozen official sets each hold, with identical values and each copy's owntime_proc. The unchanged code does not choose among them reproducibly: two old-code reads of 160585 on the same cutoff chose different copies for 66 pairs, and 25 and 41 against the baseline.compare.py --copies), 160585 is identical on every product.Raw evidence (harness, scripts, every result JSON and log, the comparison outputs and the EXPLAIN output):
s3://roman-rapid-scratch/rapidpipe/foundation/qa/packet-window-lean/. It is under no run's prefix because this card made no run.Divergences
time_procalone, and the unchanged code itself differs from run to run on that same field, on equal inputs, by more than the change does. So I judged the patch to cause no difference, and merged. Ben may read the rule differently. If so, the fix is one choice of rule (for example, the earliesttime_proc, the original measurement), not a revert.rebuild(which brought Alert diaSourceId packs the xsource's set job and xsid into one long (for the 2026-12-01 review) #665'sdiaSourceId). The seven ran after it.Improvements seen
packet_reuse_rowsindatabase/schema.sqlis now unused by the stage. Dropping it is a schema statement on SMDC, left for a schema PR.packetsreads still list every official set with a row on the window's images (91 for 160585), not only the sets whose rows are reused. Narrowing them would change the manifest contract, so this PR keeps them.forced_ids across sets come from packet jobs measuring the same pair at the same time. Each set then stores its own copy, which growsforcedand makes the reuse choice ambiguous.Session notes
/scratch(S3 Files) refusescopystatwith errno 524, soshutil.copytreefails there and the harness copies bytes only. Pytest underTMPDIRon EFS failstest_measured_with_a_set_falls*with.nfsbusy files; CI on local disk is green.Next and left
Run 277's failed packet jobs are the dataset owner's to rerun on an image holding this fix. No image is built here, and no job definition or Batch setting is touched.
🤖 Generated with Claude Code