Skip to content

[core] Bound queued BLOB split batches by a shared byte budget - #1508

Open
XiaoHongbo-Hope wants to merge 19 commits into
apache:mainfrom
XiaoHongbo-Hope:codex/blob-output-byte-budget-20261123
Open

XiaoHongbo-Hope wants to merge 19 commits into
apache:mainfrom
XiaoHongbo-Hope:codex/blob-output-byte-budget-20261123

Conversation

@XiaoHongbo-Hope

@XiaoHongbo-Hope XiaoHongbo-Hope commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Bound queued BLOB split batches with a shared per-read byte budget. For known-size managed BLOBs, the default is 512 MiB per available core, capped at 4 GiB (1 GiB on 2 cores, 2 GiB on 4, 4 GiB on 8+); read.blob.output.max-buffered-bytes overrides it. The reservation counts only BLOB files used by the projected or filtered columns, so an unread BLOB column cannot serialize the read. Files without column metadata are charged conservatively.

An unknown-size split no longer disables budgeting for other known-size splits. Known BLOB bytes in a split are still reserved when that split also references an unknown-size file. The same known-byte reservation applies when the read also resolves a REST BLOB View. Pure unknown-size groups retain their existing concurrency unless the budget is explicitly configured. Ordered reads create each split stream only when admitted to an execution slot. Finite LIMIT and descriptor-only reads keep their existing paths.

The budget limits queued split output for each reader; it is not a bound on decoder memory, caller-retained batches, or several readers combined.

Performance evidence

A real image/BLOB workload from an isolated test copy read 100 complete groups per repetition (23.6k–29.3k rows and 6.17–7.42 GB of image bytes). All 24 reads verified every payload against a frozen SHA-256 reference. On one 8-vCPU/32-GiB ECS, the parent, the prior PR head at an explicit 4-GiB budget, and head 7db2e9a at its 4-GiB default ran in alternating order with split parallelism 32 and BLOB parallelism 16. Times are end to end per read (total_s: planning, payload read, Python materialization, and SHA-256; table open excluded).

Arm Fast cold, reps 0/1/2 Fast warm, reps 0/1/2 Slow warm Slow warm peak RSS
Parent 8.99 / 9.08 / 9.25 s 8.68 / 9.04 / 10.20 s 29.72 s 3,978 MiB
Prior head, explicit 4 GiB 8.68 / 8.67 / 9.65 s 8.44 / 8.11 / 8.71 s 31.09 s 3,336 MiB
Head 7db2e9a, default 4 GiB 8.53 / 9.41 / 9.35 s 8.69 / 8.11 / 9.09 s 29.39 s 3,690 MiB

The paired 7db2e9a/parent median ratio was 1.01 for cold reads and 0.90 for warm reads. The slow consumer paused 200 ms after each batch; its single warm run had 288 MiB less sampled process peak RSS than the parent. OSS/server caches and service load were not controlled, so these numbers do not establish a speedup. They show no large sustained regression on this workload. The benchmark used unordered BLOB materialization with one BLOB column, not ordered reading, a full training DataLoader, or a Lance comparison. The projection-aware change at 579eb726 is covered by a deterministic dual-BLOB-column concurrency test; it has not been separately benchmarked on ECS.

The internal benchmark archive contains the reproducible scripts, exact source and wheel SHA-256 values, frozen input, raw observations, and ECS release verification.

Current-head slow-consumer default validation

Release wheel built from 6006685 (the later b26fc71 changes test assertions only). On separate 2-, 4-, and 8-vCPU ECSs, the exact parent, the current default, and the same current wheel with an explicit 256-MiB budget each read the same 100 complete low-precision image clips in three paired repetitions. Each repetition materialized 6.17–7.42 GB of image payload, with 200 ms consumer delay per Arrow batch. All 54 cold/warm reads passed the frozen full-payload SHA-256 check. Split and BLOB parallelism were 32 and 16. The table gives medians of immediate warm reads; time includes planning, BLOB read, Python materialization, hashing, and consumer delay. Peak RSS is sampled process memory.

vCPU Parent: time / peak RSS Current default: budget, time / peak RSS Current 256 MiB: time / peak RSS
2 31.82 s / 4,857 MiB 1 GiB, 32.48 s / 3,340 MiB 71.02 s / 3,057 MiB
4 31.21 s / 4,777 MiB 2 GiB, 30.80 s / 3,400 MiB 67.36 s / 3,181 MiB
8 31.31 s / 4,589 MiB 4 GiB, 30.68 s / 3,993 MiB 68.12 s / 3,188 MiB

