Ray集群搭建 Python Demo
目錄
- 準備條件(基于linux環境)
- 參考文獻
- 例子-python Ray集群
-
- 1.部署head節點
- 2.部署worker節點
- 部署Ray集群
- 安裝Ray(在所有節點上安裝)
- Ray工作原理
- Ray的優勢
- Ray簡介
準備條件(基于linux環境)
- 這里部署2個節點的集群,準備2個linux環境,ip為
-
安裝 python3:yum install python3
-
Ray學習文檔地址:https://ray.readthedocs.io/en/latest/index.html
-
github地址:https://github.com/ray-project/ray
Ray簡介
Ray是用于構建和運行分布式應用程序的快速,簡單的框架。
Ray與以下庫打包在一起,以加快機器學習的工作量:
Tune:可伸縮超參數調整
RLlib:可擴展的強化學習
Distributed Training :分布式培訓
Ray的優勢
- 更省時,高效
普通的執行方式是這樣的:
Ray:
Ray工作原理
該圖片引用來自參考文獻1:
安裝Ray(在所有節點上安裝)
pip3 install ray
部署Ray集群
1.部署head節點
手動在head節點上啟動:
firewall-cmd --add-port=6379/tcp ray start --head --redis-port=6379
在這個節點上啟動Ray。您可以通過調用向集群添加其他節點:
(Started Ray on this node. You can add additional nodes to the cluster by calling)
您可以通過運行Python將一個驅動程序連接到集群
(from the node you wish to add. You can connect a driver to the cluster from Python by running
)
如果從不同的機器連接有問題,請檢查防火墻的配置是否正確。如果希望終止已啟動的進程,請運行
(If you have trouble connecting from a different machine, check that your firewall is configured properly. If you wish to terminate the processes that have been started, run
)
2.部署worker節點
注意:這里的ip 192.168.2.220 是步驟1中head節點的ip
firewall-cmd --add-port=6379/tcp ray start --redis-address 192.168.2.220:6379日志存放目錄:
/tmp/ray
例子-python Ray集群
# -*- coding: utf-8 -*-
import time
import ray
ray.init(redis_address="192.168.2.220:6379")def f1():time.sleep(1)@ray.remote
def f2():time.sleep(1)#以下需要十秒。
time1=time.time()
[ f1() for _ in range(50)]
print(time.time()-time1)#以下需要一秒(假設系統至少有10個CPU)。
time2=time.time()
ray.get([ f2.remote() for _ in range(50)])
print(time.time()-time2)
如上述博客有任何錯誤或者疑問,請加VX:1755337994,及時告知!萬分感激!?
總結
以上是生活随笔為你收集整理的Ray集群搭建 Python Demo的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C语言小白适合入门的项目——扫雷
- 下一篇: python-视频分帧多帧合成视频