【问题标题】:Ray Cluster How to Access all Node ResourcesRay Cluster 如何访问所有节点资源
【发布时间】:2019-09-23 02:52:40
【问题描述】:

我可以访问节点集群,我的理解是,一旦我在具有相同 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 $1"

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

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 应该自动检测新节点上的资源,所以我不知道这里发生了什么。

【问题讨论】:

    标签: python ray


    【解决方案1】:

    ray.services.check_and_update_resources 方法是内部方法,不打算公开。您可以使用ray.global_state.cluster_resources()ray.global_state.client_table() 来查看集群资源。

    【讨论】:

    • 为什么文档中给出的the example 不使用这两种方法来检查设置是否正确?我还缺少其他关于此的文档吗?
    • 没有充分的理由。我认为这将是对文档的一个很好的改进。
    • 谢谢。在 ray 0.9+ 上,我能够使用 ray.cluster_resources() 和 ray.nodes() 参见文档:'Inspect the Cluster State'
    【解决方案2】:

    在较新版本的 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}
    

    【讨论】:

      猜你喜欢
      • 2019-07-26
      • 1970-01-01
      • 1970-01-01
      • 2020-03-16
      • 2018-06-18
      • 1970-01-01
      • 2021-03-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多