Paired warm-time default/parent median ratios were 1.016/1.000/1.007 on 2/4/8 vCPU. The defaults preserved throughput within run-to-run variation and reduced sampled peak RSS by 1,517/1,377/596 MiB versus the unbudgeted parent. The explicit 256-MiB limit reduced throughput by about 2.2× versus the defaults. These results support the chosen defaults for this workload, not global optimality. OSS/server cache and load were uncontrolled; this was an unordered, single-BLOB-column read with Python materialization, not a full training DataLoader or ordered-read benchmark. Raw observations, exact wheel/source and script SHA values, machine details, and ECS release verification are archived in paimon/xrobot branch codex/pr1508-blob-budget-benchmark, directory experiments/pr1508-blob-output-budget-20261124.

Validation

cargo fmt --all -- --check, 26 read-executor unit tests (including dual-BLOB-column single-column projection, known/unknown files in one split, mixed-size splits, and lazy-creation regressions), 32 table-read unit tests, 8 parallel-read integration tests, the REST BLOB View integration test, and git diff --check passed. The 7db2e9a wheel completed 24 correct benchmark reads and the ECS was released.

@JingsongLi JingsongLi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bounding queued BLOB payloads has end-to-end value for slow consumers. I ran the 7 parallel-read tests and 174 REST catalog tests on the merge with current main. The additional primary-key write, commit, plan and read probe below passes on main and reproduces a default-path concurrency regression on this PR.

}
}
if unknown || bytes == 0 {
budget.max_bytes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Preserve split concurrency for ordinary managed primary-key BLOBs

Every normal PK Parquet file has write_cols = None, and its managed BLOBs are referenced through the sidecar rather than listed as .blob entries in the split. This fallback therefore assigns every group the full budget, even for tiny native BLOBs. I wrote 5- and 6-byte values to two PK partitions, then delayed the first Parquet read using FileBlockCache. With parallelism=2 and the default budget, the second split opened independently on main. On this head it only started after the first was released. The existing parallel read setting becomes ineffective for this path, which can amplify object-storage latency across partitions. Keep split preparation concurrent and reserve bytes when the decoded descriptors expose their lengths, or make the serialized fallback opt-in until it has representative throughput coverage.

@XiaoHongbo-Hope
XiaoHongbo-Hope force-pushed the codex/blob-output-byte-budget-20261123 branch 2 times, most recently from 8424448 to dbb4f59 Compare November 24, 2026 06:01
Use a shared per-read budget for queued managed BLOB batches. Keep descriptor reads and unknown-size PK BLOB splits concurrent by default; make conservative reservation opt-in for unknown sizes. Avoid Parquet prefetch budget cycles and cover ordered and unordered reads.
@XiaoHongbo-Hope
XiaoHongbo-Hope force-pushed the codex/blob-output-byte-budget-20261123 branch from dbb4f59 to ed6d5dd Compare November 24, 2026 12:13
@XiaoHongbo-Hope
XiaoHongbo-Hope marked this pull request as draft November 25, 2026 05:06
@XiaoHongbo-Hope
XiaoHongbo-Hope marked this pull request as ready for review November 25, 2026 06:51

@JingsongLi JingsongLi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed b26fc715 against cd2b15af and verified these findings with end-to-end table reads.

yield batch;
}
// A paused caller keeps the permit and the current batch.
drop(_permit);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Keep the budget permit while the split retains decoded BLOBs

In unordered reads, this releases the permit and puts the open split back in the queue. The Data Evolution merge can yield a slice of a source batch and keep the remaining decoded BLOBs in source_cursors. The next split can then decode while the previous one still holds payloads that have yet to be returned.

I reproduced this on b26fc715 by writing, committing, planning, and reading three partitions. Each partition contained 1,024 one-byte values followed by a 1.5 MiB value, and each .blob file was smaller than 2 MiB. I read with split parallelism 3, read.batch-size=2048, and read.blob.output.max-buffered-bytes=2mb. After consuming the first batch from each split, Arrow buffer reference counts showed the reader still held all three unreturned 1.5 MiB values, 4.5 MiB in total. Two splits had already returned their permits.

Keep each reservation until the split releases the decoded output buffers it covers, or tie the reservation directly to those buffers.

