-
Notifications
You must be signed in to change notification settings - Fork 18
Implement a multi-threaded transaction scheduler #559
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
Closed
bmuddha
wants to merge
10
commits into
thlorenz/chainlink
from
bmuddha/feat/multi-threaded-scheduler
Closed
Implement a multi-threaded transaction scheduler #559
bmuddha
wants to merge
10
commits into
thlorenz/chainlink
from
bmuddha/feat/multi-threaded-scheduler
Conversation
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
13 files reviewed, 9 comments
22209a9 to
7c94e1f
Compare
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.
This introduces a new multi-threaded transaction scheduler to the
magicblock-processor, replacing the previous single-threaded implementation. This new design significantly improves performance by processing non-conflicting transactions in parallel.The core of this feature is a central scheduler that dispatches transactions to a pool of worker threads. A lock-free coordination mechanism based on bitmasks is used to manage account access, ensuring that only transactions with non-overlapping write sets are executed concurrently.
Changes in this PR include:
Greptile Overview
Updated On: 2025-10-01 12:37:32 UTC
Summary
This PR introduces a significant architectural change to the MagicBlock validator by implementing a multi-threaded transaction scheduler that replaces the previous single-threaded implementation. The new scheduler enables parallel processing of non-conflicting transactions, which should substantially improve throughput performance.The core architecture consists of three main components:
Multi-threaded Scheduler: A central dispatcher that manages a pool of worker threads and coordinates transaction distribution. The scheduler uses channels for communication and implements a biased event loop that prioritizes ready executors.
ExecutionCoordinator: A state management component that tracks executor readiness, manages transaction queuing for blocked operations, and handles dependency resolution. It maintains maps of ready executors and blocked transactions, automatically rescheduling transactions when their dependencies are resolved.
Bitmask-based Account Locking: A high-performance locking mechanism that uses a single
u64per account to represent lock state. The MSB indicates write locks while remaining bits track read locks for up to 63 concurrent executors. This approach provides O(1) lock operations and efficient contention detection.The implementation includes dynamic CPU-aware thread allocation, dedicating half of available cores to async I/O operations (RPC, WebSocket services) and the other half to transaction execution. The scheduler integrates with the existing
TransactionExecutorinfrastructure, maintaining compatibility with the current transaction processing pipeline while adding concurrency capabilities.The changes span multiple crates, adding dependencies for high-performance hashing (
rustc-hash) and CPU detection (num_cpus), and include comprehensive test coverage for the coordination logic.Important Files Changed
Changed Files
Confidence score: 2/5
magicblock-processor/src/scheduler/locks.rswhich has multiple critical bugs that must be fixed before mergeSequence Diagram
sequenceDiagram participant User participant TransactionScheduler participant ExecutionCoordinator participant ExecutorPool as "TransactionExecutor Pool" participant AccountsDB participant Ledger participant RPC as "RPC/WebSocket Server" User->>RPC: "Submit Transaction" RPC->>TransactionScheduler: "ProcessableTransaction via channel" TransactionScheduler->>ExecutionCoordinator: "get_ready_executor()" ExecutionCoordinator-->>TransactionScheduler: "ExecutorId" TransactionScheduler->>ExecutionCoordinator: "try_acquire_locks(executor, transaction)" ExecutionCoordinator->>ExecutionCoordinator: "Check