[core] Give io context concurrency hint#53642
Merged
edoakes merged 2 commits intoray-project:masterfrom Jun 11, 2025
Merged
Conversation
Signed-off-by: dayshah <dhyey2019@gmail.com>
Signed-off-by: dayshah <dhyey2019@gmail.com>
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR updates various components to use a new optional parameter in the instrumented_io_context constructor that indicates whether the IO context runs on a single thread for performance optimizations.
- Updated instrumented_io_context instantiations across several modules with the new running_on_single_thread parameter set to true.
- Modified both header and source implementations of instrumented_io_context to support the concurrency hint.
- Propagated the new parameter in all relevant files including main.cc, object manager, GCS components, core worker, file system monitor, client connection, IO service pool, and Python accessor.
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/ray/raylet/main.cc | Updated IO service instantiation to include single-thread flag. |
| src/ray/object_manager/plasma/store_runner.h | Added new parameter to main_service_ initialization. |
| src/ray/gcs/store_client/redis_store_client.cc | Updated IO service creation with concurrency hint flag. |
| src/ray/gcs/gcs_server/gcs_server_main.cc | Added the new parameter to main_service initialization. |
| src/ray/core_worker/task_event_buffer.h | Modified IO service initialization with the new single-thread flag. |
| src/ray/core_worker/core_worker_process.cc | Updated the IO service constructor call to include the new parameter. |
| src/ray/core_worker/core_worker.h | Updated IO service instantiation with concurrency hint indicator. |
| src/ray/common/file_system_monitor.h | Updated io_context initialization with the single-thread option. |
| src/ray/common/client_connection.cc | Adjusted lambda capture for stats_handle to allow move semantics. |
| src/ray/common/asio/io_service_pool.cc | Changed io_service creation to include the new flag for concurrency. |
| src/ray/common/asio/instrumented_io_context.h | Updated constructor declaration to accept a running_on_single_thread flag. |
| src/ray/common/asio/instrumented_io_context.cc | Amended constructor implementation to use the concurrency hint option. |
| src/ray/common/asio/asio_util.h | Updated io_service instantiation to include the single-thread parameter. |
| python/ray/includes/global_state_accessor.pxd | Instantiated io_service with the new concurrency hint parameter. |
edoakes
reviewed
Jun 10, 2025
Collaborator
edoakes
left a comment
There was a problem hiding this comment.
Looks fine to me -- run microbenchmarks to be sure?
Contributor
Author
ya looked at microbenchmarks, generally looks the same https://buildkite.com/ray-project/release/builds/45267#01975c4a-0082-4775-9414-3ea8c92995dc/553-673 |
edoakes
approved these changes
Jun 11, 2025
elliot-barn
pushed a commit
that referenced
this pull request
Jun 18, 2025
Most of our io_contexts are only run on a single thread. asio has a concurrency hint option to improve performance in this case, so I'm adding an optional parameter to the constructor if the io context is guaranteed to run on a single thread. Also serves as a source of truth for whether an io_context is only running from a single thread or multiple threads. This is for sure a premature optimization, but shouldn't hurt either way. What the boost io_context documentation says about the `1` option (we're on 1.81). https://www.boost.org/doc/libs/1_81_0/doc/html/boost_asio/overview/core/concurrency_hint.html > The implementation assumes that the io_context will be run from a single thread, and applies several optimisations based on this assumption. For example, when a handler is posted from within another handler, the new handler is added to a fast thread-local queue (with the consequence that the new handler is held back until the currently executing handler finishes). The io_context still provides full thread safety, and distinct I/O objects may be used from any thread. --------- Signed-off-by: dayshah <dhyey2019@gmail.com> Signed-off-by: elliot-barn <elliot.barnwell@anyscale.com>
elliot-barn
pushed a commit
that referenced
this pull request
Jul 2, 2025
Most of our io_contexts are only run on a single thread. asio has a concurrency hint option to improve performance in this case, so I'm adding an optional parameter to the constructor if the io context is guaranteed to run on a single thread. Also serves as a source of truth for whether an io_context is only running from a single thread or multiple threads. This is for sure a premature optimization, but shouldn't hurt either way. What the boost io_context documentation says about the `1` option (we're on 1.81). https://www.boost.org/doc/libs/1_81_0/doc/html/boost_asio/overview/core/concurrency_hint.html > The implementation assumes that the io_context will be run from a single thread, and applies several optimisations based on this assumption. For example, when a handler is posted from within another handler, the new handler is added to a fast thread-local queue (with the consequence that the new handler is held back until the currently executing handler finishes). The io_context still provides full thread safety, and distinct I/O objects may be used from any thread. --------- Signed-off-by: dayshah <dhyey2019@gmail.com> Signed-off-by: elliot-barn <elliot.barnwell@anyscale.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why are these changes needed?
Most of our io_contexts are only run on a single thread. asio has a concurrency hint option to improve performance in this case, so I'm adding an optional parameter to the constructor if the io context is guaranteed to run on a single thread. Also serves as a source of truth for whether an io_context is only running from a single thread or multiple threads.
This is for sure a premature optimization, but shouldn't hurt either way.
What the boost io_context documentation says about the
1option (we're on 1.81). https://www.boost.org/doc/libs/1_81_0/doc/html/boost_asio/overview/core/concurrency_hint.htmlRelated issue number
Checks
git commit -s) in this PR.scripts/format.shto lint the changes in this PR.method in Tune, I've added it in
doc/source/tune/api/under thecorresponding
.rstfile.