.as_ref()
.is_none_or(|cols| cols.iter().any(|col| budget.fields.contains(col)))
{
unknown = true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Resolve the physical write columns before marking a split as unknown-size

With data-evolution.write-cols-optimization.enabled=true, the writer can omit write_cols on the Parquet file that stores the ordinary columns. This branch treats that file as an unknown-size BLOB source, so an explicit budget gives the split a full-budget reservation even when all of its BLOBs are in known-size .blob files.

I wrote and planned two partitions with two tiny BLOB values each, set read.blob.output.max-buffered-bytes=4mb, and read with split parallelism 2. Each .blob file was smaller than 1 MiB. A FileBlockCache gate held the first split's Parquet read until the second split opened. On cd2b15af, both splits opened and the read completed. On b26fc715, the second split never opened before the 2-second timeout. The same probe passed on the PR head with write-column optimization disabled.

Use the file schema's effective physical columns to decide whether the split has an unknown-size BLOB source. For this layout, TableSchema::data_file_fields(None) already reconstructs the omitted columns.

.iter()
.map(|split| blob_group_cost(std::slice::from_ref(split), budget))
.collect::<Vec<_>>();
if costs.iter().any(Option::is_some) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Keep a single ordered split on the caller's executor

This branch can enter merge_items_budgeted when the requested parallelism is greater than one and the plan contains just one known-size BLOB split. That sends the read through a Tokio JoinSet and bypasses the existing single-stream path.

I wrote and planned an in-memory Data Evolution table with one managed BLOB split and an explicit 4 MiB budget. I consumed the read with futures::executor::block_on outside Tokio, using with_ordered(true) and with_parallelism(8). The same read returned both rows on cd2b15af and failed on b26fc715 with Parallel table reads require a Tokio runtime. With with_ordered(false), the PR head returned both rows.

Require splits.len() > 1 before enabling the ordered budget scheduler so a single split keeps the existing executor behavior.

Resolve implicit file columns with their schema before reserving unknown BLOB bytes. Preserve the caller executor for a single ordered split.

@JingsongLi JingsongLi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shared budget has clear value for slow BLOB consumers. On ddfd3127 integrated with ebcff9f1, 191 table, REST and resource integration tests and 26 executor tests passed. A separate write/plan/read case exposed one projection that bypasses the budget.

Comment thread crates/paimon/src/table/table_read.rs Outdated
&& uses(&views));
let resolves_view =
self.table.rest_env().is_some() && options.blob_view_resolve_enabled() && uses(&views);
let resolves_blob = (!options.blob_as_descriptor() && uses(&blob_fields)) || resolves_view;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Apply the BLOB output budget to field-ID projections with aliases. I wrote two Data Evolution splits with one 1.5 MB managed BLOB each, set a 2 MiB budget, and held the first split's Parquet read. A projection named payload kept the second split waiting. The same DataField ID and BLOB type with the output name aliased_payload opened both splits concurrently and returned both payloads correctly. The reader resolves the aliased projection by field ID, while uses and the reservation fields only match the output name. Resolve projection fields back to their table field IDs before determining the BLOB read set.

@JingsongLi JingsongLi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reran the split executor, table-read, parallel-read, REST catalog, and scan-planning suites on f4206fe1. All 266 tests passed. A separate write/commit/plan/read test reproduced a scheduling regression with skewed BLOB sizes.

let permit = match *cost {
Some(cost) => {
let Ok(permit) = Arc::clone(permits).try_acquire_many_owned(cost) else {
break;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Let a smaller split use available budget in unordered reads. I wrote, committed, and planned three Data Evolution partitions with BLOB payloads of 2.5 MiB, 2.5 MiB, and 0.5 MiB, then read them with parallelism=3, ordered=false, and a 4 MiB budget. With the first partition’s Parquet read gated, requesting [large, large, small] returned no batch until I released that gate. On the same commit, [large, small, large] returned the small partition while the first was still gated. All payloads matched after both reads completed. The reservation for the first group consumes 3 MiB, so the small group fits in the remaining 1 MiB. Stopping at the second group leaves a worker and that budget idle behind a slow object read. Keep FIFO admission for ordered reads and let unordered reads admit a later group that fits while preserving progress for large groups.

@JingsongLi JingsongLi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed fe83adb6 integrated with 8105e1eb. All 5,383 core, parallel-read, REST, and scan-planning tests passed. Two additional write/commit/plan/read tests passed on 8105e1eb and exposed scheduling regressions on this head.

if let Some(budget) = &blob_output_budget {
let costs = groups
.iter()
.map(|group| blob_group_cost(group, budget))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Reserve bytes for the active split in current-schema unordered reads. I wrote four Data Evolution partitions in order with BLOBs of 2.5, 0.5, 0.5, and 2.5 MiB. With two workers, ordered=false, and a 4 MiB budget, the two groups each reserve 3 MiB. While I held the first group's Parquet read, the second group's first split produced no output, even though that split needs only 1 MiB and the remaining 1 MiB was available. The same split finished while the first read was held with a 6 MiB budget and on main. Keep the permit while the active split can retain decoded buffers, then admit the group's next split independently, as the historical-schema path does.

Comment thread crates/paimon/src/table/table_read.rs Outdated
let file_groups = if options.data_evolution_enabled()
&& !self.update_read
&& !budget.has_resources()
&& !output_budget_active

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Preserve independent-file parallelism in splits without BLOB payloads. I committed two Parquet files in partition A with the nullable BLOB omitted via with_write_type, and a single managed BLOB row in partition B. With three workers and the first A file gated, the second A file opened concurrently on main and on this head when I projected only p, id. When I also projected the BLOB on this head, the second A file waited for the first to finish. B's budget turns off independent file scheduling for A even though A has zero payload cost. Keep independent-file scheduling for those splits and preserve their output order, with BLOB reservations still sharing one budget.

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.

2 participants