Assign a distinct event loop to each virtual-thread verticle instance#6241
Open
Develop-KIM wants to merge 1 commit into
Open
Assign a distinct event loop to each virtual-thread verticle instance#6241Develop-KIM wants to merge 1 commit into
Develop-KIM wants to merge 1 commit into
Conversation
Deploying a verticle with setInstances(N) and ThreadingModel.VIRTUAL_THREAD pinned every instance to the first instance's event loop, so raising the instance count no longer scaled I/O: the single event loop saturates while the virtual threads starve. This regressed Vert.x 4.5.x, where each virtual-thread instance was assigned an event loop via eventLoopGroup.next(). DefaultDeployment now builds a fresh context for each virtual-thread instance, letting ContextBuilderImpl round-robin over the event loop group as the event-loop threading model already does. Fixes eclipse-vertx#5924 Implemented with AI assistance (Claude); all changes were reviewed, tested and are owned by the author. Signed-off-by: Develop-KIM <kimdonghwan913@gmail.com>
8df9168 to
99c36a7
Compare
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.
Motivation
Deploying a verticle with
setInstances(N)andThreadingModel.VIRTUAL_THREADpins every instance to the same event loop (vert.x-eventloop-thread-0) instead of distributing them across the event loop group. Raising the instance count therefore stops scaling I/O — the single event loop saturates while the virtual threads starve. This is a regression from Vert.x 4.5.x, where each virtual-thread instance was assigned an event loop viaeventLoopGroup.next().The reporter's k6 load test (
setInstances(300),VIRTUAL_THREAD) hit a hard ceiling of ~40k RPS because all 300 instances shared one event loop.Fixes #5924
Root cause
In
DefaultDeployment.deploy(), theVIRTUAL_THREADbranch copied theWORKERpattern: the first instance's event loop was captured inworkerLoopand forced on every subsequent instance via.withEventLoop(workerLoop). TheEVENT_LOOPbranch omits.withEventLoop(...), soContextBuilderImpl.build()selects the next loop vianettyEventLoopGroup().next()(round-robin).Change
Build a fresh context for each virtual-thread instance (no shared-loop reuse), so each one round-robins over the event loop group like the event-loop model already does.
workerLoopis now used only by theWORKERbranch.Test
DeploymentTest#testDeployInstancesUseDistinctEventLoopsdeploys 4VIRTUAL_THREADinstances (8-loop pool) and asserts 4 distinct netty event loops. It fails on the current code (expected:<4> but was:<1>) and passes with the fix; the fullDeploymentTestandContextTestsuites remain green.@vietj — you mentioned possibly making this configurable. This restores the scaling default; happy to layer a toggle on top in a follow-up if you'd prefer.
Implemented with AI assistance (Claude); I reviewed, tested and own all changes.