ray - 在前台的 docker 容器中运行 ray 服务,而不是守护程序模式
问题描述
我正在运行 Ray Serve 来托管光线远程功能的 HTTP API。有没有比下面更好的方法在前台运行 Ray Serve(即不是守护程序模式)。代码直接取自 ray serve 示例:
import os
import time
import ray.serve
ray.serve.init(blocking=True, http_host="0.0.0.0", ray_init_kwargs={
'webui_host': '0.0.0.0',
'redis_password': os.getenv('RAY_REDIS_PASSWORD'),
})
ray.serve.create_endpoint("my_endpoint", "/echo")
def echo_v1(flask_request, response="hello from python!"):
return "1"
ray.serve.create_backend(echo_v1, "echo:v1")
ray.serve.link("my_endpoint", "echo:v1")
# Make sure the Docker container doesn't exit
while True:
time.sleep(2)
没有最后一部分:
# Make sure the Docker container doesn't exit
while True:
time.sleep(2)
Docker 容器将立即退出。
解决方案
From the ray documentation as well (https://docs.ray.io/en/latest/serve/deployment.html), you can start a server beforehand with ray start --head
and connect to the server with ray.init(address="auto")
:
ray start --head
import ray
from ray import serve
# This will connect to the running Ray cluster.
ray.init(address="auto", namespace="serve")
@serve.deployment
def my_func(request):
return "hello"
my_func.deploy()
推荐阅读
- python - Tkinter:检测一个正在运行的进程并在一个进程运行时锁定所有其他按钮?
- javascript - nodejs Worker_thread vs Promise.all 或 allSettled()
- c# - 多对多查询单个数据关系
- webrtc - TURN 服务器:对于给定的网络,总是或从不需要,还是不可预测地需要?
- git - GitHub 可以归类为版本控制系统还是 Git 的 GUI?
- database - 在主窗体和子窗体中使用字段值(数字)与日期字段(日期)进行计算,以将字段值(数字)添加为新总计的天数
- datetime - 什么是改变时区长生不老药的正确方法
- c++ - 如何将 vscode 配置为 C++ 项目?
- automated-tests - 空手道:使用数据驱动的嵌入式模板方法进行 API 测试
- encryption - 未找到密码算法“AES-256-GCM”(OpenVPN 错误)