Skip to content

[Data] Warn when configured memory is below 1.25x max USS - #65512

Merged
bveeramani merged 12 commits into
ray-project:masterfrom
viiccwen:data/high-memory-final-warning
Sep 24, 2026
Merged

bveeramani merged 12 commits into
ray-project:masterfrom
viiccwen:data/high-memory-final-warning

Conversation

@viiccwen

@viiccwen viiccwen commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Description

When a map operator completes or shuts down, the detector checks its observed maximum USS once. If logical memory was configured and is less than 125% of the maximum USS, the detector emits a warning with an exact memory=<bytes> recommendation.

The issue detector manager forces one final detection pass after successful or failed execution, bypassing the normal detection interval so short executions aren't missed. This final pass preserves issue indicators reported by earlier detections.

Related issues

Closes #65511.

Additional information

The 125% comparison uses integer arithmetic. The recommended memory is rounded up to the nearest whole byte.

Example warning

Operator 'Map(<lambda>)' used up to 8.0GiB of memory per worker. The configured logical memory was 1.0GiB. To avoid out-of-memory errors, set `memory=10737418240` (10.0GiB) in the appropriate function or method call.

@viiccwen
viiccwen requested a review from a team as a code owner August 16, 2026 08:53

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a mechanism to run issue detectors at the end of successful execution using final metrics, specifically implementing a high-memory detector that warns if an operator's memory usage exceeded its configured logical memory. The feedback suggests two improvements: first, saving and restoring hanging metrics in invoke_detectors_on_execution_end to prevent them from being wiped out by _report_issues; second, using getattr defensively when accessing op.metrics.max_uss_bytes to avoid potential AttributeErrors in mock or test environments.

@viiccwen

Copy link
Copy Markdown
Contributor Author

cc @bveeramani, PTAL. Thanks! 🙌

@ray-gardener ray-gardener Bot added data Ray Data-related issues community-contribution Contributed by the community labels Aug 16, 2026

@bveeramani bveeramani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Left some high-level thoughts.

Would you mind adding an example warning to the PR description?

Comment on lines +70 to +80
# Final detectors don't re-evaluate hanging issues, so preserve their state.
hanging_metrics = {
operator: operator.metrics._issue_detector_hanging
for operator in self.executor._topology
}
try:
self._report_issues(issues)
finally:
for operator, value in hanging_metrics.items():
operator.metrics._issue_detector_hanging = value

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What breaks if we remove this?

This code breaks abstractions barriers. We're adding code to the generic manager class that's specific to a particular issue detector implementation. In general, I think we should avoid this unless there's an extremely compelling reason

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If we remove this, the final invocation calls report_issues(...), which reset all issue metrics. Bcz the final detection only re-eval high-memory issues, it would clear hanging indicators emitted by earlier detections.

@viiccwen

Copy link
Copy Markdown
Contributor Author

Left some high-level thoughts.

Would you mind adding an example warning to the PR description?

Sure, added.

@bveeramani bveeramani self-assigned this Aug 19, 2026
Comment on lines +75 to +79
if reset_existing_indicators:
# Regular detection replaces the current issue indicators. A forced
# final pass preserves indicators reported by earlier detections.
operator.metrics._issue_detector_hanging = 0
operator.metrics._issue_detector_high_memory = 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What happens if we unconditionally do this like in the prior implementation (i.e., not expose reset_existing_indicators)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If we always reset, the final pass might remove an issue that was already detected but isn’t re-emitted. Since some detectors are stateful, preserving existing indicators avoids accidentally clearing valid issues.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't get it. Do you have a concrete example or sequence of events in mind?

IIUC the _issue_detector_high_memory and _issue_detector_hanging are just so we export how many new issues occurred between two ticks for dashboards. I don't think it actually affects the behavior of what Issue objects we return?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Actually, I did some digging. This whole _issue_detector_hanging/_issue_detector_high_memory thing seems like dead code.

Wanna open a PR to nuke it first from issue deteector, OpRuntimeMetrics, and stats, and then we can land this PR? Think it should simplify both the implementation and tests

assert map_operator.name in normalized_message
assert expected_memory_configuration in normalized_message
assert f"`memory={expected_memory}`" in normalized_message
assert detector.detect() == []

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What's the intent for this second assertion?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It verifies completion detection is one-shot, so repeated detector passes don't emit duplicate warnings or events. I've added comment to make that intent clear.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.


def _get_recommended_memory(memory_usage: Union[int, float]) -> int:
if isinstance(memory_usage, int):
return (5 * memory_usage + 3) // 4

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Where does + 3 come from? That seems pretty magic

Comment on lines +75 to +79
if reset_existing_indicators:
# Regular detection replaces the current issue indicators. A forced
# final pass preserves indicators reported by earlier detections.
operator.metrics._issue_detector_hanging = 0
operator.metrics._issue_detector_high_memory = 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't get it. Do you have a concrete example or sequence of events in mind?

