Search code examples
javaprofilingvisualvm

VisualVM socket.read


So I was profiling my application with VisualVM.

I hit a hotspot about my MySQL interaction. My first thoughts was that hot spot was showing time that my application was waiting after the IO. But in the profiling report, VisualVM has two column "Time" and "Time (cpu)". Maybe the term is wrongly used, but I assumed self-time (cpu) column was excluding IO time. After more debugging, we concluded that assumption was wrong and was showing IO time because the hotspot was on java.net.SocketInputStream.read() of the MySQL driver and other IO things that should not cost any cpu.

So, my question is why visualvm report SocketInputStream.read() as cpu time?

Screnshot


Solution

  • native calls are always in the RUNNABLE state while monitoring thread activity, probably because the JVM has no way to know if the native call is sleeping or actually doing something. Thus, time passed in the RUNNABLE state counts as CPU time.