Skip to content

[python] Choose split read parallelism from planned splits - #1504

Draft
XiaoHongbo-Hope wants to merge 3 commits into
apache:mainfrom
XiaoHongbo-Hope:codex/python-read-auto-parallelism-20261123
Draft

XiaoHongbo-Hope wants to merge 3 commits into
apache:mainfrom
XiaoHongbo-Hope:codex/python-read-auto-parallelism-20261123

Conversation

@XiaoHongbo-Hope

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

Copy link
Copy Markdown
Contributor

Summary

For filtered reads without LIMIT, choose split parallelism from the planned split count: up to 64 for descriptor reads, or 32 for tables that may resolve BLOB payloads. Other reads keep the single-worker default; an explicit parallelism is unchanged.

The API still defaults to ordered=False. Parallel reads may return batches in a different order; callers needing split order can set ordered=True.

Evidence

In a Paimon-only, three-seed paired test on an 8-vCPU, 32-GiB ECS, we queried a BLOB table with one fixed content_key. Queries selected 100 or 1000 clips, used unordered reads and the default batch size; each cold run followed a local page-cache drop:

  • 1000-clip descriptors: 64→128 workers reduced median cold query time from 2.209 to 2.027 s, but raised peak RSS from 631 to 786 MiB.
  • 100-clip full BLOBs: 32→64 workers increased median cold query time from 3.296 to 3.773 s and peak RSS from 4.34 to 5.63 GiB. Native CRC was on; timing excludes measured Python SHA time.

The caps balance latency and memory on this host; callers can still tune parallelism. The BLOB default of 32 depends on the shared buffered-byte budget in #1508.

Validation

cargo fmt --all --check; cargo check -p pypaimon_rust --tests. Added unit checks for the caps and nested BLOB classification; order-sensitive Python tests now request ordered=True.

@XiaoHongbo-Hope
XiaoHongbo-Hope marked this pull request as ready for review November 23, 2026 08:07

@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.

All 222 Python read, streaming scan, and BLOB tests passed against a wheel built from this revision.

|| (self.table.rest_env().is_some()
&& options.blob_view_resolve_enabled()
&& !options.blob_view_fields().is_empty());
default_split_parallelism(

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] Bound buffered BLOB bytes before enabling automatic parallelism.

The first poll starts a read for each split worker, and each worker can retain a materialized batch. The BLOB range-read permits are released when the I/O finishes. I reproduced this with 32 splits and a 16 MiB payload batch per split. After consuming and releasing the first read_arrow() batch and pausing, RSS was about 621 MiB with the default and 113 MiB with parallelism=1 on the same wheel. Larger image or video batches can exhaust memory even when the caller processes one batch at a time. Please keep the BLOB default at one worker until a shared byte budget covers the batches waiting to be consumed.

/// Without an explicit parallelism, filtered reads without a limit use up
/// to 64 splits for descriptors or 32 for BLOB payloads. Other reads keep
/// the existing single-split default.
#[pyo3(signature = (splits, *, parallelism = None, ordered = false))]

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] Update the shipped type stubs for both methods.

read() and read_arrow() now accept parallelism=None. The corresponding signatures in bindings/python/python/pypaimon_rust/datafusion.pyi still declare parallelism: int = 1 for both. The wheel ships py.typed, so type checkers reject an explicit None and editors show the old default. Please declare parallelism: int | None = None in both stubs and document when automatic parallelism applies.

// Favor the payload cap whenever this table may resolve a BLOB.
// Projection and filters can introduce hidden BLOB operands, so a
// wider default is only safe for descriptor-only reads.
let has_blob = !options.blob_fields().is_empty()

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] Use the descriptor cap for unresolved BLOB views.

If a table's only BLOB column is a blob-view-field and blob-view.resolve.enabled=false, Core returns the stored references. blob_fields() still includes the view, and the schema check also counts it as a scalar BLOB. With the default blob-as-descriptor=false, a filtered read with more than 32 splits therefore gets the payload cap. Please exclude view fields from the ordinary BLOB checks and use the REST and resolution conditions for views, as Core does.

@XiaoHongbo-Hope
XiaoHongbo-Hope marked this pull request as draft November 23, 2026 09:04
@XiaoHongbo-Hope
XiaoHongbo-Hope marked this pull request as ready for review November 23, 2026 09:46
@XiaoHongbo-Hope
XiaoHongbo-Hope marked this pull request as draft November 23, 2026 13:52
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