mirror of
https://github.com/wassname/ray.git
synced 2026-06-28 20:56:34 +08:00
Fix autoscaler format string for memory (#5542)
* add format string * fix cast
This commit is contained in:
@@ -28,7 +28,7 @@ from ray.autoscaler.updater import NodeUpdaterThread
|
||||
from ray.ray_constants import AUTOSCALER_MAX_NUM_FAILURES, \
|
||||
AUTOSCALER_MAX_LAUNCH_BATCH, AUTOSCALER_MAX_CONCURRENT_LAUNCHES, \
|
||||
AUTOSCALER_UPDATE_INTERVAL_S, AUTOSCALER_HEARTBEAT_TIMEOUT_S, \
|
||||
AUTOSCALER_RESOURCE_REQUEST_CHANNEL
|
||||
AUTOSCALER_RESOURCE_REQUEST_CHANNEL, MEMORY_RESOURCE_UNIT_BYTES
|
||||
from six import string_types
|
||||
from six.moves import queue
|
||||
|
||||
@@ -254,11 +254,19 @@ class LoadMetrics(object):
|
||||
ip: (now - t)
|
||||
for ip, t in most_delayed_heartbeats
|
||||
}
|
||||
|
||||
def format_resource(key, value):
|
||||
if key in ["object_store_memory", "memory"]:
|
||||
return "{} GiB".format(
|
||||
round(value * MEMORY_RESOURCE_UNIT_BYTES / 1e9, 2))
|
||||
else:
|
||||
return round(value, 2)
|
||||
|
||||
return {
|
||||
"ResourceUsage": ", ".join([
|
||||
"{}/{} {}".format(
|
||||
round(resources_used[rid], 2),
|
||||
round(resources_total[rid], 2), rid)
|
||||
format_resource(rid, resources_used[rid]),
|
||||
format_resource(rid, resources_total[rid]), rid)
|
||||
for rid in sorted(resources_used)
|
||||
]),
|
||||
"NumNodesConnected": len(self.static_resources_by_ip),
|
||||
|
||||
@@ -1301,7 +1301,7 @@ def _start_plasma_store(plasma_store_memory,
|
||||
"plasma_directory argument must be provided.")
|
||||
|
||||
if not isinstance(plasma_store_memory, int):
|
||||
raise Exception("plasma_store_memory should be an integer.")
|
||||
plasma_store_memory = int(plasma_store_memory)
|
||||
|
||||
command = [
|
||||
PLASMA_STORE_EXECUTABLE, "-s", socket_name, "-m",
|
||||
|
||||
@@ -174,10 +174,19 @@ class LoadMetricsTest(unittest.TestCase):
|
||||
lm = LoadMetrics()
|
||||
lm.update("1.1.1.1", {"CPU": 2}, {"CPU": 0})
|
||||
lm.update("2.2.2.2", {"CPU": 2, "GPU": 16}, {"CPU": 2, "GPU": 2})
|
||||
lm.update("3.3.3.3", {
|
||||
"memory": 20,
|
||||
"object_store_memory": 40
|
||||
}, {
|
||||
"memory": 0,
|
||||
"object_store_memory": 20
|
||||
})
|
||||
debug = lm.info_string()
|
||||
assert "ResourceUsage=2.0/4.0 CPU, 14.0/16.0 GPU" in debug
|
||||
assert "NumNodesConnected=2" in debug
|
||||
assert "NumNodesUsed=1.88" in debug
|
||||
assert ("ResourceUsage=2.0/4.0 CPU, 14.0/16.0 GPU, "
|
||||
"1.05 GiB/1.05 GiB memory, "
|
||||
"1.05 GiB/2.1 GiB object_store_memory") in debug
|
||||
assert "NumNodesConnected=3" in debug
|
||||
assert "NumNodesUsed=2.88" in debug
|
||||
|
||||
|
||||
class AutoscalingTest(unittest.TestCase):
|
||||
|
||||
Reference in New Issue
Block a user