Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java profiling: detect which piece of code causes high CPU load

I profiled my code with both JProfiler and YourKit. However, I haven't been able to figure out how to detect which piece of code is responsible for high CPU load.

It's trivial to detect hot spots if the response time is bad. In my case though response time is not a problem. It's just that the CPU load is really high (surprisingly high) during the short time this particular request is processed.

How can I pin-point which class(es)/method(s) are causing this? I guess what I'm looking for is some kind of list which tells me how many CPU cycles the processing of a method required - or so.

like image 920
Marcel Stör Avatar asked May 08 '11 13:05

Marcel Stör


1 Answers

CPU load essentially indicates the number of cpu cycles where the cpu had something to do instead of just twiddling virtual thumbs.

So if your request actually does real work (instead of waiting for disk I/O) then it is to be expected that the load goes high while the work is being done as the cpu has something to do.

The thing you need to look for is running out of cpu cycles as that is when the response times start climbing.

If your problem here is that the request is so short that the profiler cannot show you what you need to see, then consider using an automated tool to ask it to process hundreds of thousands of requests. This should help.

like image 116
Thorbjørn Ravn Andersen Avatar answered Oct 13 '22 22:10

Thorbjørn Ravn Andersen