Skip to content

Revert "[Serve] Set RAY_SERVE_RUN_SYNC_IN_THREADPOOL=1 to run sync in… - #61369

Merged
abrarsheikh merged 1 commit into
ray-project:masterfrom
akyang-anyscale:alexyang/revert-sync-threadpool
Feb 26, 2026
Merged

abrarsheikh merged 1 commit into
ray-project:masterfrom
akyang-anyscale:alexyang/revert-sync-threadpool

Conversation

@akyang-anyscale

Copy link
Copy Markdown
Contributor

… threadpool by default (#61229)"

This reverts commit 9e1fa2e. Enabling the flag by default introduces a significant perf regression for lightweight workloads that are sensitive to context switching and that do not take full advantage of offloading work from python. will post a RFC for community feedback before making this the default

Thank you for contributing to Ray! 🚀
Please review the Ray Contribution Guide before opening a pull request.

⚠️ Remove these instructions before submitting your PR.

💡 Tip: Mark as draft if you want early feedback, or ready for review when it's complete.

Description

Briefly describe what this PR accomplishes and why it's needed.

Related issues

Link related issues: "Fixes #1234", "Closes #1234", or "Related to #1234".

Additional information

Optional: Add implementation details, API changes, usage examples, screenshots, etc.

@akyang-anyscale
akyang-anyscale requested a review from a team as a code owner February 26, 2026 20:13
@akyang-anyscale akyang-anyscale added the go add ONLY when ready to merge, run all tests label Feb 26, 2026
… threadpool by default (ray-project#61229)"

This reverts commit 9e1fa2e.

Signed-off-by: akyang-anyscale <[email protected]>
@akyang-anyscale
akyang-anyscale force-pushed the alexyang/revert-sync-threadpool branch from 9911b5e to 000b282 Compare February 26, 2026 20:14

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request reverts the default behavior of running synchronous methods in a threadpool (RAY_SERVE_RUN_SYNC_IN_THREADPOOL=1) back to running them on the event loop (RAY_SERVE_RUN_SYNC_IN_THREADPOOL=0), citing performance regressions. The changes correctly update the default flag value, adjust documentation to reflect the new default and guide users on opting into the threadpool behavior, and modify tests to explicitly cover the non-default case. The revert appears to be complete and correct. I have one minor suggestion for a typo in the documentation.

Both FastAPI and Serve dispatch `def` methods to threadpool.
Important differences:

- FastAPI always dispatches `def` endpoints to a threadpool.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

There's a minor typo here with a double space after FastAPI. It should be a single space for better readability.

Suggested change
- FastAPI always dispatches `def` endpoints to a threadpool.
- FastAPI always dispatches `def` endpoints to a threadpool.

@abrarsheikh
abrarsheikh merged commit c69f1c0 into ray-project:master Feb 26, 2026
3 checks passed
eicherseiji added a commit that referenced this pull request Sep 29, 2026
## Description

Run synchronous deployment methods in a thread pool by default so
blocking synchronous I/O does not block the replica event loop.
`RAY_SERVE_RUN_SYNC_IN_THREADPOOL=0` retains the legacy behavior for
deployments whose shared state is not thread-safe.

| Environment variable | `master` | After this PR |
| --- | --- | --- |
| `RAY_SERVE_RUN_SYNC_IN_THREADPOOL` | OFF | ON |

The opt-in warning has been emitted since
[#48897](#48897) merged on
November 26, 2024—667 days (about 22 months) before this default swap.
This provided an extended migration period for users to make synchronous
deployment code thread-safe or convert it to `async def`.

The documentation now describes thread safety requirements and the
opt-out. This default was previously enabled in
[#61229](#61229) and reverted in
[#61369](#61369).

## Related PRs

These default changes are independent and can merge in any order:

- [#66432 Enable HAProxy by default on
Linux](#66432)
- [#66434 Select request body forwarding by
router](#66434)
- [#66435 Apply Serve LLM replica performance
defaults](#66435)

## Tests

- `RAY_USE_UVLOOP=0 python -m pytest -q
python/ray/serve/tests/test_replica_sync_methods.py`: 9 passed. The
executor-introspection cases target the standard asyncio loop used by
this Bazel test.
- Updated the thread-pool test target description
- Pre-commit, including Ruff, Black, Buildifier, mypy, Pyrefly, docs
style, and import-order checks

## Duplicate search

I searched open Ray PRs for this environment variable and found no
active duplicate.

## AI assistance

AI assistance was used for implementation and testing. The generated
changes and test results require submitter review before the PR is
marked ready.

Signed-off-by: Seiji Eicher <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
## Description

Run synchronous deployment methods in a thread pool by default so
blocking synchronous I/O does not block the replica event loop.
`RAY_SERVE_RUN_SYNC_IN_THREADPOOL=0` retains the legacy behavior for
deployments whose shared state is not thread-safe.

| Environment variable | `master` | After this PR |
| --- | --- | --- |
| `RAY_SERVE_RUN_SYNC_IN_THREADPOOL` | OFF | ON |

The opt-in warning has been emitted since
[ray-project#48897](ray-project#48897) merged on
November 26, 2024—667 days (about 22 months) before this default swap.
This provided an extended migration period for users to make synchronous
deployment code thread-safe or convert it to `async def`.

The documentation now describes thread safety requirements and the
opt-out. This default was previously enabled in
[ray-project#61229](ray-project#61229) and reverted in
[ray-project#61369](ray-project#61369).

## Related PRs

These default changes are independent and can merge in any order:

- [ray-project#66432 Enable HAProxy by default on
Linux](ray-project#66432)
- [ray-project#66434 Select request body forwarding by
router](ray-project#66434)
- [ray-project#66435 Apply Serve LLM replica performance
defaults](ray-project#66435)

## Tests

- `RAY_USE_UVLOOP=0 python -m pytest -q
python/ray/serve/tests/test_replica_sync_methods.py`: 9 passed. The
executor-introspection cases target the standard asyncio loop used by
this Bazel test.
- Updated the thread-pool test target description
- Pre-commit, including Ruff, Black, Buildifier, mypy, Pyrefly, docs
style, and import-order checks

## Duplicate search

I searched open Ray PRs for this environment variable and found no
active duplicate.

## AI assistance

AI assistance was used for implementation and testing. The generated
changes and test results require submitter review before the PR is
marked ready.

Signed-off-by: Seiji Eicher <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ray fails to serialize self-reference objects

2 participants