tags:

views:

165

answers:

6

I'm new into Java profiling, and I'd like to ask about it.

Does it make sense to profile an application on the server, where I only have the console?

Is there any console profiler which make sense?

Or should I profile the application only on localhost?

+4  A: 

VisualVM is able to connect to a remote host. The profiling works the same way as local. It's part of the JDK since JDK 6 update 7.

Thomas Jung
As far as I know it only monitors remote apps, but doesn't profile them.
bingle
+1  A: 

You can use console integration wizard of YourKit profiler http://www.yourkit.com/docs/80/help/profiling%5Fj2ee%5Fremote.jsp to hook profiler into J2EE server. After that it's possible to remotely profiler server from GUI machine.

--serge

Serge
+1  A: 

Does it make sense to profile an application on the server, where I only have the console?

Fortunately, that does not matter, since Java has always (well, for a long time, anyway) supported remote profiling, i.e. the Profiler can run on a different machine than the JVM being profiled and get its data via the network.

All Java profilers that I've ever seen support this, including visualvm, which comes with recent JDKs (in the bin directory).

Michael Borgwardt
+1  A: 

There's a "quick and dirty" but effective way to find performance problems in Java. This is a language-agnostic explanation of why it works.

Mike Dunlavey
+2  A: 

When you do profiling you should generally try to reproduce the production environment as closely as possible. Differences in hardware (# of cores, memory, etc) and software (OS, JVM version) can make your profiling results as unique as the runtime environment.

For example, what looks like a CPU bottleneck worth optimizing on your local machine might disappear entirely or turn into a disk bottleneck on your production server depending on the differences in the CPU.

All modern profilers will allow to attach to a remotely running JVM so you don't need to worry about only having console access.

What profiler you decide to use will depend on your needs and preferences. Certain profilers will show you "hotspots" where your code is spending the majority of the time and these are often good candidates for optimization.

I prefer to use JProfiler for its extensive features and good performance. I previously used YourKit but switched to JProfiler for its memory and thread profiling features.

Vladimir Giverts
A: 

Note that the JDK comes with a built-in profiler, HPROF. HPROF is a bit simplistic, but will find many problems. It is activated simply by invoking the JVM with parameter -agentlib:hprof; it will then automatically run as long as your JVM is running. It collects data until the JVM terminates, then dumps it into a file on the server, which you can analyze.

See e.g. http://java.sun.com/developer/technicalArticles/Programming/HPROF.html for a good introduction. A nice graphical analyzer for HPROF's results is PerfAnal: http://java.sun.com/developer/technicalArticles/Programming/perfanal/

sleske