Repository navigation
[Data] Warn when configured memory is below 1.25x max USS - #65512
Conversation
There was a problem hiding this comment.
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.
|
cc @bveeramani, PTAL. Thanks! 🙌 |
bveeramani
left a comment
There was a problem hiding this comment.
Left some high-level thoughts.
Would you mind adding an example warning to the PR description?
| # 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 | ||
|
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Sure, added. |
| 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 |
There was a problem hiding this comment.
What happens if we unconditionally do this like in the prior implementation (i.e., not expose reset_existing_indicators)?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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() == [] |
There was a problem hiding this comment.
What's the intent for this second assertion?
There was a problem hiding this comment.
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.
|
|
||
| def _get_recommended_memory(memory_usage: Union[int, float]) -> int: | ||
| if isinstance(memory_usage, int): | ||
| return (5 * memory_usage + 3) // 4 |
There was a problem hiding this comment.
Where does + 3 come from? That seems pretty magic
| 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 |
There was a problem hiding this comment.
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?
| 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 |
There was a problem hiding this comment.
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
| detector._issue_detectors = [issue_detector, hanging_detector] | ||
| detector._last_detection_times = { | ||
| issue_detector: float("inf"), | ||
| hanging_detector: float("inf"), | ||
| } |
There was a problem hiding this comment.
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
| 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, | ||
| ) |
There was a problem hiding this comment.
Any reason we pass a sentence for the memory configuration, but format the others?
Feel like it might be more consistent like this?
| 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, | |
| ) |
| 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) |
There was a problem hiding this comment.
Could you add a comment describing where this 5 * usage / 4 comes from? I don't think it'll be obvious to future readers
| 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) |
There was a problem hiding this comment.
Could you add a comment describing where this 5 * usage / 4 comes from? I don't think it'll be obvious to future readers
| if isinstance(memory_usage, int): | ||
| return (5 * memory_usage + 3) // 4 | ||
| return math.ceil(5 * memory_usage / 4) |
There was a problem hiding this comment.
What happens if we don't special-case int and just simplify to one branch?
| 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) |
| if isinstance(memory_usage, int): | ||
| return (5 * memory_usage + 3) // 4 | ||
| return math.ceil(5 * memory_usage / 4) |
There was a problem hiding this comment.
What happens if we don't special-case int and just simplify to one branch?
| 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) |
b7854d3 to
a32d693
Compare
|
This pull request has been automatically marked as stale because it has not had 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. |
Signed-off-by: viiccwen <[email protected]>
Signed-off-by: viiccwen <[email protected]>
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]>
Signed-off-by: viiccwen <[email protected]>
Signed-off-by: viiccwen <[email protected]>
Signed-off-by: viiccwen <[email protected]>
Signed-off-by: viiccwen <[email protected]>
f641860 to
938a343
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 938a343. Configure here.
| with pytest.raises(KeyboardInterrupt): | ||
| ray.data.range(1).take_all() | ||
|
|
||
| assert operators_shut_down |
There was a problem hiding this comment.
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.
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]>
938a343 to
6600a78
Compare
|
@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]>
…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]>
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


Description
When a map operator completes or shuts down, the detector checks its observed maximum USS once. If logical
memorywas configured and is less than 125% of the maximum USS, the detector emits a warning with an exactmemory=<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