Automatically create custom node id resource (#5882)

* node id

* comment

* comments

* fix tests
This commit is contained in:
Eric Liang
2019-10-15 21:31:11 -07:00
committed by GitHub
parent c52bb0621d
commit 6843a01a7f
6 changed files with 73 additions and 1 deletions
+8
View File
@@ -13,6 +13,10 @@ import ray.ray_constants as ray_constants
logger = logging.getLogger(__name__)
# Prefix for the node id resource that is automatically added to each node.
# For example, a node may have id `node:172.23.42.1`.
NODE_ID_PREFIX = "node:"
class ResourceSpec(
namedtuple("ResourceSpec", [
@@ -127,6 +131,10 @@ class ResourceSpec(
assert "memory" not in resources, resources
assert "object_store_memory" not in resources, resources
# Automatically create a node id resource on each node. This is
# queryable with ray.state.node_ids() and ray.state.current_node_id().
resources[NODE_ID_PREFIX + ray.services.get_node_ip_address()] = 1.0
num_cpus = self.num_cpus
if num_cpus is None:
num_cpus = multiprocessing.cpu_count()