Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[serve] Add experimental support for StreamingResponse using RayObjectRefGenerator #35720

Merged
merged 108 commits into from
May 26, 2023

Conversation

edoakes
Copy link
Contributor

@edoakes edoakes commented May 24, 2023

Why are these changes needed?

Adds experimental support for using StreamingResponses to stream intermediate results back to the client. This is currently gated behind a feature flag (must set RAY_SERVE_ENABLE_EXPERIMENTAL_STREAMING=1.

This is implemented by using the Ray ObjectRefStreamingGenerator interface. When the feature flag is on, the HTTP proxy will use num_returns="streaming" for all calls to downstream replicas. The replica code has been modified to incrementally yield raw ASGI messages back to the HTTP proxy.

Known limitations & follow-ups (to be addressed before a non-experimental release):

Related issue number

#34266

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
    • I've added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it in doc/source/tune/api/ under the
      corresponding .rst file.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

Signed-off-by: SangBin Cho <[email protected]>
Signed-off-by: SangBin Cho <[email protected]>
Signed-off-by: SangBin Cho <[email protected]>
Signed-off-by: SangBin Cho <[email protected]>
Signed-off-by: SangBin Cho <[email protected]>
Signed-off-by: SangBin Cho <[email protected]>
Signed-off-by: SangBin Cho <[email protected]>
Signed-off-by: SangBin Cho <[email protected]>
Signed-off-by: SangBin Cho <[email protected]>
This reverts commit 05f468a.

Signed-off-by: SangBin Cho <[email protected]>
Signed-off-by: SangBin Cho <[email protected]>
Signed-off-by: SangBin Cho <[email protected]>
Signed-off-by: SangBin Cho <[email protected]>
Signed-off-by: SangBin Cho <[email protected]>
Signed-off-by: SangBin Cho <[email protected]>
Signed-off-by: SangBin Cho <[email protected]>
Signed-off-by: SangBin Cho <[email protected]>
never_set_event = asyncio.Event()
await never_set_event.wait()
If the result is already a Response type, it will be sent directly. Else it
will be converted to our custom Response type that handles serialization for
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
will be converted to our custom Response type that handles serialization for
is converted to a custom Response type that handles serialization for

Signed-off-by: Edward Oakes <[email protected]>
python/ray/serve/api.py Outdated Show resolved Hide resolved
@angelinalg
Copy link
Contributor

Tip: Use the Add suggestion to batch to combine multiple suggestions into a single commit.

Copy link
Contributor

@angelinalg angelinalg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Made some minor suggestions.

Signed-off-by: Edward Oakes <[email protected]>
@edoakes
Copy link
Contributor Author

edoakes commented May 25, 2023

Tip: Use the Add suggestion to batch to combine multiple suggestions into a single commit.

Oh wow that is a revelation 😂

@edoakes edoakes merged commit 6ae6920 into ray-project:master May 26, 2023
edoakes added a commit to edoakes/ray that referenced this pull request May 26, 2023
…jectRefGenerator` (ray-project#35720)

Adds experimental support for using `StreamingResponse`s to stream intermediate results back to the client. This is currently gated behind a feature flag (must set `RAY_SERVE_ENABLE_EXPERIMENTAL_STREAMING=1`.

This is implemented by using the Ray `ObjectRefStreamingGenerator` interface. When the feature flag is on, the HTTP proxy will use `num_returns="streaming"` for _all_ calls to downstream replicas. The replica code has been modified to incrementally yield raw ASGI messages back to the HTTP proxy.

Known limitations & follow-ups (to be addressed before a non-experimental release):

- Minor performance regression due to an extra RPC from streaming protocol (see the microbenchmark results posted on ray-project#35468). Most of this should be able to be optimized away before turning this on by default.
- Streaming is not yet possible using the `ServeHandle` interface: ray-project#35777
- `max_concurrent_queries` is not respected by the HTTP proxy when streaming is enabled; we do simple round-robin instead: ray-project#35778
- The timeout set in the HTTP proxy does not apply to streaming responses: ray-project#35779
edoakes added a commit to edoakes/ray that referenced this pull request May 26, 2023
…jectRefGenerator` (ray-project#35720)

Adds experimental support for using `StreamingResponse`s to stream intermediate results back to the client. This is currently gated behind a feature flag (must set `RAY_SERVE_ENABLE_EXPERIMENTAL_STREAMING=1`.

This is implemented by using the Ray `ObjectRefStreamingGenerator` interface. When the feature flag is on, the HTTP proxy will use `num_returns="streaming"` for _all_ calls to downstream replicas. The replica code has been modified to incrementally yield raw ASGI messages back to the HTTP proxy.

Known limitations & follow-ups (to be addressed before a non-experimental release):

- Minor performance regression due to an extra RPC from streaming protocol (see the microbenchmark results posted on ray-project#35468). Most of this should be able to be optimized away before turning this on by default.
- Streaming is not yet possible using the `ServeHandle` interface: ray-project#35777
- `max_concurrent_queries` is not respected by the HTTP proxy when streaming is enabled; we do simple round-robin instead: ray-project#35778
- The timeout set in the HTTP proxy does not apply to streaming responses: ray-project#35779

Signed-off-by: Edward Oakes <[email protected]>
edoakes added a commit to edoakes/ray that referenced this pull request May 26, 2023
…jectRefGenerator` (ray-project#35720)

Adds experimental support for using `StreamingResponse`s to stream intermediate results back to the client. This is currently gated behind a feature flag (must set `RAY_SERVE_ENABLE_EXPERIMENTAL_STREAMING=1`.

This is implemented by using the Ray `ObjectRefStreamingGenerator` interface. When the feature flag is on, the HTTP proxy will use `num_returns="streaming"` for _all_ calls to downstream replicas. The replica code has been modified to incrementally yield raw ASGI messages back to the HTTP proxy.

Known limitations & follow-ups (to be addressed before a non-experimental release):

- Minor performance regression due to an extra RPC from streaming protocol (see the microbenchmark results posted on ray-project#35468). Most of this should be able to be optimized away before turning this on by default.
- Streaming is not yet possible using the `ServeHandle` interface: ray-project#35777
- `max_concurrent_queries` is not respected by the HTTP proxy when streaming is enabled; we do simple round-robin instead: ray-project#35778
- The timeout set in the HTTP proxy does not apply to streaming responses: ray-project#35779

Signed-off-by: Edward Oakes <[email protected]>
edoakes added a commit to edoakes/ray that referenced this pull request May 26, 2023
…jectRefGenerator` (ray-project#35720)

Adds experimental support for using `StreamingResponse`s to stream intermediate results back to the client. This is currently gated behind a feature flag (must set `RAY_SERVE_ENABLE_EXPERIMENTAL_STREAMING=1`.

This is implemented by using the Ray `ObjectRefStreamingGenerator` interface. When the feature flag is on, the HTTP proxy will use `num_returns="streaming"` for _all_ calls to downstream replicas. The replica code has been modified to incrementally yield raw ASGI messages back to the HTTP proxy.

Known limitations & follow-ups (to be addressed before a non-experimental release):

- Minor performance regression due to an extra RPC from streaming protocol (see the microbenchmark results posted on ray-project#35468). Most of this should be able to be optimized away before turning this on by default.
- Streaming is not yet possible using the `ServeHandle` interface: ray-project#35777
- `max_concurrent_queries` is not respected by the HTTP proxy when streaming is enabled; we do simple round-robin instead: ray-project#35778
- The timeout set in the HTTP proxy does not apply to streaming responses: ray-project#35779

Signed-off-by: Edward Oakes <[email protected]>
ArturNiederfahrenhorst pushed a commit that referenced this pull request May 26, 2023
…jectRefGenerator` (#35720) (#35811)

Adds experimental support for using `StreamingResponse`s to stream intermediate results back to the client. This is currently gated behind a feature flag (must set `RAY_SERVE_ENABLE_EXPERIMENTAL_STREAMING=1`.

This is implemented by using the Ray `ObjectRefStreamingGenerator` interface. When the feature flag is on, the HTTP proxy will use `num_returns="streaming"` for _all_ calls to downstream replicas. The replica code has been modified to incrementally yield raw ASGI messages back to the HTTP proxy.

Known limitations & follow-ups (to be addressed before a non-experimental release):

- Minor performance regression due to an extra RPC from streaming protocol (see the microbenchmark results posted on #35468). Most of this should be able to be optimized away before turning this on by default.
- Streaming is not yet possible using the `ServeHandle` interface: #35777
- `max_concurrent_queries` is not respected by the HTTP proxy when streaming is enabled; we do simple round-robin instead: #35778
- The timeout set in the HTTP proxy does not apply to streaming responses: #35779

Signed-off-by: Edward Oakes <[email protected]>
edoakes added a commit that referenced this pull request Jun 12, 2023
Extends #35720 to also add support for websockets (as well as detecting HTTP disconnects).
scv119 pushed a commit to scv119/ray that referenced this pull request Jun 16, 2023
…jectRefGenerator` (ray-project#35720)

Adds experimental support for using `StreamingResponse`s to stream intermediate results back to the client. This is currently gated behind a feature flag (must set `RAY_SERVE_ENABLE_EXPERIMENTAL_STREAMING=1`.

This is implemented by using the Ray `ObjectRefStreamingGenerator` interface. When the feature flag is on, the HTTP proxy will use `num_returns="streaming"` for _all_ calls to downstream replicas. The replica code has been modified to incrementally yield raw ASGI messages back to the HTTP proxy.

Known limitations & follow-ups (to be addressed before a non-experimental release):

- Minor performance regression due to an extra RPC from streaming protocol (see the microbenchmark results posted on ray-project#35468). Most of this should be able to be optimized away before turning this on by default.
- Streaming is not yet possible using the `ServeHandle` interface: ray-project#35777
- `max_concurrent_queries` is not respected by the HTTP proxy when streaming is enabled; we do simple round-robin instead: ray-project#35778
- The timeout set in the HTTP proxy does not apply to streaming responses: ray-project#35779
arvind-chandra pushed a commit to lmco/ray that referenced this pull request Aug 31, 2023
…jectRefGenerator` (ray-project#35720)

Adds experimental support for using `StreamingResponse`s to stream intermediate results back to the client. This is currently gated behind a feature flag (must set `RAY_SERVE_ENABLE_EXPERIMENTAL_STREAMING=1`.

This is implemented by using the Ray `ObjectRefStreamingGenerator` interface. When the feature flag is on, the HTTP proxy will use `num_returns="streaming"` for _all_ calls to downstream replicas. The replica code has been modified to incrementally yield raw ASGI messages back to the HTTP proxy.

Known limitations & follow-ups (to be addressed before a non-experimental release):

- Minor performance regression due to an extra RPC from streaming protocol (see the microbenchmark results posted on ray-project#35468). Most of this should be able to be optimized away before turning this on by default.
- Streaming is not yet possible using the `ServeHandle` interface: ray-project#35777
- `max_concurrent_queries` is not respected by the HTTP proxy when streaming is enabled; we do simple round-robin instead: ray-project#35778
- The timeout set in the HTTP proxy does not apply to streaming responses: ray-project#35779

Signed-off-by: e428265 <[email protected]>
arvind-chandra pushed a commit to lmco/ray that referenced this pull request Aug 31, 2023
Extends ray-project#35720 to also add support for websockets (as well as detecting HTTP disconnects).

Signed-off-by: e428265 <[email protected]>
glennmoy pushed a commit to beacon-biosignals/ray that referenced this pull request Sep 26, 2023
…jectRefGenerator` (ray-project#35720) (ray-project#35811)

Adds experimental support for using `StreamingResponse`s to stream intermediate results back to the client. This is currently gated behind a feature flag (must set `RAY_SERVE_ENABLE_EXPERIMENTAL_STREAMING=1`.

This is implemented by using the Ray `ObjectRefStreamingGenerator` interface. When the feature flag is on, the HTTP proxy will use `num_returns="streaming"` for _all_ calls to downstream replicas. The replica code has been modified to incrementally yield raw ASGI messages back to the HTTP proxy.

Known limitations & follow-ups (to be addressed before a non-experimental release):

- Minor performance regression due to an extra RPC from streaming protocol (see the microbenchmark results posted on ray-project#35468). Most of this should be able to be optimized away before turning this on by default.
- Streaming is not yet possible using the `ServeHandle` interface: ray-project#35777
- `max_concurrent_queries` is not respected by the HTTP proxy when streaming is enabled; we do simple round-robin instead: ray-project#35778
- The timeout set in the HTTP proxy does not apply to streaming responses: ray-project#35779

Signed-off-by: Edward Oakes <[email protected]>
glennmoy pushed a commit to beacon-biosignals/ray that referenced this pull request Sep 26, 2023
…jectRefGenerator` (ray-project#35720) (ray-project#35811)

Adds experimental support for using `StreamingResponse`s to stream intermediate results back to the client. This is currently gated behind a feature flag (must set `RAY_SERVE_ENABLE_EXPERIMENTAL_STREAMING=1`.

This is implemented by using the Ray `ObjectRefStreamingGenerator` interface. When the feature flag is on, the HTTP proxy will use `num_returns="streaming"` for _all_ calls to downstream replicas. The replica code has been modified to incrementally yield raw ASGI messages back to the HTTP proxy.

Known limitations & follow-ups (to be addressed before a non-experimental release):

- Minor performance regression due to an extra RPC from streaming protocol (see the microbenchmark results posted on ray-project#35468). Most of this should be able to be optimized away before turning this on by default.
- Streaming is not yet possible using the `ServeHandle` interface: ray-project#35777
- `max_concurrent_queries` is not respected by the HTTP proxy when streaming is enabled; we do simple round-robin instead: ray-project#35778
- The timeout set in the HTTP proxy does not apply to streaming responses: ray-project#35779

Signed-off-by: Edward Oakes <[email protected]>
glennmoy pushed a commit to beacon-biosignals/ray that referenced this pull request Sep 26, 2023
…jectRefGenerator` (ray-project#35720) (ray-project#35811)

Adds experimental support for using `StreamingResponse`s to stream intermediate results back to the client. This is currently gated behind a feature flag (must set `RAY_SERVE_ENABLE_EXPERIMENTAL_STREAMING=1`.

This is implemented by using the Ray `ObjectRefStreamingGenerator` interface. When the feature flag is on, the HTTP proxy will use `num_returns="streaming"` for _all_ calls to downstream replicas. The replica code has been modified to incrementally yield raw ASGI messages back to the HTTP proxy.

Known limitations & follow-ups (to be addressed before a non-experimental release):

- Minor performance regression due to an extra RPC from streaming protocol (see the microbenchmark results posted on ray-project#35468). Most of this should be able to be optimized away before turning this on by default.
- Streaming is not yet possible using the `ServeHandle` interface: ray-project#35777
- `max_concurrent_queries` is not respected by the HTTP proxy when streaming is enabled; we do simple round-robin instead: ray-project#35778
- The timeout set in the HTTP proxy does not apply to streaming responses: ray-project#35779

Signed-off-by: Edward Oakes <[email protected]>
glennmoy pushed a commit to beacon-biosignals/ray that referenced this pull request Sep 26, 2023
…jectRefGenerator` (ray-project#35720) (ray-project#35811)

Adds experimental support for using `StreamingResponse`s to stream intermediate results back to the client. This is currently gated behind a feature flag (must set `RAY_SERVE_ENABLE_EXPERIMENTAL_STREAMING=1`.

This is implemented by using the Ray `ObjectRefStreamingGenerator` interface. When the feature flag is on, the HTTP proxy will use `num_returns="streaming"` for _all_ calls to downstream replicas. The replica code has been modified to incrementally yield raw ASGI messages back to the HTTP proxy.

Known limitations & follow-ups (to be addressed before a non-experimental release):

- Minor performance regression due to an extra RPC from streaming protocol (see the microbenchmark results posted on ray-project#35468). Most of this should be able to be optimized away before turning this on by default.
- Streaming is not yet possible using the `ServeHandle` interface: ray-project#35777
- `max_concurrent_queries` is not respected by the HTTP proxy when streaming is enabled; we do simple round-robin instead: ray-project#35778
- The timeout set in the HTTP proxy does not apply to streaming responses: ray-project#35779

Signed-off-by: Edward Oakes <[email protected]>
glennmoy pushed a commit to beacon-biosignals/ray that referenced this pull request Sep 26, 2023
…jectRefGenerator` (ray-project#35720) (ray-project#35811)

Adds experimental support for using `StreamingResponse`s to stream intermediate results back to the client. This is currently gated behind a feature flag (must set `RAY_SERVE_ENABLE_EXPERIMENTAL_STREAMING=1`.

This is implemented by using the Ray `ObjectRefStreamingGenerator` interface. When the feature flag is on, the HTTP proxy will use `num_returns="streaming"` for _all_ calls to downstream replicas. The replica code has been modified to incrementally yield raw ASGI messages back to the HTTP proxy.

Known limitations & follow-ups (to be addressed before a non-experimental release):

- Minor performance regression due to an extra RPC from streaming protocol (see the microbenchmark results posted on ray-project#35468). Most of this should be able to be optimized away before turning this on by default.
- Streaming is not yet possible using the `ServeHandle` interface: ray-project#35777
- `max_concurrent_queries` is not respected by the HTTP proxy when streaming is enabled; we do simple round-robin instead: ray-project#35778
- The timeout set in the HTTP proxy does not apply to streaming responses: ray-project#35779

Signed-off-by: Edward Oakes <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants