I just went through a lot of memory optimization on a small spider I
wrote, here's some thoughts..

>Essentially, RSS reflects how much of the program's address space has
>been touched recently, as well as the kernel's decision about how to
>allocate physical memory among processes that need it.

Yes, the RSS is the most useful number. The VSZ for a Java process is
just going to be the maximum heap. Ie: you run "java -mx128M", and VSZ
will be 128M. RSS reflects better the memory requirements, although if
some of your process is swapped out you'll get confused. (ps -axm
reports some other interesting numbers, but at least back in Linux 2.0
they didn't actually make sense.)

Java also has a couple of calls to learn about its memory status -
Runtime.getFreeMemory() and Runtime.getTotalMemory(). As near as I can
tell, these are completely meaningless in the Blackdown JDK. Someone
please correct me if I'm wrong, but when I was calling them I was
getting essentially random numbers.

I just spent 3 days trying to fix a process that was chewing up way
too much memory. I've written a spider, and part of what it does is
keep about 500,000 IP addresses in a hashtable in memory. I was
storing the addresses as strings and was consuming > 170M, which I
couldn't handle. Turns out if I store the addresses as Integers, it's
a lot more efficient, like 60M instead of 170M.

This month's Javaworld has a good article on basics of memory
efficiency in Java.
  http://www.javaworld.com/javaworld/jw-11-1999/jw-11-performance.html

The most useful nugget of info there is that in JDK 1.1, the overhead
for Object is 26 bytes, and for String it's closer to 60 bytes.
(Strings are actually two objects + some integers). And characters in
Strings are 2 bytes each. Even so, I can't figure out why the memory
consumption of my program was so bad, unless Hashtable is horribly
space inefficient.

I'd be curious to know why Java needs 26 bytes for an Object. I'd
guess generously more like 16 bytes - 8 bytes for 2 pointers, 4 bytes
for a monitor, 4 bytes for GC state. But what do I know? Even Hotspot
only gets it down to 22 bytes/Object.

                                                  [EMAIL PROTECTED]
.       .      .     .    .   .  . . http://www.media.mit.edu/~nelson/


----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to