Repository navigation
[Serve][1/5] Expose backend HTTP endpoint metadata - #62667
kouroshHakha merged 16 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a "direct ingress" mechanism for Ray Serve, allowing users to register custom ASGI apps that bypass the standard request handling pipeline. Key changes include the addition of a _DirectIngressRegistry for tracking endpoints, the set_asgi_app API in the context module, and logic within the Replica class to allocate ports and start the custom HTTP server. Feedback focuses on avoiding blocking ray.get calls within the asynchronous replica environment, managing the lifecycle of the registry actor to prevent resource leaks, and removing unused code related to body chunk logging.
Add a generic Serve-level primitive that allows any deployment to register a custom ASGI app on its replica's direct ingress HTTP port. This enables the "ingress bypass" pattern where a proxy routes requests directly to replica-hosted ASGI apps, bypassing the standard Serve request pipeline. Key changes: - context.py: set_asgi_app(), inc/dec_num_ongoing_requests() callbacks - replica.py: deferred custom ASGI app lifecycle, counting middleware, _DirectIngressRegistry for endpoint discovery - common.py: direct_ingress_http_port on RunningReplicaInfo - deployment_state.py: plumb direct_ingress_http_port through - replica_wrapper.py: direct_ingress_endpoint property - handle.py: get_request_router() for local routing decisions Signed-off-by: Seiji Eicher <[email protected]>
8bd37f4 to
72fb5ac
Compare
- Remove _DirectIngressRegistry and all its usage (never read by any downstream PR; endpoint discovery uses replica_wrapper instead) - Replace blocking ray.get with asyncio.gather for http/grpc options - Remove unused first_body_chunk_logged tracking Signed-off-by: Seiji Eicher <[email protected]>
The counting middleware in _maybe_start_direct_ingress_servers already handles request counting directly. The context-level callbacks were never called by anything in the stack. Signed-off-by: Seiji Eicher <[email protected]>
The retry-loop for port allocation + server start was duplicated between _start_direct_ingress_for_custom_app and the nested function inside _maybe_start_direct_ingress_servers. Extract it as a proper method so both paths share the same implementation. Signed-off-by: Seiji Eicher <[email protected]>
Delete _start_direct_ingress_for_custom_app, _replica_initialized flag, and the branching callback. set_asgi_app() just stores the app; the existing _maybe_start_direct_ingress_servers() handles everything at init time. Also make set_asgi_app() sync and remove the _allocate_and_start_server extraction (revert to original nested fn). Signed-off-by: Seiji Eicher <[email protected]>
Replace the set_asgi_app() context callback with the standard Serve convention: user callable sets self.direct_ingress_app during __init__ or start(), and the Replica discovers it via getattr (same pattern as check_health, reconfigure, etc.). Removes context.py from this PR. Signed-off-by: Seiji Eicher <[email protected]>
…60865 Rename to _get_request_router and add TODO to migrate to DeploymentHandle.choose_replica() once ray-project#60865 lands. Signed-off-by: Seiji Eicher <[email protected]>
- test_custom_direct_ingress_app: verifies a deployment that sets self.direct_ingress_app gets a direct ingress port and serves the custom ASGI app on it - test_custom_direct_ingress_app_without_global_flag: verifies the custom app path works even without RAY_SERVE_ENABLE_DIRECT_INGRESS Signed-off-by: Seiji Eicher <[email protected]>
Benchmarks showed no measurable overhead from the standard Serve ASGI pipeline (~0.16ms TTFT difference). Replace the custom ASGI app mechanism with a simple opt-in: non-ingress deployments set self.enable_direct_ingress = True to get a direct ingress port serving the standard Serve handler. Remove set_asgi_app, context callbacks, counting middleware, and _get_request_router. Signed-off-by: Seiji Eicher <[email protected]>
LLMServer will be the ingress deployment so it gets direct ingress ports naturally. No guard clause changes needed. PR 1 is now just the metadata plumbing to expose direct_ingress_http_port through RunningReplicaInfo and RunningReplica.direct_ingress_endpoint. Signed-off-by: Seiji Eicher <[email protected]>
- Guard against falsy (0) port values with `or None` - Include direct_ingress_http_port in RunningReplicaInfo hash so long-poll broadcasts updates if the port changes - Tighten return type to Optional[Tuple[str, int]] Signed-off-by: Seiji Eicher <[email protected]>
Signed-off-by: Seiji Eicher <[email protected]>
d0f59cb to
4205bc2
Compare
Signed-off-by: Seiji Eicher <[email protected]>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces the backend_http_port field to RunningReplicaInfo and adds a backend_http_endpoint property to ReplicaWrapper to expose the host and port of a replica's HTTP server. The feedback identifies that the hash calculation for RunningReplicaInfo should also include node_ip and the gRPC port to ensure network changes trigger necessary updates. Additionally, a suggestion was made to ensure both host and port are present in backend_http_endpoint to avoid type hint violations.
Signed-off-by: Seiji Eicher <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 338959e. Configure here.
| multiplexed_model_ids=self.multiplexed_model_ids, | ||
| routing_stats=self.routing_stats, | ||
| port=self._actor._internal_grpc_port, | ||
| backend_http_port=self._actor._http_port or None, |
There was a problem hiding this comment.
Falsy port value silently converted to None
Low Severity
self._actor._http_port or None uses truthiness to coerce the value, which means a legitimate port value of 0 would be silently converted to None. The adjacent line passes self._actor._internal_grpc_port directly without or None, even though both attributes share the same lifecycle (None when unset, positive int when allocated). The or None is both redundant (when the value is already None) and subtly incorrect (it would suppress a valid falsy port), and is inconsistent with the established pattern.
Reviewed by Cursor Bugbot for commit 338959e. Configure here.
Fixes AttributeError in test_deployment_state.py unit tests after backend_http_port was added to DeploymentReplica.get_running_replica_info(). Signed-off-by: Seiji Eicher <[email protected]>
Signed-off-by: Seiji Eicher <[email protected]>
Signed-off-by: Seiji Eicher <[email protected]>


Why this is needed
Later in the stack,
/internal/routereturns areplica_id, and the controller / HAProxy layers need to turn that chosen replica into a concrete backendhost:port. Replica-owned backend HTTP servers already exist, but their ports are only local runtime state on the replica actor; this PR exposes that endpoint information throughRunningReplicaInfo/RunningReplicasoreplica_id -> backend host:portresolution becomes possible.Summary
backend_http_porttoRunningReplicaInfoDeploymentReplica.get_running_replica_info()so controller and proxy layers can resolve a chosen replica to its backend HTTP portRunningReplica.backend_http_endpointas a convenience(host, port)accessor for backend-HTTP-capable replicasRunningReplicaInfohashing andRunningReplica.update_replica_info()refreshing the derived endpointThis PR is only the metadata substrate. It does not add routing or change request flow by itself.
Stack: this -> #62680 -> #62668 -> #62669 -> #62670
Test plan
python/ray/serve/tests/unit/test_common.pypython/ray/serve/tests/test_actor_replica_wrapper.pypython -m py_compileon the edited filesgit diff --checkpytestfrom the detached PR worktreerayfrom the PR worktree fails on missing built_raylet