mirror of
https://github.com/wassname/ray.git
synced 2026-07-04 05:35:55 +08:00
[Serve] Push route table updates to HTTP proxy (#7774)
This commit is contained in:
+17
-14
@@ -8,7 +8,7 @@ import numpy as np
|
||||
|
||||
import ray
|
||||
from ray.serve.constants import (DEFAULT_HTTP_HOST, DEFAULT_HTTP_PORT,
|
||||
SERVE_NURSERY_NAME)
|
||||
SERVE_MASTER_NAME)
|
||||
from ray.serve.global_state import GlobalState, start_initial_state
|
||||
from ray.serve.kv_store_service import SQLiteKVStore
|
||||
from ray.serve.task_runner import RayServeMixin, TaskRunnerActor
|
||||
@@ -114,9 +114,9 @@ def init(
|
||||
if not ray.is_initialized():
|
||||
ray.init(**ray_init_kwargs)
|
||||
|
||||
# Try to get serve nursery if there exists
|
||||
# Try to get serve master actor if it exists
|
||||
try:
|
||||
ray.util.get_actor(SERVE_NURSERY_NAME)
|
||||
ray.util.get_actor(SERVE_MASTER_NAME)
|
||||
global_state = GlobalState()
|
||||
return
|
||||
except ValueError:
|
||||
@@ -138,15 +138,16 @@ def init(
|
||||
def kv_store_connector(namespace):
|
||||
return SQLiteKVStore(namespace, db_path=kv_store_path)
|
||||
|
||||
nursery = start_initial_state(kv_store_connector)
|
||||
master = start_initial_state(kv_store_connector)
|
||||
|
||||
global_state = GlobalState(nursery)
|
||||
if start_server:
|
||||
global_state.init_or_get_http_server(host=http_host, port=http_port)
|
||||
global_state.init_or_get_router(
|
||||
global_state = GlobalState(master)
|
||||
router = global_state.init_or_get_router(
|
||||
queueing_policy=queueing_policy, policy_kwargs=policy_kwargs)
|
||||
global_state.init_or_get_metric_monitor(
|
||||
gc_window_seconds=gc_window_seconds)
|
||||
if start_server:
|
||||
global_state.init_or_get_http_proxy(
|
||||
host=http_host, port=http_port).set_router_handle.remote(router)
|
||||
|
||||
if start_server and blocking:
|
||||
block_until_http_ready("http://{}:{}/-/routes".format(
|
||||
@@ -168,6 +169,9 @@ def create_endpoint(endpoint_name, route=None, methods=["GET"]):
|
||||
methods = [m.upper() for m in methods]
|
||||
global_state.route_table.register_service(
|
||||
route, endpoint_name, methods=methods)
|
||||
ray.get(global_state.init_or_get_http_proxy().set_route_table.remote(
|
||||
global_state.route_table.list_service(
|
||||
include_methods=True, include_headless=False)))
|
||||
|
||||
|
||||
@_ensure_connected
|
||||
@@ -321,9 +325,9 @@ def _start_replica(backend_tag):
|
||||
# get actor creation kwargs
|
||||
actor_kwargs = backend_config.get_actor_creation_args(init_args)
|
||||
|
||||
# Create the runner in the nursery
|
||||
# Create the runner in the master actor
|
||||
[runner_handle] = ray.get(
|
||||
global_state.actor_nursery_handle.start_actor_with_creator.remote(
|
||||
global_state.master_actor_handle.start_actor_with_creator.remote(
|
||||
creator, actor_kwargs, replica_tag))
|
||||
|
||||
# Setup the worker
|
||||
@@ -347,15 +351,14 @@ def _remove_replica(backend_tag):
|
||||
|
||||
replica_tag = global_state.backend_table.remove_replica(backend_tag)
|
||||
[replica_handle] = ray.get(
|
||||
global_state.actor_nursery_handle.get_handle.remote(replica_tag))
|
||||
global_state.master_actor_handle.get_handle.remote(replica_tag))
|
||||
|
||||
# Remove the replica from metric monitor.
|
||||
ray.get(global_state.init_or_get_metric_monitor().remove_target.remote(
|
||||
replica_handle))
|
||||
|
||||
# Remove the replica from actor nursery.
|
||||
ray.get(
|
||||
global_state.actor_nursery_handle.remove_handle.remote(replica_tag))
|
||||
# Remove the replica from master actor.
|
||||
ray.get(global_state.master_actor_handle.remove_handle.remote(replica_tag))
|
||||
|
||||
# Remove the replica from router.
|
||||
# This will also destory the actor handle.
|
||||
|
||||
Reference in New Issue
Block a user