mirror of
https://github.com/wassname/ray.git
synced 2026-07-13 11:12:12 +08:00
[autoscaler] Refactor code in preparation for multi instance type support (#8632)
* wip refactor * add util * wip * fix * fix * remove * remove extraneous string type for sg
This commit is contained in:
@@ -10,8 +10,9 @@ from jsonschema.exceptions import ValidationError
|
||||
|
||||
import ray
|
||||
import ray.services as services
|
||||
from ray.autoscaler.autoscaler import StandardAutoscaler, LoadMetrics, \
|
||||
fillout_defaults, validate_config
|
||||
from ray.autoscaler.util import fillout_defaults, validate_config
|
||||
from ray.autoscaler.load_metrics import LoadMetrics
|
||||
from ray.autoscaler.autoscaler import StandardAutoscaler
|
||||
from ray.autoscaler.tags import TAG_RAY_NODE_TYPE, TAG_RAY_NODE_STATUS, \
|
||||
STATUS_UP_TO_DATE, STATUS_UPDATE_FAILED
|
||||
from ray.autoscaler.node_provider import NODE_PROVIDERS, NodeProvider
|
||||
@@ -545,13 +546,13 @@ class AutoscalingTest(unittest.TestCase):
|
||||
# Update will try to create, but will block until we set the flag
|
||||
self.provider.ready_to_create.clear()
|
||||
autoscaler.update()
|
||||
assert autoscaler.num_launches_pending.value == 2
|
||||
assert autoscaler.pending_launches.value == 2
|
||||
assert len(self.provider.non_terminated_nodes({})) == 0
|
||||
|
||||
# Set the flag, check it updates
|
||||
self.provider.ready_to_create.set()
|
||||
self.waitForNodes(2)
|
||||
assert autoscaler.num_launches_pending.value == 0
|
||||
assert autoscaler.pending_launches.value == 0
|
||||
|
||||
# Update the config to reduce the cluster size
|
||||
new_config = SMALL_CLUSTER.copy()
|
||||
@@ -583,12 +584,9 @@ class AutoscalingTest(unittest.TestCase):
|
||||
rtc1.clear()
|
||||
autoscaler.update()
|
||||
# Synchronization: wait for launchy thread to be blocked on rtc1
|
||||
if hasattr(rtc1, "_cond"): # Python 3.5
|
||||
waiters = rtc1._cond._waiters
|
||||
else: # Python 2.7
|
||||
waiters = rtc1._Event__cond._Condition__waiters
|
||||
waiters = rtc1._cond._waiters
|
||||
self.waitFor(lambda: len(waiters) == 1)
|
||||
assert autoscaler.num_launches_pending.value == 5
|
||||
assert autoscaler.pending_launches.value == 5
|
||||
assert len(self.provider.non_terminated_nodes({})) == 0
|
||||
|
||||
# Call update() to launch a second wave of 3 nodes,
|
||||
@@ -599,24 +597,24 @@ class AutoscalingTest(unittest.TestCase):
|
||||
rtc2.set()
|
||||
autoscaler.update()
|
||||
self.waitForNodes(3)
|
||||
assert autoscaler.num_launches_pending.value == 5
|
||||
assert autoscaler.pending_launches.value == 5
|
||||
|
||||
# The first wave of 5 will now tragically fail
|
||||
self.provider.fail_creates = True
|
||||
rtc1.set()
|
||||
self.waitFor(lambda: autoscaler.num_launches_pending.value == 0)
|
||||
self.waitFor(lambda: autoscaler.pending_launches.value == 0)
|
||||
assert len(self.provider.non_terminated_nodes({})) == 3
|
||||
|
||||
# Retry the first wave, allowing it to succeed this time
|
||||
self.provider.fail_creates = False
|
||||
autoscaler.update()
|
||||
self.waitForNodes(8)
|
||||
assert autoscaler.num_launches_pending.value == 0
|
||||
assert autoscaler.pending_launches.value == 0
|
||||
|
||||
# Final wave of 2 nodes
|
||||
autoscaler.update()
|
||||
self.waitForNodes(10)
|
||||
assert autoscaler.num_launches_pending.value == 0
|
||||
assert autoscaler.pending_launches.value == 0
|
||||
|
||||
def testUpdateThrottling(self):
|
||||
config_path = self.write_config(SMALL_CLUSTER)
|
||||
@@ -632,7 +630,7 @@ class AutoscalingTest(unittest.TestCase):
|
||||
update_interval_s=10)
|
||||
autoscaler.update()
|
||||
self.waitForNodes(2)
|
||||
assert autoscaler.num_launches_pending.value == 0
|
||||
assert autoscaler.pending_launches.value == 0
|
||||
new_config = SMALL_CLUSTER.copy()
|
||||
new_config["max_workers"] = 1
|
||||
self.write_config(new_config)
|
||||
@@ -641,7 +639,7 @@ class AutoscalingTest(unittest.TestCase):
|
||||
# note that node termination happens in the main thread, so
|
||||
# we do not need to add any delay here before checking
|
||||
assert len(self.provider.non_terminated_nodes({})) == 2
|
||||
assert autoscaler.num_launches_pending.value == 0
|
||||
assert autoscaler.pending_launches.value == 0
|
||||
|
||||
def testLaunchConfigChange(self):
|
||||
config_path = self.write_config(SMALL_CLUSTER)
|
||||
@@ -682,7 +680,7 @@ class AutoscalingTest(unittest.TestCase):
|
||||
for _ in range(10):
|
||||
autoscaler.update()
|
||||
time.sleep(0.1)
|
||||
assert autoscaler.num_launches_pending.value == 0
|
||||
assert autoscaler.pending_launches.value == 0
|
||||
assert len(self.provider.non_terminated_nodes({})) == 2
|
||||
|
||||
# New a good config again
|
||||
@@ -812,7 +810,7 @@ class AutoscalingTest(unittest.TestCase):
|
||||
autoscaler.update()
|
||||
self.waitForNodes(1)
|
||||
autoscaler.update()
|
||||
assert autoscaler.num_launches_pending.value == 0
|
||||
assert autoscaler.pending_launches.value == 0
|
||||
assert len(self.provider.non_terminated_nodes({})) == 1
|
||||
|
||||
# Scales up as nodes are reported as used
|
||||
@@ -829,19 +827,19 @@ class AutoscalingTest(unittest.TestCase):
|
||||
lm.update("172.0.0.0", {"CPU": 2}, {"CPU": 2}, {})
|
||||
lm.update("172.0.0.1", {"CPU": 2}, {"CPU": 2}, {})
|
||||
autoscaler.update()
|
||||
assert autoscaler.num_launches_pending.value == 0
|
||||
assert autoscaler.pending_launches.value == 0
|
||||
assert len(self.provider.non_terminated_nodes({})) == 5
|
||||
|
||||
# Scales down as nodes become unused
|
||||
lm.last_used_time_by_ip["172.0.0.0"] = 0
|
||||
lm.last_used_time_by_ip["172.0.0.1"] = 0
|
||||
autoscaler.update()
|
||||
assert autoscaler.num_launches_pending.value == 0
|
||||
assert autoscaler.pending_launches.value == 0
|
||||
assert len(self.provider.non_terminated_nodes({})) == 3
|
||||
lm.last_used_time_by_ip["172.0.0.2"] = 0
|
||||
lm.last_used_time_by_ip["172.0.0.3"] = 0
|
||||
autoscaler.update()
|
||||
assert autoscaler.num_launches_pending.value == 0
|
||||
assert autoscaler.pending_launches.value == 0
|
||||
assert len(self.provider.non_terminated_nodes({})) == 1
|
||||
|
||||
def testDontScaleBelowTarget(self):
|
||||
@@ -861,7 +859,7 @@ class AutoscalingTest(unittest.TestCase):
|
||||
update_interval_s=0)
|
||||
assert len(self.provider.non_terminated_nodes({})) == 0
|
||||
autoscaler.update()
|
||||
assert autoscaler.num_launches_pending.value == 0
|
||||
assert autoscaler.pending_launches.value == 0
|
||||
assert len(self.provider.non_terminated_nodes({})) == 0
|
||||
|
||||
# Scales up as nodes are reported as used
|
||||
|
||||
@@ -5,7 +5,7 @@ import yaml
|
||||
import urllib
|
||||
import tempfile
|
||||
|
||||
from ray.autoscaler.autoscaler import fillout_defaults, validate_config
|
||||
from ray.autoscaler.util import fillout_defaults, validate_config
|
||||
from ray.test_utils import recursive_fnmatch
|
||||
|
||||
RAY_PATH = os.path.abspath(os.path.join(__file__, "../../"))
|
||||
|
||||
Reference in New Issue
Block a user