Reputation: 1966
I am profiling my application which uses Spring, Hibernate, and mysql-java-connector. The VisualVM shows that more than 50% of CPU time is spent in com.myql.jdbc.utils.ReadAheadInputStream.fill()
method when there are 1000 parallel connections doing read.
Is there any optimization to make it faster?
Upvotes: 12
Views: 2892
Reputation: 2223
VisualVM counts a thread as using CPU time whenever the JVM thinks it's runnable. This means that any thread not waiting on a lock is considered runnable, more or less, including threads waiting for I/O in the kernel! This is where the large amount of CPU usage in com.myql.jdbc.utils.ReadAheadInputStream.fill()
is coming from. So instead of a CPU problem you have an I/O problem.
There are some things you can do on the JVM side, but not a lot of straightforward optimizing:
Upvotes: 3
Reputation: 6107
On top of the other suggestions, consider also experimenting with a much lower amount of connections (i.e. 20). It's very possible that the overhead of handling such a large amount of open connections is slightly fooling your profiling observations.
Not least, make sure you're using a recent version of Hibernate ORM. We made version 5.0+ much smarter than previous versions, especially regarding performance improvements ;-) Improvements are applied daily, so keeping up to date or at least trying the latest might be an easy win.
Upvotes: 2
Reputation: 9945
It's hard to answer your question without additional information. Here some information needs that should be fulfilled before.
fill()
method uses half of CPU time available to system it seems strange. But if this number was get using VisualVM which reports usage time relative to time spent in application, it just may be the rest of your application is not doing significant work?pidstat
, mpstat
and sar
to crosscheck if you on a Linux. I've seen VisualVM marked time spent in SocketInputStream.socketRead0()
method as a CPU time, which was not confirmed by pidstat
. I guess it's consequences of some measurement approximations in VisualVM itself or JVM behavior. So it's always good idea to crosscheck using OS tools.Upvotes: 0