diff --git a/python/ray/serve/api.py b/python/ray/serve/api.py index 7cec895dc..c5f887c88 100644 --- a/python/ray/serve/api.py +++ b/python/ray/serve/api.py @@ -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) diff --git a/python/ray/serve/controller.py b/python/ray/serve/controller.py index 91ba09844..3176a6321 100644 --- a/python/ray/serve/controller.py +++ b/python/ray/serve/controller.py @@ -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 diff --git a/python/ray/serve/tests/test_api.py b/python/ray/serve/tests/test_api.py index 93ea187f4..5d2bc76c0 100644 --- a/python/ray/serve/tests/test_api.py +++ b/python/ray/serve/tests/test_api.py @@ -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