python - 关于将不同的 Ray 工人翻译成 dask 工人的问题
问题描述
我目前正在努力将 Ray 方法转换为 dask,我想知道如何为一个类创建五个不同的“工人”,就像下面的 Ray 程序一样(在 jupyter notebook 中运行程序):
- 到目前为止,我的 dask 版本中有一个类似的方法,但是每个“actor_”都从 ping 函数打印相同的演员 ID。有人可以帮助在 Dask 中创建类似的产品吗?
"""
#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()
解决方案
推荐阅读
- java - Spring boot 2.2.2 失败,原因是:java.lang.ClassNotFoundException: org.springframework.core.log.LogMessage
- python - Python 卡在 pipe.stdin.write(image.tostring())
- java - 使用 Gradle Java 项目迁移版本 3.x 的 Azure Functions,但出现“值不能为空”错误
- android - 如何在 Appium 的 AndroidDriver 类中增加 HTTP 超时
- ios - pushRegistry(:didUpdate:for) 没有被调用
- r - 用户移动传单地图后,如何以闪亮的方式返回其位置?
- javascript - 选中复选框时如何自动填充文本区域
- python - 有没有使用 bs4 提取(获取)属性值的函数
- python - 测试不同大小的数组之间的相同性:“DeprecationWarning:元素比较失败;这将在未来引发错误”
- nginx - 如何控制 vhost_shared_traffic 内存 K8s nginx 入口?