mirror of
https://github.com/wassname/ray.git
synced 2026-07-13 13:58:30 +08:00
[autoscaler] resource demand scheduler get_nodes_to_launch should return Dict not List (#11118)
This commit is contained in:
@@ -105,34 +105,34 @@ def test_bin_pack():
|
||||
|
||||
def test_get_nodes_packing_heuristic():
|
||||
assert get_nodes_for(TYPES_A, {}, 9999, [{"GPU": 8}]) == \
|
||||
[("p2.8xlarge", 1)]
|
||||
{"p2.8xlarge": 1}
|
||||
assert get_nodes_for(TYPES_A, {}, 9999, [{"GPU": 1}] * 6) == \
|
||||
[("p2.8xlarge", 1)]
|
||||
{"p2.8xlarge": 1}
|
||||
assert get_nodes_for(TYPES_A, {}, 9999, [{"GPU": 1}] * 4) == \
|
||||
[("p2.xlarge", 4)]
|
||||
{"p2.xlarge": 4}
|
||||
assert get_nodes_for(TYPES_A, {}, 9999, [{"CPU": 32, "GPU": 1}] * 3) \
|
||||
== [("p2.8xlarge", 3)]
|
||||
== {"p2.8xlarge": 3}
|
||||
assert get_nodes_for(TYPES_A, {}, 9999, [{"CPU": 64, "GPU": 1}] * 3) \
|
||||
== []
|
||||
== {}
|
||||
assert get_nodes_for(TYPES_A, {}, 9999, [{"CPU": 64}] * 3) == \
|
||||
[("m4.16xlarge", 3)]
|
||||
{"m4.16xlarge": 3}
|
||||
assert get_nodes_for(TYPES_A, {}, 9999, [{"CPU": 64}, {"CPU": 1}]) \
|
||||
== [("m4.16xlarge", 1), ("m4.large", 1)]
|
||||
== {"m4.16xlarge": 1, "m4.large": 1}
|
||||
assert get_nodes_for(
|
||||
TYPES_A, {}, 9999, [{"CPU": 64}, {"CPU": 9}, {"CPU": 9}]) == \
|
||||
[("m4.16xlarge", 1), ("m4.4xlarge", 2)]
|
||||
{"m4.16xlarge": 1, "m4.4xlarge": 2}
|
||||
assert get_nodes_for(TYPES_A, {}, 9999, [{"CPU": 16}] * 5) == \
|
||||
[("m4.16xlarge", 1), ("m4.4xlarge", 1)]
|
||||
{"m4.16xlarge": 1, "m4.4xlarge": 1}
|
||||
assert get_nodes_for(TYPES_A, {}, 9999, [{"CPU": 8}] * 10) == \
|
||||
[("m4.16xlarge", 1), ("m4.4xlarge", 1)]
|
||||
{"m4.16xlarge": 1, "m4.4xlarge": 1}
|
||||
assert get_nodes_for(TYPES_A, {}, 9999, [{"CPU": 1}] * 100) == \
|
||||
[("m4.16xlarge", 1), ("m4.4xlarge", 2), ("m4.large", 2)]
|
||||
{"m4.16xlarge": 1, "m4.4xlarge": 2, "m4.large": 2}
|
||||
assert get_nodes_for(
|
||||
TYPES_A, {}, 9999, [{"GPU": 1}] + ([{"CPU": 1}] * 64)) == \
|
||||
[("m4.16xlarge", 1), ("p2.xlarge", 1)]
|
||||
{"m4.16xlarge": 1, "p2.xlarge": 1}
|
||||
assert get_nodes_for(
|
||||
TYPES_A, {}, 9999, ([{"GPU": 1}] * 8) + ([{"CPU": 1}] * 64)) == \
|
||||
[("m4.16xlarge", 1), ("p2.8xlarge", 1)]
|
||||
{"m4.16xlarge": 1, "p2.8xlarge": 1}
|
||||
|
||||
|
||||
def test_get_nodes_respects_max_limit():
|
||||
@@ -151,19 +151,25 @@ def test_get_nodes_respects_max_limit():
|
||||
},
|
||||
}
|
||||
assert get_nodes_for(types, {}, 2, [{"CPU": 1}] * 10) == \
|
||||
[("m4.large", 2)]
|
||||
{"m4.large": 2}
|
||||
assert get_nodes_for(types, {"m4.large": 9999}, 9999, [{
|
||||
"CPU": 1
|
||||
}] * 10) == []
|
||||
}] * 10) == {}
|
||||
assert get_nodes_for(types, {"m4.large": 0}, 9999, [{
|
||||
"CPU": 1
|
||||
}] * 10) == [("m4.large", 5)]
|
||||
}] * 10) == {
|
||||
"m4.large": 5
|
||||
}
|
||||
assert get_nodes_for(types, {"m4.large": 7}, 4, [{
|
||||
"CPU": 1
|
||||
}] * 10) == [("m4.large", 3)]
|
||||
}] * 10) == {
|
||||
"m4.large": 3
|
||||
}
|
||||
assert get_nodes_for(types, {"m4.large": 7}, 2, [{
|
||||
"CPU": 1
|
||||
}] * 10) == [("m4.large", 2)]
|
||||
}] * 10) == {
|
||||
"m4.large": 2
|
||||
}
|
||||
|
||||
|
||||
def test_add_min_workers_nodes():
|
||||
@@ -194,19 +200,19 @@ def test_add_min_workers_nodes():
|
||||
{},
|
||||
types) == \
|
||||
([{"CPU": 2}]*50+[{"GPU": 1}]*99999, {"m2.large": 50, "gpu": 99999},
|
||||
[("m2.large", 50), ("gpu", 99999)])
|
||||
{"m2.large": 50, "gpu": 99999})
|
||||
|
||||
assert _add_min_workers_nodes([{"CPU": 2}]*5,
|
||||
{"m2.large": 5},
|
||||
types) == \
|
||||
([{"CPU": 2}]*50+[{"GPU": 1}]*99999, {"m2.large": 50, "gpu": 99999},
|
||||
[("m2.large", 45), ("gpu", 99999)])
|
||||
{"m2.large": 45, "gpu": 99999})
|
||||
|
||||
assert _add_min_workers_nodes([{"CPU": 2}]*60,
|
||||
{"m2.large": 60},
|
||||
types) == \
|
||||
([{"CPU": 2}]*60+[{"GPU": 1}]*99999, {"m2.large": 60, "gpu": 99999},
|
||||
[("gpu", 99999)])
|
||||
{"gpu": 99999})
|
||||
|
||||
assert _add_min_workers_nodes([{
|
||||
"CPU": 2
|
||||
@@ -222,7 +228,7 @@ def test_add_min_workers_nodes():
|
||||
}] * 99999, {
|
||||
"m2.large": 50,
|
||||
"gpu": 99999
|
||||
}, [])
|
||||
}, {})
|
||||
|
||||
|
||||
def test_get_nodes_to_launch_with_min_workers():
|
||||
@@ -241,7 +247,7 @@ def test_get_nodes_to_launch_with_min_workers():
|
||||
to_launch = scheduler.get_nodes_to_launch(nodes, {}, [{
|
||||
"GPU": 8
|
||||
}], utilizations)
|
||||
assert to_launch == [("p2.8xlarge", 1)]
|
||||
assert to_launch == {"p2.8xlarge": 1}
|
||||
|
||||
|
||||
def test_get_nodes_to_launch_with_min_workers_and_bin_packing():
|
||||
@@ -263,7 +269,7 @@ def test_get_nodes_to_launch_with_min_workers_and_bin_packing():
|
||||
demands = [{"GPU": 8}] * (len(utilizations) + 1) + [{"GPU": 1}]
|
||||
to_launch = scheduler.get_nodes_to_launch(nodes, pending_nodes, demands,
|
||||
utilizations)
|
||||
assert to_launch == [("p2.xlarge", 1)]
|
||||
assert to_launch == {"p2.xlarge": 1}
|
||||
|
||||
# 3 min_workers of p2.8xlarge covers the 2 p2.8xlarge + 1 p2.xlarge demand.
|
||||
# 2 p2.8xlarge are running/pending. So we need 1 more p2.8xlarge only to
|
||||
@@ -273,7 +279,7 @@ def test_get_nodes_to_launch_with_min_workers_and_bin_packing():
|
||||
to_launch = scheduler.get_nodes_to_launch(nodes, pending_nodes, demands,
|
||||
utilizations)
|
||||
# Make sure it does not return [("p2.8xlarge", 1), ("p2.xlarge", 1)]
|
||||
assert to_launch == [("p2.8xlarge", 1)]
|
||||
assert to_launch == {"p2.8xlarge": 1}
|
||||
|
||||
|
||||
def test_get_nodes_to_launch_limits():
|
||||
@@ -290,7 +296,7 @@ def test_get_nodes_to_launch_limits():
|
||||
to_launch = scheduler.get_nodes_to_launch(nodes, {"p2.8xlarge": 1}, [{
|
||||
"GPU": 8
|
||||
}] * 2, utilizations)
|
||||
assert to_launch == []
|
||||
assert to_launch == {}
|
||||
|
||||
|
||||
def test_calculate_node_resources():
|
||||
@@ -311,7 +317,7 @@ def test_calculate_node_resources():
|
||||
to_launch = scheduler.get_nodes_to_launch(nodes, pending_nodes, demands,
|
||||
utilizations)
|
||||
|
||||
assert to_launch == [("p2.8xlarge", 1)]
|
||||
assert to_launch == {"p2.8xlarge": 1}
|
||||
|
||||
|
||||
class LoadMetricsTest(unittest.TestCase):
|
||||
|
||||
Reference in New Issue
Block a user