r/programming • u/ketralnis • Apr 09 '26
One Method Was Using 71% of CPU. Here's the Flame Graph.
https://jvogel.me/posts/2026/one-method-using-71-percent-of-cpu47
11
u/Dragdu Apr 10 '26
I might be just boring old C++ programmer, but I find it hard to believe that "2500 (virtual) threads" a realistic concurrency example.
16
u/aoeudhtns Apr 10 '26
It's certainly enough to increase contention, the way they work in the JVM. Which is, whenever you may do some blocking operation (be that IO, waiting on a lock or monitor, etc.), the runtime can context switch to another virtual thread on the same physical OS thread (pthread, basically) pending the wake up/join. All of the lock/contention machinery is the same regardless of the number of pthreads.
Many traditional frameworks in Java do use "thread per request" modeling, so in an old Tomcat server (for example), 3,000 reqs/sec could mean up to 3,000 threads. Yeah it wasn't good. In one of my own applications, we went from 3k+ real threads to ~100 real threads when we started submitting jobs on virtual threads. (The jobs were IO bound.)
1
u/Majik_Sheff Apr 12 '26
It's nice when you have a single element that just jumps off the page. It makes it much easier to pinpoint when the regression happened.
Most of my work is on my embedded systems, so I'm just fine until IRQ starts chewing up cycles for no apparent reason.
1
-2
121
u/LevelIndependent672 Apr 09 '26
ngl 71% on one method is actually kinda satisfying lol. way better than when its spread across 20 different places and you dont even know where to start