views:

1289

answers:

4

We ship Java applications that are run on Linux, AIX and HP-Ux (PA-RISC). We seem to struggle to get acceptable levels of performance on HP-Ux from applications that work just fine in the other two environments. This is true of both execution time and memory consumption.

Although I'm yet to find a definitive article on "why", I believe that measuring memory consumption using "top" is a crude approach due to things like the shared code giving misleading results. However, it's about all we have to go on with a customer site where memory consumption on HP-Ux has become an issue. It only became an issue this time when we moved from Java 1.4 to Java 1.5 (on HP-Ux 11.23 PA-RISC). By "an issue", I mean that the machine ceased to create new processes because we had exhausted all 16GB of physical memory.

By measuring "before" and "after" total "free memory" we are trying to gauge how much has been consumed by a Java application. I wrote a quick app that stores 10,000 random 64 bit strings in an ArrayList and tried this approach to measuring consumption on Linux and HP-Ux under Java 1.4 and Java 1.5.

The results:

HP Java 1.4 ~60MB

HP Java 1.5 ~150MB

Linux Java 1.4 ~24MB

Linux Java 1.5 ~16MB

Can anyone explain why these results might arise? Is this some idiosyncrasy of the way "top" measures free memory? Does Java 1.5 on HP really consume 2.5 times more memory than Java 1.4?

Thanks.

+1  A: 
anjanb
JConsole shows nothing unusual. Of course I can only try it on Java 1.5, not 1.4, but the heap sits around the same size on both platforms. The "committed" memory also roughly the same size for the same maximum heap size (512M).
Gareth
Did you try the sun java forums. When a question has trumped other forums, I head to the source --- sun java forums -- http://forums.sun.com/forum.jspa?forumID=31
anjanb
A: 

First, it's not clear what did you measure by "10,000 random 64 bit strings" test. You supposed to start the application, measure it's bootstrap memory footprint, and then run your test. It could easily be that Java 1.5 acquires more heap right after start (due to heap manager settings, for instance).

Second, we do run Java apps under 1.4, 1.5 and 1.6 under HP-UX, and they don't demonstrate any special memory requirements. We have Itanium hardware, though.

Third, why do you use top? Why not just print Runtime.getRuntime().totalMemory()?

Fourth, by adding values to ArrayList you create memory fragmentation. ArrayList has to double it's internal storage now and then. Depending on GC settings and ArrayList.ensureCapacity() implementation the amount of non-collected memory may differ dramatically between 1.4 and 1.5.

Essentially, instead of figuring out the cause of problem you have run a random test that gives you no useful information. You should run a profiler on the application to figure out where the memory leaks.

Vladimir Dyuzhev
The heap params are explicity set via the -Xm parameters.I am trying to test the difference between before Java runs and afterwards - totalMemory() can't be called while Java is not running.The ArrayList is initialised to size, it is not dynamically sized. The profiler shows no leaks.
Gareth
A: 

The JVMs might just have different default parameters. The heap will grow to the size that you have configured to let it. The default on the Sun VM is a certain percentage of the RAM in the machine - that's to say that Java will, by default, use more memory if you use a machine with more memory on it.

I'd be really surprised if the HP-UX VM hadn't had lots of tuning for this sort of thing by HP. I'd suggest you fiddle with the parameters on both - figure out what the smallest max heap size you can use without hurting performance or throughput.

Jonathan
A: 

You might also want to look at the problem you are trying to solve... I don't imagine there are many problems that eat 16GB of memory that aren't due for a good round of optimization.

Are you launching multiple VMs? Are you reading large datasets into memory, and not discarding them quickly enough? etc etc etc.

James Van Huis
Yes, we are launching multiple VMs. That's a separate issue. These are Jini services serving many users across multiple physical sites and installations of the same applications on the one server. The servers are stateless though, so there's no problems with object retention.
Gareth