Skip to content
New issue

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

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

Already on GitHub? # to your account

[serve] Warn about upcoming change to run sync code on executor thread #44403

Closed
edoakes opened this issue Apr 2, 2024 · 0 comments · Fixed by #48897
Closed

[serve] Warn about upcoming change to run sync code on executor thread #44403

edoakes opened this issue Apr 2, 2024 · 0 comments · Fixed by #48897
Assignees
Labels
enhancement Request for new feature and/or capability P1 Issue that should be fixed within a few weeks ray-2.11 serve Ray Serve Related Issue

Comments

@edoakes
Copy link
Collaborator

edoakes commented Apr 2, 2024

Follow fastapi semantic. This is a breaking behavior change so we will need to warn at least a release ahead.

@edoakes edoakes added enhancement Request for new feature and/or capability P1 Issue that should be fixed within a few weeks ray-2.11 labels Apr 2, 2024
@edoakes edoakes self-assigned this Apr 2, 2024
@anyscalesam anyscalesam added the serve Ray Serve Related Issue label Jun 21, 2024
@zcin zcin closed this as completed in 0f2c62c Nov 26, 2024
jecsand838 pushed a commit to jecsand838/ray that referenced this issue Dec 4, 2024
## Why are these changes needed?

Adds a feature flag to run sync user-defined methods in a threadpool by
default. This matches the existing behavior when using a FastAPI
ingress.

This should address a lot of user confusion and make it easier to write
performant code by default. For example, just sticking a torch model
call in a sync method will now provide reasonable performance out of the
box.

However, there may be some existing user code that is not thread safe,
so we need to do a gentle migration. This PR introduces the behavior
behind a feature flag and warns users about the upcoming change and how
to opt into the new behavior or maintain existing behavior once it does
(just adding `async def` will do it).

I've opted to set the max thread pool size to `max_ongoing_requests`,
which seems like a reasonable policy. If needed we can add a user-facing
API for this in the future.

TODO before merging:

- [x] Get it working for sync generators.
- [x] Add warning for default change (people can keep behavior by
changing to async def).
- [x] Add/update UserCallableWrapper tests.
- [x] Add/update some integration tests (verify that request context is
set correctly!).
- [x] Set maximum thread pool size.

## Related issue number

Closes ray-project#44354
Closes ray-project#44403
Closes ray-project#48903

---------

Signed-off-by: Edward Oakes <ed.nmi.oakes@gmail.com>
Signed-off-by: Connor Sanders <connor@elastiflow.com>
dentiny pushed a commit to dentiny/ray that referenced this issue Dec 7, 2024
## Why are these changes needed?

Adds a feature flag to run sync user-defined methods in a threadpool by
default. This matches the existing behavior when using a FastAPI
ingress.

This should address a lot of user confusion and make it easier to write
performant code by default. For example, just sticking a torch model
call in a sync method will now provide reasonable performance out of the
box.

However, there may be some existing user code that is not thread safe,
so we need to do a gentle migration. This PR introduces the behavior
behind a feature flag and warns users about the upcoming change and how
to opt into the new behavior or maintain existing behavior once it does
(just adding `async def` will do it).

I've opted to set the max thread pool size to `max_ongoing_requests`,
which seems like a reasonable policy. If needed we can add a user-facing
API for this in the future.

TODO before merging:

- [x] Get it working for sync generators.
- [x] Add warning for default change (people can keep behavior by
changing to async def).
- [x] Add/update UserCallableWrapper tests.
- [x] Add/update some integration tests (verify that request context is
set correctly!).
- [x] Set maximum thread pool size.

## Related issue number

Closes ray-project#44354
Closes ray-project#44403
Closes ray-project#48903

---------

Signed-off-by: Edward Oakes <ed.nmi.oakes@gmail.com>
Signed-off-by: hjiang <dentinyhao@gmail.com>
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement Request for new feature and/or capability P1 Issue that should be fixed within a few weeks ray-2.11 serve Ray Serve Related Issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants