Repository navigation
test(bench): add a cleanup benchmark - #10511
Merged
Merged
Conversation
Measure cleanup on two shapes: many unreferenced files and many versions. A wrapping object store counts delete requests and paths so the same benchmark can compare per-file deletes with bulk deletes. Dataset sizes are configurable through CLEANUP_BENCH_* environment variables.
lichuang
force-pushed
the
bench-cleanup
branch
from
October 30, 2026 08:00
6ee967a to
87bde35
Compare
Build the local dataset URI with the same path normalization used by the cleanup tests so a Windows drive letter cannot become the URL authority. State that delete_requests counts wrapped-store delete_stream calls rather than cloud HTTP requests. Reject malformed or out-of-range CLEANUP_BENCH_* values instead of silently falling back to defaults or resizing the requested workload. Assert the first iteration's expected removals and counter consistency so the benchmark cannot silently measure a no-op cleanup.
Xuanwo
approved these changes
Nov 5, 2026
Xuanwo
left a comment
Member
There was a problem hiding this comment.
Reviewed the final head: a local Criterion benchmark for cleanup's orphan-file and expired-version delete paths. Fixture teardown stays outside the measured region; the wrapper reports delete_stream calls and paths, not cloud HTTP requests; the local URI construction keeps Windows drive letters out of the URL authority; malformed and out-of-range CLEANUP_BENCH_* values fail with the variable name and bound.
Validation on this head: root cargo fmt --all and full ci-profile Clippy including benches; both workload shapes pass with expected removals, failed_deletes=0, and retained latest data; invalid-input smokes fail as intended. Production cleanup code and dependencies are unchanged.
Xuanwo
added a commit
that referenced
this pull request
Nov 14, 2026
## Summary Cleanup issued one object-store delete per unreferenced file. S3's `DeleteObjects` accepts up to 1000 keys per request, so a large cleanup sweep paid one request per file even when the provider could coalesce them. This adds a bulk-delete path to cleanup. Manifests and small batches keep single-object deletes, so a failed manifest delete still keeps its commit-handler record and per-path outcomes stay exact. ## What changed - Add `ObjectStore::delete_stream`, delegating to the underlying object store's bulk delete. It keeps the local-staging behavior `ObjectStore::delete` already owned: hidden staging names (ending in `#<digits>`) are unlinked through the local filesystem, because the local backend rejects those names, and the delete is recorded the same way. A store that can hold staging files has no bulk request to coalesce into, so it dispatches one delete per path; remote stores pass the batch through. - Delete non-manifest cleanup candidates in 1000-path sub-batches. - Keep manifests on single-object deletes. A failed manifest delete must keep its commit-handler record so `forget_version` is not called ahead of the manifest removal. - Keep batches below 100 paths on single-object deletes. This preserves exact per-path outcomes. - Bound in-flight delete operations with the existing delete semaphore, so `delete_concurrency` covers both manifest deletes and bulk requests. One operation is one manifest delete or one bulk request; a backend may coalesce or fan out the paths inside a request. - Map bulk results back to candidates by path: - `NotFound` counts as removed; - a candidate with no reported outcome counts as `failed_deletes`, including when a failed request ends the stream early or a response omits the path; - a failed bulk request does not abort the sweep. - Keep `delete_rate_limit` as a per-path budget. Bulk requests may carry several paths, so the HTTP request rate can be lower than the configured path rate. - Update the cleanup rate-limit and concurrency documentation accordingly. ## Measurement The counter in the benchmark added by #10511 is `delete_stream` calls observed by a wrapper installed in front of the store. On the local `file-object-store` runs of `cleanup/orphans/2000` and `cleanup/versions/200` recorded while developing this change, it moved from one call per path to one call per sub-batch (2000 → 2 and 597 → 200), while wall-clock moved within noise: a local filesystem charges nothing per request, and cleanup time is dominated by listing, manifest reads and classification. Those counts are Lance-level store calls against a local wrapper. They are not S3 HTTP requests and not filesystem syscalls, and they were recorded before the staging-path repair above: a local store now dispatches one delete per path, so this counter no longer drops for local runs. A separate estimate charged a synthetic 1 ms per request; that was a model, not measured cloud performance, and is not a result of this change. This change makes no claim about provider-side latency or request rates. The reduction applies to backends whose `delete_stream` coalesces into one request and should be measured against one; no benchmark is added here. ## Tests - `cargo test --profile ci --locked -p lance-io --lib` — 688 passed - `cargo test --profile ci --locked -p lance --lib -- dataset::cleanup::tests` — 261 passed - `cargo fmt --all -- --check` - `cargo clippy --profile ci --locked --all --tests --benches -- -D warnings` New coverage crosses the bulk threshold with hidden staging files, drives a coalescing store through success, already gone, rejected and unreported keys, and asserts one bulk request is one semaphore unit and one rate permit per path. ## Notes for reviewers - `ObjectStore::delete_stream` is additive; no existing API changes. - Cleanup semantics for manifests, `failed_deletes`, `NotFound`, rate limits, and commit-handler records are preserved. - `ObjectStore::remove_stream` is unchanged: it predates this change and no cleanup path sends staging names through it. --------- Co-authored-by: Xuanwo <[email protected]>
Xuanwo
added a commit
that referenced
this pull request
Dec 2, 2026
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 the `data/` and `_transactions/` listings both await their first response at the same time. With serial listing, the same test fails at the overlap assertion. <details> <summary>Original implementation and measurements before #11596 landed</summary> ## Summary Cleanup listed its managed directories through a serial `flatten()`, so a large `data/` 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 stream directly from `read_dir_all` instead of wrapping every listed object in its own boxed 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-boxing looked ~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: - De-boxing removes about one allocation per listed object, but `flatten_unordered` re-inserts its next-item future into its scheduler after every emitted item, adding roughly the same number back. Over 700k items the allocation count is **700,007 both before and after**. - Measured on its own, de-boxing while keeping the serial merge is 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 15s - local `file-object-store` - `CLEANUP_BENCH_ORPHANS=2000`, `CLEANUP_BENCH_VERSIONS=200` - medians of 3 interleaved rounds | 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% | 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 delay inside the timed region only (setup stays unthrottled). With 1000 µs, roughly a same-region object store: | Variant | orphans/2000 | versions/200 | | --- | ---: | ---: | | before (serial `flatten`) | 27.40 ms | 21.63 ms | | de-boxed, still serial | 26.35 ms | 21.71 ms | | **this PR** | **14.70 ms** | **8.64 ms** | | | −46% | −60% | 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 - Which files cleanup selects and deletes. - The listing cutoffs, including the `_versions`/`_indices` rules that scan without a retained-manifest cutoff. - Delete request counts: 2000 requests for 2000 paths in the orphan scenario 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 - New `rust/lance/src/dataset/cleanup/tests/listing.rs`: a store wrapper holds each 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: - Dropped the comment describing the removed per-object boxing, and moved the history of the previous `flatten()` into the commit message. - Corrected the concurrency note: `read_dir_all` is a single paginated LIST, so the merge is at most one in-flight LIST per subtree — not something bounded by the store's own listing concurrency. `None` is used instead of restating `streams.len()`. - Added the concurrency regression test and the modeled LIST latency to the benchmark. ## Notes - No file-format or API changes. - `flatten_unordered` costs roughly 83–108 ns per item in scheduler overhead when 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 #11167 --event com.github.pull_request.review.submitted.v1,com.github.pull_request.state.changed.v1 - It prints the first event as a JSON line on stdout and exits; run it again to wait for the next one. - Add `--timeout` to stop waiting after a while, for example `--timeout 30m`; it then exits with status 8. - Events carry no details; read the pull request to see what changed. - It misses changes made before it starts, so read the pull request once it is running. - See `gh event listen --help` for other event types. - Event subscriptions are in preview and may not be enabled for your account. </details> Co-authored-by: Xuanwo <[email protected]>
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
Cleanup had no benchmark for its delete path, so changes such as switching from per-file deletes to bulk deletes could not be compared directly. This adds a Criterion benchmark for two cleanup shapes and reports wrapped-store delete counts next to the measured time.
What it adds
rust/lance/benches/cleanup.rswith two benchmarks:cleanup/orphans/N: one retained version plus N recent, unreferenced data files. Cleanup deletes the orphan files.cleanup/versions/V: V versions written withWriteMode::Overwrite, one data file each. Cleanup deletes every version except the latest.rust/lance/Cargo.toml: registers the benchmark withharness = false.Each iteration creates a fresh dataset and runs only the cleanup call inside the measured region (
iter_batchedsetup and fixture teardown are excluded).The benchmark wraps the object store and counts
delete_streamcalls and input paths. Inobject_store0.14 a single-objectdeleteis an extension method that delegates todelete_streamwith one path, so a per-file implementation reportsdelete_requests == delete_paths, while a bulk implementation can be recognized by fewer calls for the same paths.delete_requestscounts wrapped-storedelete_streamcalls, not physical cloud HTTP requests: provider retries, request splitting, and network latency are not measured. The first iteration asserts the expected removals,failed_deletes == 0, and that the wrapped-store path count matches the reported removals.Example output from a local run with
CLEANUP_BENCH_ORPHANS=8 CLEANUP_BENCH_VERSIONS=4:The version scenario sets
delete_unverified = truebecause the benchmark has no concurrent writers. That lets it measure data-file deletion in addition to manifest deletion; otherwise recent data files from expired versions are retained.The local dataset URI uses the same path normalization as the cleanup tests, keeping a Windows drive letter in the path instead of treating it as the URL authority. Windows runtime was not executed; CI covers compilation only.
Running
cargo bench -p lance --bench cleanupCLEANUP_BENCH_ORPHANS: number of orphan files (default: 2000, minimum: 1)CLEANUP_BENCH_VERSIONS: number of versions (default: 200, minimum: 2)CLEANUP_BENCH_SAMPLE_SIZE: Criterion sample size (default: 10, minimum: 10)CLEANUP_BENCH_SKIP_ORPHANS: set to 1/true/yes to skip the orphan scenarioCLEANUP_BENCH_SKIP_VERSIONS: set to 1/true/yes to skip the version scenarioMalformed or out-of-range values fail with a descriptive error instead of silently changing the requested workload.
Validation
cargo fmt --allcargo clippy --profile ci --all --tests --benches -- -D warningsThe benchmark uses a local
file-object-storeonly; it does not measure cloud HTTP requests, retries, or network latency.