IIUC the _issue_detector_high_memory and _issue_detector_hanging are just so we export how many new issues occurred between two ticks for dashboards. I don't think it actually affects the behavior of what Issue objects we return?

Comment on lines +75 to +79
if reset_existing_indicators:
# Regular detection replaces the current issue indicators. A forced
# final pass preserves indicators reported by earlier detections.
operator.metrics._issue_detector_hanging = 0
operator.metrics._issue_detector_high_memory = 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Actually, I did some digging. This whole _issue_detector_hanging/_issue_detector_high_memory thing seems like dead code.

Wanna open a PR to nuke it first from issue deteector, OpRuntimeMetrics, and stats, and then we can land this PR? Think it should simplify both the implementation and tests

Comment on lines +146 to +150
detector._issue_detectors = [issue_detector, hanging_detector]
detector._last_detection_times = {
issue_detector: float("inf"),
hanging_detector: float("inf"),
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This tests breaks abstraction barriers (modifies internal state of the IssueDetectorManager) and relies on heavy mocking.

I'm okay to land as-is for the sake of landing this incremental improvement, but let's clean up in a follow up PR

Comment on lines +146 to +155
memory_configuration = (
f"The configured logical memory was {memory_string(memory_request)}."
)
message = HIGH_MEMORY_FINAL_WARNING.format(
op_name=op.name,
max_memory=memory_string(max_uss_bytes),
memory_configuration=memory_configuration,
recommended_memory=memory_string(recommended_memory),
recommended_memory_bytes=recommended_memory,
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Any reason we pass a sentence for the memory configuration, but format the others?

Feel like it might be more consistent like this?

Suggested change
memory_configuration = (
f"The configured logical memory was {memory_string(memory_request)}."
)
message = HIGH_MEMORY_FINAL_WARNING.format(
op_name=op.name,
max_memory=memory_string(max_uss_bytes),
memory_configuration=memory_configuration,
recommended_memory=memory_string(recommended_memory),
recommended_memory_bytes=recommended_memory,
)
message = HIGH_MEMORY_FINAL_WARNING.format(
op_name=op.name,
max_memory=memory_string(max_uss_bytes),
memory_configuration=memory_string(memory_request),
recommended_memory=memory_string(recommended_memory),
recommended_memory_bytes=recommended_memory,
)

Comment on lines +167 to +170
def _get_recommended_memory(memory_usage: Union[int, float]) -> int:
if isinstance(memory_usage, int):
return (5 * memory_usage + 3) // 4
return math.ceil(5 * memory_usage / 4)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you add a comment describing where this 5 * usage / 4 comes from? I don't think it'll be obvious to future readers

Comment on lines +167 to +170
def _get_recommended_memory(memory_usage: Union[int, float]) -> int:
if isinstance(memory_usage, int):
return (5 * memory_usage + 3) // 4
return math.ceil(5 * memory_usage / 4)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you add a comment describing where this 5 * usage / 4 comes from? I don't think it'll be obvious to future readers

Comment on lines +168 to +170
if isinstance(memory_usage, int):
return (5 * memory_usage + 3) // 4
return math.ceil(5 * memory_usage / 4)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What happens if we don't special-case int and just simplify to one branch?

Suggested change
if isinstance(memory_usage, int):
return (5 * memory_usage + 3) // 4
return math.ceil(5 * memory_usage / 4)
return math.ceil(5 * memory_usage / 4)

Comment on lines +168 to +170
if isinstance(memory_usage, int):
return (5 * memory_usage + 3) // 4
return math.ceil(5 * memory_usage / 4)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What happens if we don't special-case int and just simplify to one branch?

Suggested change
if isinstance(memory_usage, int):
return (5 * memory_usage + 3) // 4
return math.ceil(5 * memory_usage / 4)
return math.ceil(5 * memory_usage / 4)

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

You can always ask for help on our discussion forum or Ray's public slack channel.

If you'd like to keep this open, just leave any comment, and the stale label will be removed.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Sep 9, 2026
Keep completion detection within the existing IssueDetector interface and force a final detector pass after successful or failed execution. Warn only when configured logical memory is below 125% of the observed maximum USS, while preserving existing issue indicators.

Signed-off-by: viiccwen <[email protected]>
@viiccwen
viiccwen force-pushed the data/high-memory-final-warning branch from f641860 to 938a343 Compare September 19, 2026 06:14

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 938a343. Configure here.

with pytest.raises(KeyboardInterrupt):
ray.data.range(1).take_all()

assert operators_shut_down

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cancel test never checks shutdown

Low Severity

assert operators_shut_down sits inside the pytest.raises(KeyboardInterrupt) block after take_all(), so the interrupt exits before the assert runs. Unlike the success and error callback tests, this never verifies that operators are already shut down when after_execution_fails runs.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 938a343. Configure here.

Run detector-specific final checks after successful, failed, or cancelled execution instead of forcing periodic detection. Preserve one-shot high-memory checks and ensure final issues are collected before usage reporting.

Signed-off-by: viiccwen <[email protected]>
@viiccwen
viiccwen force-pushed the data/high-memory-final-warning branch from 938a343 to 6600a78 Compare September 19, 2026 06:33
@github-actions github-actions Bot added unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it. and removed stale The issue is stale. It will be closed within 7 days unless there are further conversation labels Sep 19, 2026
@viiccwen

Copy link
Copy Markdown
Contributor Author

@bveeramani PTAL!

Remove the completed-operator branch from periodic detection. The
execution-end check already covers every map operator, and the extra
branch only produced an earlier warning when an interval tick happened
to land after an operator finished, at the cost of suppressing periodic
warnings for completed operators.

Rename the manager methods to invoke_periodic_detection and
invoke_final_detection, since the old names implied one was a superset
of the other. Use "per worker" consistently in both warnings and rewrap
the final warning template.

Signed-off-by: Balaji Veeramani <[email protected]>
Match the IssueDetector methods to the manager's
invoke_periodic_detection and invoke_final_detection so the periodic,
interval-gated check and the one-shot check at execution end read as
peers rather than one being a variant of the other.

Signed-off-by: Balaji Veeramani <[email protected]>
detect_final is called only from StreamingExecutor.shutdown, which
returns early on repeat calls and invokes exactly one of the success or
failure callbacks, so the per-operator guard set never suppressed a
warning.

Signed-off-by: Balaji Veeramani <[email protected]>
The periodic warning recommended 1.25x the mean of per-worker peak USS,
while the final warning recommended 1.25x the max. When both fired for
the same operator, users saw two different `memory=` values. Both now
recommend from the max, and the periodic warning reports the max
alongside the mean. The periodic trigger condition still uses the mean.

Signed-off-by: Balaji Veeramani <[email protected]>
@bveeramani
bveeramani enabled auto-merge (squash) September 24, 2026 00:37
@github-actions github-actions Bot added the go add ONLY when ready to merge, run all tests label Sep 24, 2026
@bveeramani
bveeramani merged commit 6dd8373 into ray-project:master Sep 24, 2026
7 of 8 checks passed
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…t#65512)

## Description

When a map operator completes or shuts down, the detector checks its
observed maximum USS once. If logical `memory` was configured and is
less than 125% of the maximum USS, the detector emits a warning with an
exact `memory=<bytes>` recommendation.

The issue detector manager forces one final detection pass after
successful or failed execution, bypassing the normal detection interval
so short executions aren't missed. This final pass preserves issue
indicators reported by earlier detections.

## Related issues

Closes ray-project#65511.

## Additional information

The 125% comparison uses integer arithmetic. The recommended memory is
rounded up to the nearest whole byte.

### Example warning

```text
Operator 'Map(<lambda>)' used up to 8.0GiB of memory per worker. The configured logical memory was 1.0GiB. To avoid out-of-memory errors, set `memory=10737418240` (10.0GiB) in the appropriate function or method call.
```

---------

Signed-off-by: viiccwen <[email protected]>
Signed-off-by: Balaji Veeramani <[email protected]>
Co-authored-by: Balaji Veeramani <[email protected]>
@viiccwen
viiccwen deleted the data/high-memory-final-warning branch October 12, 2026 02:09
chia7712 pushed a commit to opensource4you/readme that referenced this pull request Oct 23, 2026
Add a nomination under `fellowship/ray/`

Suggested level: 30k

Highlights from 2026-09-01 to 2026-10-11:

- [Contribution](https://github.com/opensource4you/readme/blob/main/fellowship/ray/fellow-contribution/viiccwen/September/report.md)
- Merged 10 Ray Data PRs and filed 8 issues in 6 weeks
- Made shuffle tasks up to 12.84x faster by pinning the fused map function, so large UDF closures are no longer serialized again for every shuffle task ([#65480](ray-project/ray#65480))
- Built a memory observability series to help users avoid OOM: exported task peak USS and logical memory metrics with Grafana charts ([#65666](ray-project/ray#65666), [#66044](ray-project/ray#66044)), added a warning with a suggested memory value when it is set below 1.25x max USS ([#65512](ray-project/ray#65512)), and updated the OOM prevention docs ([#65509](ray-project/ray#65509))
- Found, reported and fixed silent data loss in hash-shuffle (V2) anti joins, where rows were dropped when the other side was empty and had an unknown schema ([#66126](ray-project/ray#66126))
- Reviewed other fellows' PRs with suggestions ([#66878](ray-project/ray#66878))
- Merged the most PRs and filed the most issues of all Ray Fellowship participants
- Solid work for an early contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community data Ray Data-related issues go add ONLY when ready to merge, run all tests unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Data] Warn when configured memory is below 1.25x max USS

2 participants