Add AsyncDrainWriter to eliminate PrintWriter lock contention - #12654
Draft
gnodet wants to merge 1 commit into
Draft
Add AsyncDrainWriter to eliminate PrintWriter lock contention#12654gnodet wants to merge 1 commit into
gnodet wants to merge 1 commit into
Conversation
During parallel model building, multiple PhasingExecutor threads log concurrently via SLF4J → ProjectBuildLogAppender → SimpleBuildEventListener → PrintWriter.println(). Since PrintWriter.println() is synchronized, this creates significant contention (1,470ms blocked time on a 4383-module project with -T1C). AsyncDrainWriter wraps the writer Consumer with a lock-free ConcurrentLinkedQueue and a non-blocking tryLock() drain pattern: - Producers enqueue messages (CAS, no blocking) - At most one thread drains the queue to the underlying PrintWriter - Other threads return immediately after enqueue - close() performs a final blocking drain to ensure no messages are lost JFR results on 4383-module diamond project (validate -T1C): - PrintWriter contention: 1,470ms → 0ms (eliminated) - PhasingExecutor contention: 546ms → 49ms (side effect) - Median wall time: -485ms (-3.3%) - Run-to-run variance halved (range 2.70s → 1.33s) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.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.
Summary
During parallel model building (
-T1C), multiplePhasingExecutorthreads log concurrently via:Since
PrintWriter.println()issynchronized, all threads serialize on every log call. JFR profiling on a 4383-module diamond-graph project shows 1,470ms of blocked time from this single contention point — the #1 source of lock contention duringvalidate.Fix
AsyncDrainWriterwraps theConsumer<String>writer with a lock-free queue + non-blocking drain:ConcurrentLinkedQueue(CAS, no blocking)PrintWriter(viaReentrantLock.tryLock())close()performs a final blocking drain to guarantee no messages are lostJFR Results (4383-module diamond project,
validate -T1C)Benchmark (10 runs)
All 8,766 module log lines verified present — zero messages lost.
Test plan
maven-coreunit tests passmaven-cliunit tests pass🤖 Generated with Claude Code