Repository navigation
perf(sched): shorten the turns of a thread that spins while the threads it waits on run short turns - #100
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
There was a problem hiding this comment.
The PR reduces scheduler quantum for threads that spin while other threads run short turns. It adds per-thread quantum tracking and a global short-turn counter; when a thread stays runnable for over 50 µs while other threads have recently blocked, its turn is halved down to 200 instructions. A new test SpinningNotifier.java validates the fix.
review-bot, model nvidia/nemotron-3-ultra-550b-a55b:free, verdict approve
What this changes
The scheduler gives each thread turns of 20000 instructions. A thread that spins (for example on
notify()in a loop) while the threads it waits on run short turns held the VM for most of the time: inCancelTimerWithContentionthe spinning main thread used 1849 of 1919 ms in one step.test/java/SpinningNotifier.java: the main thread spins onnotify()while 3000 virtual threads wait on the same locks.Tests
pnpm test: 269 pass, 0 fail, 3 skipped.SpinningNotifieroutput matches HotSpot.passing.txtunderjava/lang/Thread,java/util/concurrentandjava/lang/management: 76 pass, 3 time out (theJSR166TestCaseentries, which also time out onnext).ParkALotandGetStackTraceALotWhenBlockingpass.CancelTimerWithContentionstep with 6400 threads: about 1 s on the branch, 10.5 to 11.4 s onnext. CPU time for the 3200 and 6400 thread steps: 5.3 s against 17.8 s. The whole test now passes at a 600 s timeout (269 s and 443 s under load), so it stays out ofpassing.txtfor now.nextwithin the spread over 5 alternating runs each.Noticed, not fixed
Skynet100kWithMonitorsstill times out at 600 s on both: 10.4 to 13.6 s per round over 50 rounds. Its profile is flat (GC 8%, frame unpacking 4%, scheduler 8%), about 100 µs per virtual thread, so it needs faster Java execution in general rather than a scheduler change.CancelTimerWithContentionto 199 s, but madeParkALotandGetStackTraceALotWhenBlockingtime out. A version that works needs a rule that never delays a thread another thread waits for.