就地更新应用程序#
生产中的 Serve 应用程序可以通过更新配置文件中的设置并使用 serve deploy
命令重新部署来更新。在重新部署的配置文件中,您可以添加新的部署设置或删除旧的部署设置。这是因为 serve deploy
是幂等的,这意味着您的 Serve 应用程序的配置始终与您最近成功部署的配置匹配(或遵从),无论您之前部署过什么配置文件。
轻量级配置更新#
轻量级配置更新在不销毁和重新启动正在运行的部署副本的情况下对其进行修改,因此在部署更新时停机时间更少。对于每个部署,修改以下值被视为轻量级配置更新,并且不会销毁该部署的副本:
num_replicas
autoscaling_config
user_config
max_ongoing_requests
graceful_shutdown_timeout_s
graceful_shutdown_wait_loop_s
health_check_period_s
health_check_timeout_s
更新 user config#
本示例使用生产指南中的文本摘要和翻译应用程序。这两个独立的部署都包含一个 reconfigure()
方法。此方法允许您通过更新 user_config
对部署进行轻量级更新。
首先,让我们部署图。为本示例确保使用 CLI 命令 ray stop
停止任何之前的 Ray 集群:
$ ray start --head
$ serve deploy serve_config.yaml
然后向应用程序发送请求:
import requests
english_text = (
"It was the best of times, it was the worst of times, it was the age "
"of wisdom, it was the age of foolishness, it was the epoch of belief"
)
response = requests.post("http://127.0.0.1:8000/", json=english_text)
french_text = response.text
print(french_text)
# 'c'était le meilleur des temps, c'était le pire des temps .'
通过更改 Translator
user config 中的 language
属性,将文本翻译语言从法语更改为德语:
...
applications:
- name: default
route_prefix: /
import_path: text_ml:app
runtime_env:
pip:
- torch
- transformers
deployments:
- name: Translator
num_replicas: 1
user_config:
language: german
...
在不停止 Ray 集群的情况下,使用 serve deploy
重新部署应用程序:
$ serve deploy serve_config.yaml
...
我们可以使用 serve status
检查我们的部署。一旦应用程序的 status
返回到 RUNNING
,我们可以再尝试一次请求:
$ serve status
proxies:
cef533a072b0f03bf92a6b98cb4eb9153b7b7c7b7f15954feb2f38ec: HEALTHY
applications:
default:
status: RUNNING
message: ''
last_deployed_time_s: 1694041157.2211847
deployments:
Translator:
status: HEALTHY
replica_states:
RUNNING: 1
message: ''
Summarizer:
status: HEALTHY
replica_states:
RUNNING: 1
message: ''
语言已更新。现在返回的文本是德语而不是法语。
import requests
english_text = (
"It was the best of times, it was the worst of times, it was the age "
"of wisdom, it was the age of foolishness, it was the epoch of belief"
)
response = requests.post("http://127.0.0.1:8000/", json=english_text)
german_text = response.text
print(german_text)
# 'Es war die beste Zeit, es war die schlimmste Zeit .'
代码更新#
更改部署配置中的以下值将触发重新部署并重启该部署的所有副本。
ray_actor_options
placement_group_bundles
placement_group_strategy
更改以下应用程序级配置值也被视为代码更新,并且应用程序中的所有部署都将重启。
import_path
runtime_env
警告
尽管您可以通过使用不同的 import_path
和不同的 runtime_env
部署全新的部署图来更新您的 Serve 应用程序,但这在生产环境中是不推荐的。
大规模代码更新的最佳实践是启动一个新的 Ray 集群,使用 serve deploy
将更新后的代码部署到新集群,然后将流量从旧集群切换到新集群。