-
Notifications
You must be signed in to change notification settings - Fork 7k
[core] Autoscaler with resource availability #58623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
edoakes
merged 20 commits into
ray-project:master
from
wxwmd:feature/autoscale_with_resource_availability
Nov 25, 2025
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
c689b67
autoscaler for spot resources
2b4113c
autoscaler for spot resources
f5babbf
autoscaler for spot resources
30db581
autoscaler for spot resources
dd31148
autoscaler for spot resources
9a84eab
autoscaler for spot resources
ff64f09
autoscaler for spot resources
94796cf
autoscaler for spot resources
0b34179
autoscaler for spot resources
4e6ef80
autoscaler for spot resources
185a62b
autoscaler for spot resources
c95675c
autoscaler for spot resources
87b2860
autoscaler for spot resources
7eb7fdf
autoscaler for spot resources
1b6039d
autoscaler for spot resources
3375aa1
autoscaler for spot resources
9dace5d
autoscaler for spot resources
3290f1b
autoscaler for spot resources
d8f22d9
autoscaler for spot resources
1035b89
autoscaler for spot resources
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
python/ray/autoscaler/v2/instance_manager/subscribers/cloud_resource_monitor.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import logging | ||
| import time | ||
| from typing import Dict, List | ||
|
|
||
| from ray.autoscaler.v2.instance_manager.instance_manager import ( | ||
| InstanceUpdatedSubscriber, | ||
| ) | ||
| from ray.autoscaler.v2.schema import NodeType | ||
| from ray.core.generated.instance_manager_pb2 import Instance, InstanceUpdateEvent | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class CloudResourceMonitor(InstanceUpdatedSubscriber): | ||
| """CloudResourceMonitor records the availability of all node types. | ||
|
|
||
| In the Spot scenario, the resources in the cluster change dynamically. | ||
| When scaling up, it is necessary to know which node types are most | ||
| likely to have resources, in order to decide which type of node to request. | ||
|
|
||
| During scaling up, if resource of a node type is requested but fail to | ||
| allocate, that type is considered unavailable at that timestamp.This class | ||
| records the last timestamp at which a node type is unavailable,allowing the | ||
| autoscaler to skip such node types when making future scaling decisions. | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| ) -> None: | ||
| self._last_unavailable_timestamp: Dict[NodeType, float] = {} | ||
|
|
||
| def allocation_timeout(self, failed_event: InstanceUpdateEvent): | ||
| unavailable_timestamp = time.time() | ||
| self._last_unavailable_timestamp[ | ||
| failed_event.instance_type | ||
| ] = unavailable_timestamp | ||
| logger.info( | ||
| f"Cloud Resource Type {failed_event.instance_type} is " | ||
| f"unavailable at timestamp={unavailable_timestamp}. " | ||
| f"We will lower its priority in feature schedules." | ||
| ) | ||
|
|
||
| def allocation_succeeded(self, succeeded_event: InstanceUpdateEvent): | ||
| if succeeded_event.instance_type in self._last_unavailable_timestamp: | ||
| self._last_unavailable_timestamp.pop(succeeded_event.instance_type) | ||
| logger.info( | ||
| f"Cloud Resource Type {succeeded_event.instance_type} is " | ||
| f"available at timestamp={time.time()}. We will higher its priority in " | ||
| f"feature schedules." | ||
| ) | ||
|
|
||
| def notify(self, events: List[InstanceUpdateEvent]) -> None: | ||
| for event in events: | ||
| if event.new_instance_status == Instance.ALLOCATION_TIMEOUT: | ||
| self.allocation_timeout(event) | ||
| elif ( | ||
| event.new_instance_status == Instance.RAY_RUNNING | ||
| and event.instance_type | ||
| ): | ||
| self.allocation_succeeded(event) | ||
|
|
||
| def get_resource_availabilities(self) -> Dict[NodeType, float]: | ||
| """Calculate the availability scores of node types. | ||
| Higher values indicate a higher likelihood of resource allocation. | ||
| """ | ||
| resource_availability_scores: Dict[NodeType, float] = {} | ||
| if self._last_unavailable_timestamp: | ||
| max_ts = max(self._last_unavailable_timestamp.values()) | ||
| for node_type in self._last_unavailable_timestamp: | ||
| resource_availability_scores[node_type] = ( | ||
| 1 - self._last_unavailable_timestamp[node_type] / max_ts | ||
| ) | ||
| return resource_availability_scores | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
wxwmd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.