From 6810ecd51730d630614cd8db2580b9eb8cfb9b21 Mon Sep 17 00:00:00 2001 From: Eric Liang Date: Mon, 26 Aug 2019 14:56:00 -0700 Subject: [PATCH 1/2] add format string --- python/ray/autoscaler/autoscaler.py | 14 +++++++++++--- python/ray/tests/test_autoscaler.py | 15 ++++++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/python/ray/autoscaler/autoscaler.py b/python/ray/autoscaler/autoscaler.py index bef2224507ea..8873fec71729 100644 --- a/python/ray/autoscaler/autoscaler.py +++ b/python/ray/autoscaler/autoscaler.py @@ -28,7 +28,7 @@ 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 @@ def _info(self): 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), diff --git a/python/ray/tests/test_autoscaler.py b/python/ray/tests/test_autoscaler.py index dfb88a0bd140..36d55e940f26 100644 --- a/python/ray/tests/test_autoscaler.py +++ b/python/ray/tests/test_autoscaler.py @@ -174,10 +174,19 @@ def testDebugString(self): 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): From e64254f323d675fcce847a9f5574ab4b2621a8a1 Mon Sep 17 00:00:00 2001 From: Eric Liang Date: Mon, 26 Aug 2019 15:09:32 -0700 Subject: [PATCH 2/2] fix cast --- python/ray/services.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/ray/services.py b/python/ray/services.py index 2f6d915f7502..b15fcbb849b4 100644 --- a/python/ray/services.py +++ b/python/ray/services.py @@ -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",