Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 297
plcstpierre Avatar asked Jun 02 '12 12:06

plcstpierre


2 Answers

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.

like image 90
Guillaume Perrot Avatar answered Sep 30 '22 23:09

Guillaume Perrot


This very long thread claims that small writes could be causing the problem. It is worth a read, but I don't know what you could do about it. What could you do? You might make sure you aren't using a small fetch size. This wouldn't give you small writes, but small reads which leads to the same problem. You might try different platforms for the client or server. There is a comment in this bug that reads:

"We've seen vastly different behavior on how quickly I/O buffers get filled between Solaris and Linux (and thus the number of calls to ReadAheadInputStream.fill(), because it reads what's available, it doesn't block unless it needs to read more than what's available)."

like image 37
John Watts Avatar answered Oct 01 '22 00:10

John Watts