Repository navigation
Introduce a thread pool for batch execution of parallel CPU-bound tasks. - #5354
Merged
Merged
Conversation
dmkozh
force-pushed
the
apply_thread_pool
branch
2 times, most recently
from
July 16, 2026 21:25
b8a33cd to
3a8b7c1
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Introduces a reusable CPU-pinned thread pool for parallel workloads, initially replacing per-stage Soroban apply threads.
Changes:
- Adds
BatchExecutorwith worker reuse, affinity pinning, ordering, and exception handling. - Exposes the executor through application interfaces.
- Migrates parallel Soroban cluster execution and adds unit tests.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
src/util/BatchExecutor.h |
Defines the batch-execution API. |
src/util/BatchExecutor.cpp |
Implements workers, synchronization, and affinity. |
src/util/test/BatchExecutorTests.cpp |
Tests execution, concurrency, errors, and reuse. |
src/main/Application.h |
Exposes the shared executor. |
src/main/ApplicationImpl.h |
Adds executor ownership and accessor. |
src/main/ApplicationImpl.cpp |
Constructs and returns the executor. |
src/main/AppConnector.h |
Declares executor forwarding. |
src/main/AppConnector.cpp |
Implements executor forwarding. |
src/ledger/LedgerManagerImpl.cpp |
Uses the pool for Soroban clusters. |
src/transactions/ParallelApplyUtils.cpp |
Adjusts apply-thread assertions. |
dmkozh
force-pushed
the
apply_thread_pool
branch
3 times, most recently
from
July 17, 2026 19:21
560f4f7 to
2050b6d
Compare
This introduced a new `BatchExecutor` class that uses a pool of physical CPU-pinned (if possible) workers to execute CPU-heavy workloads in parallel. Currently this is only used for the Soroban apply stage (which is already parallel), but in the followups we'll be able to use this for more apply flow stages (pre/post apply), as well as tasks outside of apply (like parallel tx set building). Pinning the threads helps a lot with making per-thread runtime more even on machines with hyper-threading (which is probably pretty much every CPU out there). Pooling the threads is less impactful, but it helps a bit with the allocator churn.
dmkozh
force-pushed
the
apply_thread_pool
branch
from
July 22, 2026 20:03
2050b6d to
902cefa
Compare
graydon
approved these changes
Jul 23, 2026
Contributor
There was a problem hiding this comment.
Looks fine to me. The robot flagged a couple things you might or might-not care about:
- Starting at logical CPU 0 when there are more cores than you need will be a little suboptimal, because the OS tends to schedule a lot of random stuff on that CPU ("housekeeping and unsteered IRQs", it claims). So you could check to see if you have more cores than needed and if so skip core 0.
- If you have fewer cores than needed, you wrap around to co-schedule on an already-used one, while skipping hyperthread siblings. Which is strictly worse than letting it land on hyperthread siblings. Shouldn't happen much in practice, but shrug might want to degrade a bit more gracefully?
Neither of these are dealbreakers to me so I'll approve as-is but if you want to fix either of them and go around again, ping me when you're ready and I'll re-approve.
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.
Description
This introduced a new
BatchExecutorclass that uses a pool of physical CPU-pinned (if possible) workers to execute CPU-heavy workloads in parallel. Currently this is only used for the Soroban apply stage (which is already parallel), but in the followups we'll be able to use this for more apply flow stages (pre/post apply), as well as tasks outside of apply (like parallel tx set building).Pinning the threads helps a lot with making per-thread runtime more even on machines with hyper-threading (which is probably pretty much every CPU out there). Pooling the threads is less impactful, but it helps a bit with the allocator churn.
While this is adding 'yet another' pool of workers, I've tried to make the interface invariants simple - the executor may only be used by a single thread at once, and the execution itself is blocking. Basically this is meant to be used in a similar fashion to one-off execution threads that we have now, but in a managed fashion.
Checklist
clang-formatv8.0.0 (viamake formator the Visual Studio extension)