Repository navigation
[Data][Autoscaler][1/N] Add AutoscalingCoordinator - #59353
Conversation
Signed-off-by: Balaji Veeramani <[email protected]>
Signed-off-by: Balaji Veeramani <[email protected]>
Signed-off-by: Balaji Veeramani <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces an AutoscalingCoordinator to centralize resource requests, which is a significant improvement for managing resources in concurrent job scenarios. The implementation is robust, featuring a resilient actor-based design with timeout handling, caching, and lazy initialization. The tests are comprehensive, covering unit, integration, and failure cases effectively.
My feedback highlights a few areas for improvement:
- A potential high-severity issue regarding the over-allocation of remaining resources.
- A medium-severity issue concerning an in-place modification of an argument list, which could lead to unexpected side effects.
- Minor suggestions for improving code style and test hygiene.
Overall, this is a well-executed feature addition. Addressing these points will further enhance the reliability and maintainability of the new coordinator.
| for ongoing_req in ongoing_reqs: | ||
| if ongoing_req.request_remaining: | ||
| ongoing_req.allocated_resources.extend(cluster_node_resources) |
There was a problem hiding this comment.
The current implementation allocates all remaining cluster resources to every requester with request_remaining=True. As noted in the code comment, this can lead to double-allocation and overallocation if multiple such requesters exist, potentially causing resource contention and task scheduling failures. While this is for parity with previous behavior, it's a significant correctness risk. A more robust approach would be to divide the remaining resources among the requesters, for example, proportionally to their initial requests, or on a first-come, first-served basis.
| requester_id = kwargs.get(requester_id_param) | ||
| if requester_id is None: | ||
| # Try to get from args by checking function signature | ||
| import inspect |
| for r in resources: | ||
| for k in r: | ||
| r[k] = math.ceil(r[k]) |
There was a problem hiding this comment.
This loop modifies the resources list in-place, which can be an unexpected side effect for the caller. To avoid this, consider creating a new list of resource dictionaries with the rounded-up values using a list comprehension. This makes the function's behavior clearer and safer as it avoids mutating its inputs.
resources = [{k: math.ceil(v) for k, v in r.items()} for r in resources]| MOCKED_TIME = 0 | ||
|
|
||
|
|
||
| def mock_time(): | ||
| global MOCKED_TIME | ||
|
|
||
| return MOCKED_TIME |
There was a problem hiding this comment.
Using a global variable MOCKED_TIME for mocking time can lead to test flakiness, especially if tests are run in parallel. It would be more robust to encapsulate the mock time state, for example, by using a class instance or a fixture that doesn't rely on global state.
For example, you could define a callable class:
class MockTime:
def __init__(self, initial_time=0):
self.current_time = initial_time
def __call__(self):
return self.current_time
def set_time(self, new_time):
self.current_time = new_timeAnd then in your test:
mock_time = MockTime()
with patch("time.time", mock_time):
# ... test logic ...
mock_time.set_time(10)
# ... more test logic ...AutoscalingCoordinatorAutoscalingCoordinator
| # Call tick() as an actor task, | ||
| # so we don't need to handle multi-threading. | ||
| time.sleep(self.TICK_INTERVAL_S) | ||
| ray.get(self._self_handle.tick.remote()) |
There was a problem hiding this comment.
Bug: Tick thread silently crashes on unhandled exceptions
The tick_thread_run function has no exception handling around the ray.get(self._self_handle.tick.remote()) call. If any exception occurs (network issues, actor errors, or other runtime errors), the thread will terminate silently without any notification since it's a daemon thread. This causes the periodic maintenance operations (purging expired requests, updating cluster resources, reallocating resources) to stop functioning permanently until the actor restarts, potentially leading to stale allocation information and memory growth from accumulated expired requests.
| return False | ||
| for key in res2: | ||
| res1[key] -= res2[key] | ||
| return True |
There was a problem hiding this comment.
Bug: KeyError when subtracting zero-valued resources not present in node
The _maybe_subtract_resources function raises a KeyError if a requested resource bundle contains a key with value 0 that doesn't exist in the node's resources. The check on line 352 uses res1.get(key, 0) < res2[key], which evaluates to 0 < 0 (False) when res2[key] is 0, so the function proceeds to line 355 which attempts res1[key] -= res2[key]. Since key doesn't exist in res1, this raises a KeyError. This could occur if a resource request includes resource types with zero values that aren't present on cluster nodes.
Signed-off-by: Balaji Veeramani <[email protected]>
Signed-off-by: Balaji Veeramani <[email protected]>
…rces (#63306) #59353 open-sourced the `AutoscalingCoordinator` including a `math.ceil` block on incoming resource bundles. The block traces back to that validator was added back in #26626 to fix a *shape* bug (#23166 ). The literal `int` came from an informal type annotation; It seems that neither v1 (KV → load_metrics → bin-packing) nor v2 (proto `map<string, double>`) requires it. Drop the value-type check in the SDK and remove the `math.ceil` workaround in Ray Data --------- Signed-off-by: Lehui Liu <[email protected]>
…rces (ray-project#63306) ray-project#59353 open-sourced the `AutoscalingCoordinator` including a `math.ceil` block on incoming resource bundles. The block traces back to that validator was added back in ray-project#26626 to fix a *shape* bug (ray-project#23166 ). The literal `int` came from an informal type annotation; It seems that neither v1 (KV → load_metrics → bin-packing) nor v2 (proto `map<string, double>`) requires it. Drop the value-type check in the SDK and remove the `math.ceil` workaround in Ray Data --------- Signed-off-by: Lehui Liu <[email protected]> Signed-off-by: phattruong <[email protected]>
…rces (ray-project#63306) ray-project#59353 open-sourced the `AutoscalingCoordinator` including a `math.ceil` block on incoming resource bundles. The block traces back to that validator was added back in ray-project#26626 to fix a *shape* bug (ray-project#23166 ). The literal `int` came from an informal type annotation; It seems that neither v1 (KV → load_metrics → bin-packing) nor v2 (proto `map<string, double>`) requires it. Drop the value-type check in the SDK and remove the `math.ceil` workaround in Ray Data --------- Signed-off-by: Lehui Liu <[email protected]> Signed-off-by: Alexandr Plashchinsky <[email protected]>
## Summary Runs the shared AutoscalingCoordinator actor on the head node instead of the first caller's node, so losing a worker node no longer takes the coordinator with it for every Ray Data and Ray Train requester on the cluster. ## Before `get_or_create_autoscaling_coordinator` created the detached actor with hard node affinity to the caller's node and `max_restarts=-1`. The original PR (#59353) noted "Create the actor on the local node, to reduce network overhead". The problem is that the coordinator, though, is shared by every requester on the cluster. The first caller can be on any node, for example a Train controller or a Ray Data executor inside a Train worker. If that node dies, the actor can't be rescheduled (`ActorUnschedulableError`). Requesters that already hold a handle, such as Train's coordinator client, lose it for good, so a running elastic run can't resize or restart. Soft affinity doesn't help: `ClusterResourceScheduler::GetBestSchedulableNode` places an actor that requests no resources on a random node unless its affinity is hard, so it could land on an autoscaled worker and restart elsewhere every time that worker scales down. ## After The actor requests `node:__internal_head__: 0.001` and uses `scheduling_strategy="DEFAULT"`. This is the same pattern as the Serve controller (`serve/_private/default_impl.py`) and both Train state actors (`train/_internal/state/state_actor.py`, `train/v2/_internal/state/state_actor.py`). The head node lives as long as the cluster. With GCS fault tolerance, a restarted head has the same resource, so the actor can restart there. The explicit `"DEFAULT"` strategy matters. Without it, a caller in a placement group that captures child tasks (Tune trials, Train V1 workers) makes the actor join that group. The bundles don't hold the head-node resource, so creation fails with `ValueError: Cannot schedule _AutoscalingCoordinatorActor with the placement group` and a detached actor shouldn't die with someone else's group anyway. ## New tests In `test_autoscaling_coordinator.py`: - `test_coordinator_actor_runs_on_the_head_node`: created from a worker node, the actor runs on the head and survives that worker's removal. - `test_coordinator_actor_escapes_the_callers_placement_group`: created from a task in a placement group that captures child tasks, the actor runs on the head and survives the group's removal. It fails without `scheduling_strategy="DEFAULT"`. The end-to-end case, `test_run_restarts_after_the_coordinators_first_caller_dies`, is in #67481. AI assistance (Claude Code) was used to write these changes and tests, run the suites, and write this description. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Mark Towers <[email protected]> Signed-off-by: Mark Towers <[email protected]> Co-authored-by: Mark Towers <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Chi-Sheng Liu <[email protected]>
When multiple Ray Data or Ray Train jobs run concurrently on a cluster, they each independently request resources from the Ray Autoscaler without awareness of each other. This can lead to inefficient resource utilization and conflicts.
This PR introduces an
AutoscalingCoordinatorthat acts as a central point for coordinating resource requests across components.