Repository navigation
test(cleanup): verify managed subtree listings overlap - #11167
Conversation
There was a problem hiding this comment.
The author accepts the per-candidate allocation and CPU scheduling overhead to retain overlapping subtree listings. That performance trade-off remains non-blocking; no further change is requested for this finding.
wjones127
left a comment
There was a problem hiding this comment.
Thanks, this is a nice small change. Listing the managed subtrees concurrently makes sense, and the NotFound handling and the outer ordering (unreferenced files, then staging files, then manifests) are unchanged. Nothing here blocks.
Non-blocking: a question about whether the benchmark shows a real win given run-to-run noise, plus two comment nits.
question: How noisy is this benchmark run to run? In your reply table, serial flatten after de-boxing comes in at 103.9–105.7 ms vs 94.4 ms on main for orphans, and 32.7–33.9 ms vs 31.3 ms for versions. Removing an allocation per object shouldn't make things ~10% slower, so I suspect the variance between runs is about as big as the 8% improvement. Also, per the gatekeeper's probe, flatten_unordered adds back about one allocation per item, so the de-boxing win mostly cancels out.
The concurrency should really pay off on object stores, where each LIST page has real latency. Could we measure that directly, for example by running main and this branch interleaved, or by using a local store with injected list latency? I'm fine merging either way since this is easy to revisit. I'd just like the PR description to make a claim the numbers support.
| // `flatten()` consumed one directory stream at a time, so a large | ||
| // `data/` directory delayed listing of `_indices/`, `_deletions/`, | ||
| // etc. Each stream is already bounded by the object store's own | ||
| // listing concurrency. |
There was a problem hiding this comment.
nitpick: "Each stream is already bounded by the object store's own listing concurrency" isn't quite right. read_dir_all is a single paginated list(), so each subtree is one sequential LIST, and total concurrency is just the number of subtrees. Also, the history ("The previous flatten()...") fits better in the commit message. Since all the streams are already in hand, None gives the same behavior as Some(streams.len()). Maybe:
// List the managed subtrees concurrently so a large `data/` listing
// doesn't delay `_indices/`, `_deletions/`, etc. Each subtree is a
// single paginated LIST, so this is at most one in-flight LIST per subtree.
let unreferenced_files = stream::iter(streams).flatten_unordered(None).boxed();|
|
||
| // Build stream for a managed subtree | ||
| // Build stream for a managed subtree. Keep the object metadata stream | ||
| // unboxed: the previous per-object `stream::once(...).boxed()` created |
There was a problem hiding this comment.
nitpick: This describes code that no longer exists, which won't mean much to a future reader. I'd drop it and keep just // Build stream for a managed subtree.. The NotFound comment below already explains the part that isn't obvious.
There was a problem hiding this comment.
Thanks — the benchmark question was fair, and it changed the conclusion I should have drawn from my own numbers. The description is updated.
The old numbers came from my MacBook Pro, which is not a controlled environment: desktop session, uneven thermal throttling, varying background load. Its run-to-run spread was on the order of the effect I was claiming, which is very likely why serial flatten() after de-boxing looked ~10% slower than before — impossible from removing an allocation.
I re-ran everything on a relatively clean Linux box (32 cores, 59 GB, no desktop session, nothing else running), with the variants interleaved so drift and page-cache state hit all of them equally. Medians of 3 rounds, release-with-debug, 20 samples, 5s warm-up / 15s measurement, 2000 orphans / 200 versions.
The absolute times are much lower than the old table because the machine is faster, not because the code changed. The two tables are not comparable; only within-machine differences mean anything.
You were right about the de-boxing
| Variant | orphans/2000 | versions/200 |
|---|---|---|
before (serial flatten) |
17.15 ms | 12.65 ms |
| de-boxed, still serial | 17.20 ms | 12.66 ms |
| this PR | 10.77 ms | 5.60 ms |
| −37% | −56% |
De-boxing saves ~one allocation per listed object, but flatten_unordered re-inserts its next-item future after every item and adds them back — over 700k items it is 700,007 both before and after, exactly the cancellation you predicted. On its own it moves nothing. I keep it as a simplification, not for speed; the description no longer credits it with the win.
Measuring the case this change is for
You're right that local file-object-store has no LIST round trip. I added CLEANUP_BENCH_LIST_LATENCY_MICROS, which charges each LIST a fixed delay inside the timed region only (setup stays unthrottled). At 1000 µs:
| Variant | orphans/2000 | versions/200 |
|---|---|---|
before (serial flatten) |
27.40 ms | 21.63 ms |
| this PR | 14.70 ms | 8.64 ms |
| −46% | −60% |
A modeled delay, not a real remote store: it shows the shape of the win, not its size on S3. Delete request counts are unchanged (2000/2000 and 597/597).
Cleanup listed each managed directory through a serial `flatten()` over directory streams. A large `data/` directory therefore delayed listing of `_indices/`, `_deletions/`, and the other independent subtrees. The listing path also wrapped every object metadata item in a boxed `stream::once(...)` and immediately flattened it, allocating one boxed stream per listed object. Build directory streams directly from `read_dir_all` with `filter_map` and `try_filter_map`, treating a missing managed directory as an empty subtree. Then consume the independent directory streams with `flatten_unordered` so they are listed concurrently. Benchmark with `release-with-debug`, 20 samples, 2000 orphans and 200 versions: - `cleanup/orphans/2000`: 94.398 ms -> 95.837 ms (+1.5%, p=0.91, no change) - `cleanup/versions/200`: 31.339 ms -> 28.817 ms (-8.0%, p<0.05) Delete request counts are unchanged: 2000 for the orphan scenario and 597 for the version scenario. The version scenario benefits because cleanup scans multiple managed subtrees; the orphan scenario is dominated by the 2000 deletes. `cargo test -p lance cleanup::tests`: 231 passed.
dd3f2d0 to
891cc9b
Compare
Merge main to use the cleanup implementation and benchmark from lance-format#11596. Keep the overlap regression from lance-format#11167, observing only the data and transaction listings in the sweep. Co-authored-by: codedump <[email protected]>
The concurrent listing implementation and latency benchmark landed in #11596. This PR retains the regression test from the original contribution. It calls
cleanup().explain()and checks that thedata/and_transactions/listings both await their first response at the same time. With serial listing, the same test fails at the overlap assertion.Original implementation and measurements before #11596 landed
Summary
Cleanup listed its managed directories through a serial
flatten(), so a largedata/listing delayed_indices/,_deletions/,_blobs/,_transactions/,_versions/, and_fri/even though they are independent.Each subtree is a single paginated LIST, so those round trips were paid one
after another.
This PR overlaps them with
flatten_unordered, and builds each subtree streamdirectly from
read_dir_allinstead of wrapping every listed object in its ownboxed stream.
About the numbers in the previous revision
The earlier description was measured on my MacBook Pro. That machine is not a
controlled environment — desktop session, uneven thermal throttling, varying
background load — and its run-to-run spread was on the order of the effect
being claimed. That is very likely why serial
flatten()after de-boxinglooked ~10% slower than before, which should be impossible from removing an
allocation.
Everything below has been re-measured on a clean Linux machine (32 cores,
59 GB, no desktop session, nothing else running) with the variants interleaved
so drift and page-cache state hit all of them equally. The absolute times are
much lower here because the machine is faster, not because the code changed.
Only differences within a single machine are meaningful, so the old and new
tables are not comparable with each other and should not be mixed.
Corrected claim about allocations
The previous description credited the per-object de-boxing with a speed-up.
That does not hold up, and the review was right to question it:
flatten_unorderedre-inserts its next-item future into its scheduler afterevery emitted item, adding roughly the same number back. Over 700k items the
allocation count is 700,007 both before and after.
indistinguishable from the previous code.
The de-boxing is kept because it is a simplification that disappears in the
noise, not because it pays. The gain in this PR is entirely from overlapping
the listings.
Benchmark
Same harness as #10511, one machine, variants interleaved (A/B/C adjacent).
release-with-debug, sample size 20, warm-up 5s, measurement 15sfile-object-storeCLEANUP_BENCH_ORPHANS=2000,CLEANUP_BENCH_VERSIONS=200flatten)The de-boxed row is the point the review raised: removing the per-object stream
buys nothing measurable on its own, so the entire change is the concurrency.
Modeling object-store listing latency
A local filesystem has no LIST round trip, so the local numbers understate what
this change is for. The benchmark now accepts
CLEANUP_BENCH_LIST_LATENCY_MICROS, which charges every LIST a fixed delayinside the timed region only (setup stays unthrottled). With 1000 µs, roughly a
same-region object store:
flatten)This is still a modeled delay, not a real remote store. It shows the shape of
the win rather than its absolute size on S3 or GCS.
What is unchanged
_versions/_indicesrules that scanwithout a retained-manifest cutoff.
and 597 for 597 paths in the version scenario, before and after.
The outer composition (unreferenced files, then local staging files, then
manifests) is also unchanged.
Tests
rust/lance/src/dataset/cleanup/tests/listing.rs: a store wrapper holdseach listing open and records the peak number of in-flight listings. The test
asserts more than one managed subtree is in flight at a time, and fails on a
serial merge. It asserts overlap, not duration, so it does not depend on
machine speed.
cargo test -p lance --lib dataset::cleanup: 311 passed.cargo clippy -p lance --all-targets -- -D warnings: clean.cargo fmt --all: clean.The full workspace test suite was not run; the change is confined to cleanup
listing and the cleanup benchmark.
Review follow-ups in this revision
These three are folded into the PR and do not change performance — the numbers
above already describe the original commit:
history of the previous
flatten()into the commit message.read_dir_allis a single paginated LIST, sothe merge is at most one in-flight LIST per subtree — not something bounded
by the store's own listing concurrency.
Noneis used instead of restatingstreams.len().benchmark.
Notes
flatten_unorderedcosts roughly 83–108 ns per item in scheduler overheadwhen measured with no I/O. At cleanup's real scale (~600 files in the version
scenario, 2000 in the orphan scenario) that is not observable end to end, but
a zero-allocation merge is a reasonable later optimisation if it ever is. It
was measured at parity here, so it is not part of this PR.
hint: if you need to wait for this pull request to be reviewed, merged, or closed before continuing, use this instead of polling:
gh event listen --resource test(cleanup): verify managed subtree listings overlap #11167 --event com.github.pull_request.review.submitted.v1,com.github.pull_request.state.changed.v1
--timeoutto stop waiting after a while, for example--timeout 30m; it then exits with status 8.gh event listen --helpfor other event types.