Ray集群如何访问所有节点资源

Ray Cluster How to Access all Node Resources

我可以访问一个节点集群,我的理解是,一旦我在每个具有相同 redis 地址的节点上启动 ray,头节点将可以访问所有节点的所有资源。

主脚本:

export LC_ALL=en_US.utf-8
export LANG=en_US.utf-8 # required for using python 3 with click
source activate rllab3

redis_address="$(hostname --ip-address)"
echo $redis_address
redis_address="$redis_address:59465"
~/.conda/envs/rllab3/bin/ray start --head --redis-port=59465

for host in $(srun hostname | grep -v $(hostname)); do 
    ssh $host setup_node.sh $redis_address
done

python test_multi_node.py $redis_address

setup_node.sh

export LC_ALL=en_US.utf-8
export LANG=en_US.utf-8

source activate rllab3

echo "redis address is "

~/.conda/envs/rllab3/bin/ray start --redis-address=

test_multi_node.py

import ray
import time
import argparse

parser = argparse.ArgumentParser(description = "ray multinode test")
parser.add_argument("redis_address", type=str, help="ip:port")
args = parser.parse_args()
print("in python script redis addres is:", args.redis_address)

ray.init(redis_address=args.redis_address)
print("resources:", ray.services.check_and_update_resources(None, None, None))

@ray.remote
def f():
    time.sleep(0.01)
    return ray.services.get_node_ip_address()

# Get a list of the IP addresses of the nodes that have joined the cluster.
print(set(ray.get([f.remote() for _ in range(10000)])))

Ray 似乎在所有节点上成功启动,并且 python 脚本打印出与我有节点一样多的 IP 地址(它们是正确的)。但是打印资源的时候只有一个节点的资源。

如何让ray访问所有节点的所有资源?我一定有一个根本性的误解,因为我认为在其他节点上设置 ray 的目的是让它访问它们的所有资源。

根据 to this ray 应该自动检测新节点上的资源所以我不知道这里发生了什么。

方法ray.services.check_and_update_resources是一个内部方法,不打算公开。您可以使用 ray.global_state.cluster_resources() 以及 ray.global_state.client_table().

检查集群资源

在较新版本的 Ray(此处测试为 0.8.2+)上,我们可以尝试:

检查集群状态 https://ray.readthedocs.io/en/latest/package-ref.html#inspect-the-cluster-state 单机系统输出示例:

print(ray.nodes())
"""[{'NodeID': <ID>, 'Alive': True, 'NodeManagerAddress': <IP>,
'NodeManagerHostname': <HOSTNAME>, 'NodeManagerPort': <PORT>,
'ObjectManagerPort': 32799, 'ObjectStoreSocketName':
'/tmp/ray/session_2020-03-25_00-42-55_127146_1246/sockets/plasma_store',
'RayletSocketName':
'/tmp/ray/session_2020-03-25_00-42-55_127146_1246/sockets/raylet',
'Resources': {'node:<IP>': 1.0, 'GPU': 1.0, 'CPU': 8.0, 'memory':
160.0, 'object_store_memory': 55.0}, 'alive': True}]"""

资源信息 https://ray.readthedocs.io/en/latest/advanced.html 如其他解决方案中所述,cluster_resources 或 available_resources 等项目可以专门获取资源信息:

print(ray.cluster_resources()) 
# {'node:<IP>': 1.0, 'GPU': 1.0, 'CPU': 8.0, 'memory': 160.0, 'object_store_memory': 55.0}