Repository navigation
[Data] Request each Parquet read task's estimated decode peak as its logical memory [6/6] - #67841
AarryaSaraf wants to merge 42 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to dynamically estimate the heap memory required by tasks consuming table blocks and request that memory instead of relying on static defaults. It adds consumer_memory_bytes to BlockMetadata, which is populated from Arrow schema metadata stamped by the bin packer. The TaskPoolMapOperator can now dynamically request this estimated memory, capped at a safe default. The review feedback suggests adding robust error handling when parsing the metadata integer to prevent potential ValueError or TypeError exceptions, and defensively validating that the estimated memory is non-negative to avoid task scheduling issues in Ray.
| schema_metadata = self._table.schema.metadata | ||
| if schema_metadata and CONSUMER_MEMORY_BYTES_METADATA_KEY in schema_metadata: | ||
| metadata = replace( | ||
| metadata, | ||
| consumer_memory_bytes=int( | ||
| schema_metadata[CONSUMER_MEMORY_BYTES_METADATA_KEY] | ||
| ), | ||
| ) |
There was a problem hiding this comment.
Parsing the consumer_memory_bytes metadata value directly with int() can raise a ValueError or TypeError if the metadata is malformed or corrupted. Since this is executed in a critical path, wrapping it in a try-except block ensures robustness by gracefully falling back to None if parsing fails.
| schema_metadata = self._table.schema.metadata | |
| if schema_metadata and CONSUMER_MEMORY_BYTES_METADATA_KEY in schema_metadata: | |
| metadata = replace( | |
| metadata, | |
| consumer_memory_bytes=int( | |
| schema_metadata[CONSUMER_MEMORY_BYTES_METADATA_KEY] | |
| ), | |
| ) | |
| schema_metadata = self._table.schema.metadata | |
| if schema_metadata and CONSUMER_MEMORY_BYTES_METADATA_KEY in schema_metadata: | |
| try: | |
| metadata = replace( | |
| metadata, | |
| consumer_memory_bytes=int( | |
| schema_metadata[CONSUMER_MEMORY_BYTES_METADATA_KEY] | |
| ), | |
| ) | |
| except (ValueError, TypeError): | |
| logger.warning( | |
| "Failed to parse consumer_memory_bytes from schema metadata: %r", | |
| schema_metadata[CONSUMER_MEMORY_BYTES_METADATA_KEY], | |
| ) |
There was a problem hiding this comment.
Only Ray writes this key, so a value that doesn't parse is a bug to surface rather than skip.
| for metadata in bundle.metadata: | ||
| if metadata.consumer_memory_bytes is None: | ||
| return None | ||
| total += metadata.consumer_memory_bytes |
There was a problem hiding this comment.
If consumer_memory_bytes is negative (e.g., due to corrupted metadata or an estimation bug), the total requested memory could become negative, which is invalid and can cause issues when scheduling tasks in Ray. Adding a defensive check to ensure the estimate is non-negative is highly recommended.
| for metadata in bundle.metadata: | |
| if metadata.consumer_memory_bytes is None: | |
| return None | |
| total += metadata.consumer_memory_bytes | |
| for metadata in bundle.metadata: | |
| if metadata.consumer_memory_bytes is None or metadata.consumer_memory_bytes < 0: | |
| return None | |
| total += metadata.consumer_memory_bytes |
There was a problem hiding this comment.
Every estimate is a sum of non-negative byte counts, so it can't go below zero.
d5c0db8 to
a97badd
Compare
a97badd to
c448349
Compare
c448349 to
7775228
Compare
7775228 to
6ab15d1
Compare
6ab15d1 to
6d6e936
Compare
6d6e936 to
d8d0b89
Compare
…logical memory Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Aarrya <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Aarrya <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Aarrya <[email protected]>
Signed-off-by: Aarrya <[email protected]>
d8d0b89 to
23cf682
Compare
Signed-off-by: Aarrya <[email protected]>
Signed-off-by: Aarrya <[email protected]>
…t group Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Aarrya <[email protected]>
Signed-off-by: Aarrya <[email protected]>
Signed-off-by: Aarrya <[email protected]>
Signed-off-by: Aarrya <[email protected]> # Conflicts: # python/ray/data/_internal/datasource_v2/common/online_bin_packer.py # python/ray/data/_internal/datasource_v2/interfaces/file_manifest.py # python/ray/data/block.py # python/ray/data/tests/unit/datasource_v2/test_online_bin_packer.py
Signed-off-by: Aarrya <[email protected]>
Signed-off-by: Aarrya <[email protected]>
…her than its packed bytes Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Aarrya <[email protected]>
Signed-off-by: Aarrya <[email protected]>
…s after it Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Aarrya <[email protected]>
Signed-off-by: Aarrya <[email protected]>
Co-Authored-By: Claude <[email protected]> Signed-off-by: Aarrya <[email protected]>
Co-Authored-By: Claude <[email protected]> Signed-off-by: Aarrya <[email protected]>
Co-Authored-By: Claude <[email protected]> Signed-off-by: Aarrya <[email protected]>
Co-Authored-By: Claude <[email protected]> Signed-off-by: Aarrya <[email protected]>
Signed-off-by: Aarrya <[email protected]>
Signed-off-by: Aarrya <[email protected]>
Signed-off-by: Aarrya <[email protected]>
Signed-off-by: Aarrya <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Aarrya <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Aarrya <[email protected]>
Signed-off-by: Aarrya <[email protected]>
Signed-off-by: Aarrya <[email protected]>
Signed-off-by: Aarrya <[email protected]> # Conflicts: # python/ray/data/_internal/datasource_v2/common/online_bin_packer.py # python/ray/data/_internal/execution/operators/map_operator.py # python/ray/data/_internal/execution/operators/task_pool_map_operator.py
Signed-off-by: Aarrya <[email protected]>
Signed-off-by: Aarrya <[email protected]>
Signed-off-by: Aarrya <[email protected]>
Signed-off-by: Aarrya <[email protected]>
Description
Stacked on #67840.
With #67840, a DSv2 Parquet read task holds row groups whose estimated decoded sizes sum to about the block target, 128 MiB by default, and each row group carries the memory PyArrow is estimated to peak at decoding it (
FileChunk.memory_bytes). The task still asks Ray for the memory it always did: nothing, or withDataContext.default_map_logical_memory_enableda flat 2.4 GiB per CPU (SAFE_DEFAULT_LOGICAL_MEMORY_PER_CPU), however small its bin. Now each read task requests its bin's summed estimate.How it works:
memory_bytes, as Arrow schema metadata underray.data.consumer_memory_bytes(online_bin_packer.py,FileManifest.construct_manifest).ArrowBlockAccessor.get_metadatareads the stamp into a new field,BlockMetadata.consumer_memory_bytes, so it travels with the listing block's metadata to the driver (BlockMetadataWithSchemacarries it).TaskPoolMapOperator, with the newmemory_from_input_estimateflag, sums the estimates over a bundle's blocks, caps the total at the safe default, and passes it as the task'smemoryin.options(...)(_get_dynamic_ray_remote_args).plan_read_files_opsets the flag on the read operator.flowchart TD FR["Footer reader"] -->|"each row group's memory_bytes"| BP["Bin packer"] BP -->|"one manifest per bin, stamped with the sum of its runs' memory_bytes"| LB["Listing block"] LB -->|"ArrowBlockAccessor.get_metadata reads the stamp"| MD["BlockMetadata.consumer_memory_bytes, to the driver"] MD -->|"summed over the bundle, capped at 2.4 GiB per CPU"| OP["TaskPoolMapOperator with memory_from_input_estimate"] OP -->|".options(memory=estimate)"| RT["Read task"] U["memory in ray_remote_args"] -->|"wins: the estimate is not used"| OPmemorythe caller set, as inread_parquet(..., ray_remote_args={"memory": ...}), wins, and the flag does nothing. The estimate applies whether or notdefault_map_logical_memory_enabledis set.num_cpus=1.operator_fusion.py). The estimate covers the read only, not the maps.PlacementGroupSchedulingStrategydoesn't request the estimate: the group's bundles may hold no memory, so the task would never schedule.incremental_resource_usage,per_task_resource_allocation) stay at the staticray_remote_args: the operator only sees a bundle as it schedules it. Ray Core enforces each task's request when it places the task, andcurrent_logical_usagecounts the running tasks' requests.Before and after, for #67840's bin of 41 row groups of 200,000 rows of an
int64and adouble, 127 MiB decoded and 400 MiB of summedmemory_bytes: before, its task was submitted with nomemory, or withmemory=2.4 GiBunder the default-memory flag; after, withmemory=400 MiB. On a node with 48 GiB of logical memory the flat default admits 20 such tasks at once and the estimate 122.Tests:
tests/unit/test_arrow_block.py: the stamp is read intoconsumer_memory_bytes.tests/unit/datasource_v2/test_online_bin_packer.py: every bin's stamp equals the sum of its runs'memory_bytes, across bin budgets and with coalesced runs split; a bin with a whole-file row or a run without an estimate has none.tests/test_task_pool_map_operator.py: the estimates sum over a bundle's blocks, cap at the safe default, give way to amemorythe caller set, replace the default-memory flag's value, and are skipped under a placement group.tests/test_operator_fusion.py: a read fused with a map keeps the flag.tests/datasource/test_read_parquet_v2.py: end to end, with a one-byte bin budget so every row group is its own task, each task'sget_assigned_resources()["memory"]is above 0 and below the safe default.97 passed in the two unit files on Python 3.10 with PyArrow 23.0.0 and 25.0.1 and on Python 3.12 with PyArrow 26.0.1. The other three files need a cluster and run in CI.
Signed-off-by: Aarrya [email protected]
🤖 Generated with Claude Code