Earth Notes: A Note On the JProfiler Java Performance-tuning Tool: Review

Tuning my application with JProfiler to run it on smaller servers, save energy, and cut its carbon footprint...

Review

I've used a lot of IT performance-tuning tools over the years, in particular for the C++ and Java programming languages, but also more widely for systems tuning for improved performance and reduced power consumption.

I've also used JProfiler before: ej-technologies has in the past granted me a free licence for JProfiler to work on my pro-bono Java-based multimedia gallery. (And I have such a licence again, having been really pleased with the trial period the offered on the new version, and asked nicely...) I remain earnestly of the opinion that JProfiler is one of the more pleasant tools in this area to work with that I have encountered, and both improvements in the Java platform and JProfiler's polish have helped.

With Java's reflection it is possible to build some simple programmatic profiling tools that examine what running threads are up to, and the Gallery automatically accumulates a simple profile of mirrors/nodes/servers that get unexpectedly busy for example, but that takes some effort and requires knowing fairly precisely what you're looking for. The beauty of tools such as JProfiler is the holistic view that they can provide of CPU, memory, threading and similar issues, often ones that you didn't know you had.

Something I keep reminding my clients, on Knuth's dictum:

"Premature optimisation is the root of all evil"
is to build a sensible design that is not deliberately profligate or careless with resources, but do not attempt to optimise without finding that there is some performance problem and then use a tool such as JProfiler to know where it actually is, not where you think it might be. That focus of effort on where it will actually pay off is priceless.

For the Gallery, though it may look like it's all about photographs, it actually spends a great deal of its time handling and manipulating text, partly because it's an HTTP/Web based server, and partly because it holds the entire meta-data database in memory for speed, and therefore has to use efficient and complex representations for some parts. Especially since I'm aiming to run on relatively low-powered systems (constrained memory and CPU speed) to keep down carbon footprint, even while running geographically-distributed instances to keep responsiveness good for users worldwide.

Basically I aim to be able to run mirrors on server instances using a few Watts at most, such as the SheevaPlug and maybe even a (B) Raspberry Pi, though the latter will require further tweaking!

(The biggest/busiest of my mirrors are multi-core, multi-GB, multi-GHz affairs, and the exact same Java code runs on them, inflating itself to fit!)

The two facets that tend to alternate in my attention therefore are memory and CPU efficiency, and JProfiler does a good job with each of those.

Memory

For example, if I run up a mirror of the Gallery in development (it attaches itself to the rest of the system just like a production node, but only I can see its Web interface so only I see how much I borked it), and attach JProfiler to it (without changing start-up scripts for example) I have access to most JProfiler features (other than watching array allocation) and can ask it to start profiling for memory and CPU immediately, the whole effort taking about 30 seconds:

initial memory view

...which tells you straight away that a lot of memory is taken up with text (String and char[]) though in fact after a little while when the system warms up, it holds most text as 7- or 8-bit clean text in byte[] for a 50% space saving, or with various compression schemes, again resulting in byte[], and the String and char[] entries largely go away.

CPU

On the CPU side (and on any system that can 'sleep' well, saving energy, less CPU load corresponds directly to less energy use as well as better speed) I heavily use the "Hot Spots" screen, and here the top items are all to do with text handling again:

CPU Hot Spots view

Methods that I was concentrating on tuning last week, from the Name class (another compact representation like a trie), and that were right at the top of the list eating up >10% of CPU, have slipped a long way down out of sight. I may have slowed sea-level rise!

Conclusion

This is not the right site for an in-depth technical exposé, but JProfile does what it says on the tin, reliably and well.

Sources/Links

The machine that serves this site is powered by local off-grid solar and wind renewable energy as far as possible, backed up by on-grid renewables including as of 2008/03 a substantial grid-tie solar PV system, and 100% renewable grid power (mainly wind) from Ecotricity; power draw is ~4W.
Please email corrections, comments and suggestions.
Please read our privacy policy.
Copyright © Damon Hart-Davis 2007-2013.