Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use VisualVM to spot the bottleneck/problem

As I posted in Performance drop after 5 days running web application, how to spot the bottleneck? , I have a problem with an application that gets slow after running for a while.

I got VisualVM running and made a snapshot between different times. Now the application is really slow, but I have no idea how to spot the bottleneck. They don't have many differences between each other and the only thing that grows a bit is the Heap, which is successfully garbage collected after a while.

Can anyone give me some pointers?

Here are the snapshots (apps):

[1] http://www.2shared.com/file/W4XJ6HtE/application-1314108550032.html

[2] http://www.2shared.com/fadmin/22521338/f512f97e/application-1314097232727.apps.html

Thank you!

EDIT: Looking closer, I've noticed that the CPU is not even being used much.. and the system is really slow!

like image 988
José Leal Avatar asked Aug 23 '11 14:08

José Leal


2 Answers

As a first step I would suggest to identify what exactly is slow. Does it execute some job slowly? Or demonstrates low throughput on handling jobs from different clients?

What resource is unsufficient?

  • If you are using some external services (like database or RPC server) always log their response time and check it before making any other optimization steps.
  • It could be a lack of processor power. Just look at CPU usage.
  • It could be a lack of memory. Use gc logging to detect such kind of issues. There is a good topic about it.
  • It could be a lack of hard drive speed. Use the iostat and know your HDD performance limits.
  • It could be a lack of network throughput. Check network channel usage.
  • Also it is possible that you run out of some OS-specific limits, like number of opened files and/or network sockets. Check that you properly report all OS-level exception into log files.

As you have identified which resource is unsufficient and the part of your program which suffers from it you could try to find the piece of code to optimize. Taking a random tool and run your application through it without knowing what to look for makes no sense.

From my personal experience it is very rare case when you have just a slow method, which could be found with a profiler. Most likely it is an unexpected IO and/or synchronisation somewhere in your algorithm or bad database schema.

like image 107
CheatEx Avatar answered Sep 23 '22 07:09

CheatEx


Actually, there are some better tools than VisualVM.

You could try JProfiler, which is a nice profiler (but paid)

And you could try the Netbeans profiler, which is free and works great

With VisualVM you'll only see the actual state of your application (memory and cpu usage, JMXs, classes loaded, etc).

like image 39
Kico Lobo Avatar answered Sep 25 '22 07:09

Kico Lobo