[serve] Add option to not start HTTP servers (#11627)

This commit is contained in:
Edward Oakes
2020-12-02 16:49:34 -06:00
committed by GitHub
parent a5c846c83b
commit 8058c1eb54
3 changed files with 29 additions and 11 deletions
+12 -11
View File
@@ -399,7 +399,7 @@ def start(detached: bool = False,
http_host (str): Host for HTTP servers to listen on. Defaults to
"127.0.0.1". To expose Serve publicly, you probably want to set
this to "0.0.0.0". One HTTP server will be started on each node in
the Ray cluster.
the Ray cluster. To not start HTTP servers, set this to None.
http_port (int): Port for HTTP server. Defaults to 8000.
http_middlewares (list): A list of Starlette middlewares that will be
applied to the HTTP servers in the cluster.
@@ -435,16 +435,17 @@ def start(detached: bool = False,
http_middlewares,
detached=detached)
futures = []
for node_id in ray.state.node_ids():
future = block_until_http_ready.options(
num_cpus=0, resources={
node_id: 0.01
}).remote(
"http://{}:{}/-/routes".format(http_host, http_port),
timeout=HTTP_PROXY_TIMEOUT)
futures.append(future)
ray.get(futures)
if http_host is not None:
futures = []
for node_id in ray.state.node_ids():
future = block_until_http_ready.options(
num_cpus=0, resources={
node_id: 0.01
}).remote(
"http://{}:{}/-/routes".format(http_host, http_port),
timeout=HTTP_PROXY_TIMEOUT)
futures.append(future)
ray.get(futures)
return Client(controller, controller_name, detached=detached)
+3
View File
@@ -329,6 +329,9 @@ class ActorStateReconciler:
def _start_routers_if_needed(self, http_host: str, http_port: str,
http_middlewares: List[Any]) -> None:
"""Start a router on every node if it doesn't already exist."""
if http_host is None:
return
for node_id, node_resource in get_all_node_ids():
if node_id in self.routers_cache:
continue
+14
View File
@@ -180,6 +180,20 @@ def test_reject_duplicate_endpoint_and_route(serve_instance):
client.create_endpoint("test", backend="backend2", route="/test")
def test_no_http(serve_instance):
client = serve.start(http_host=None)
assert len(ray.get(client._controller.get_routers.remote())) == 0
def hello(*args):
return "hello"
client.create_backend("backend", hello)
client.create_endpoint("endpoint", backend="backend")
assert ray.get(client.get_handle("endpoint").remote()) == "hello"
def test_set_traffic_missing_data(serve_instance):
client = serve_instance