首页 > 解决方案 > 关于将不同的 Ray 工人翻译成 dask 工人的问题

问题描述

我目前正在努力将 Ray 方法转换为 dask,我想知道如何为一个类创建五个不同的“工人”,就像下面的 Ray 程序一样(在 jupyter notebook 中运行程序):

"""
#CURRENT VERSION 
A simple test of Ray
This example uses placement_group API to spread work around
"""
import random
import os
import platform
import ray
import time
ray.init(ignore_reinit_error=True)

@ray.remote
class Actor():
    def __init__(self, actor_id) -> None:
        self.pid = os.getpid()
        self.hostname = platform.node()
        self.ip = ray._private.services.get_node_ip_address()
        self.actor_id = actor_id
        
    def ping(self):
        print(f"{self.actor_id} {self.pid} {self.hostname} {self.ip} {time.time()} - ping")
        time.sleep(random.randint(1,3))
        return f"{self.actor_id}"

@ray.remote
def main():
# Get list of nodes to use
    print(f"Found {len(actors)} Worker nodes in the Ray Cluster:")
# Setup one Actor per node
    print(f"Setting up {len(actors)} Actors...")
    time.sleep(1)
    
# Ping-Pong test
    messages = [actors[a].ping.remote() for a in actors]
    time.sleep(1)
    for _ in range(20):
        new_messages, messages = ray.wait(messages, num_returns=1)
        for ray_message_id in new_messages:
            pong = ray.get(ray_message_id)
            print(pong, "- pong")
            check = actors[pong].ping.remote()
            time.sleep(1)
            messages.append(check)

actors = {
    "actor1" : Actor.remote(actor_id="actor1"),
    "actor2" : Actor.remote(actor_id="actor2"),
    "actor3" : Actor.remote(actor_id="actor3"),
    "actor4" : Actor.remote(actor_id="actor4"),
    "actor5" : Actor.remote(actor_id="actor5")
}

print(actors)
if __name__ == "__main__":
    main.remote()

标签: pythondaskdask-distributedray

解决方案


推荐阅读