aspose file tools*
The moose likes Java in General and the fly likes how much memory my hash table is consuming? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "how much memory my hash table is consuming?" Watch "how much memory my hash table is consuming?" New topic
Author

how much memory my hash table is consuming?

Sekhar Mondal
Greenhorn

Joined: Apr 25, 2012
Posts: 4

Recently after analyzing the heap dump I found that some hash tables are becoming too large. Yes, we store some information in hash table and cached it. It remains in memory until the JVMs got recycled.

Want to find out how much memory my hash table is consuming? Something like this...I will run a small program/JSP, it will catch the details and give me output like XYZ hash table size is 15 MB etc.

Can someone please let me know how to get this? Any leads will be helpful.


hakuna matata!!!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18675
    
    8

There are profilers which can do that kind of thing for you.

But suppose that the profiler tells you that your hash table is using 12 megabytes of memory, just for example. What do you propose to do with that information?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Welcome to the Ranch

How large are these maps? 15MB seems inordinately large for a Map, but it only forms a small part of the average heap size (the default is ¼ of the available RAM), so even on my little 11″ laptop that is nearly 500MB.
Sekhar Mondal
Greenhorn

Joined: Apr 25, 2012
Posts: 4

Campbell Ritchie wrote:Welcome to the Ranch

How large are these maps? 15MB seems inordinately large for a Map, but it only forms a small part of the average heap size (the default is ¼ of the available RAM), so even on my little 11″ laptop that is nearly 500MB.


Thanks Campbell!
We have 1GB of heap size. In heap dump I found one single hashtable was taking around 185MB which is way way above our expectation. It had 18000 entries. 30-40MB is acceptable. That's why I am worried. Want to check the hashtable size periodically. Whether it's behaving awkward or not.
Sekhar Mondal
Greenhorn

Joined: Apr 25, 2012
Posts: 4

Paul Clapham wrote:There are profilers which can do that kind of thing for you.

But suppose that the profiler tells you that your hash table is using 12 megabytes of memory, just for example. What do you propose to do with that information?


I do jProfiling my code before check in to repository. But they'll never ever allow me to profile the app which is in customer side. That's why I'm looking for backdoor. :)
Yesterday I found Java added Instrumentation interface...webpage
But it sounds to me that it's for the tool makers....

"What do you propose to do with that information?"...will try to simulate the situation,try to recreate the issue...I would like to know why this is getting bigger...and if I can recreate the issue then we can fix it. :)
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8016
    
  22

Sekhar Mondal wrote:...will try to simulate the situation,try to recreate the issue...I would like to know why this is getting bigger...and if I can recreate the issue then we can fix it. :)

It may be worth mentioning that hash tables (you haven't said whether this is a Hashtable or a HashMap) are generally very poor when it comes to space utilization.

For a start, the bucket array alone will be the nearest power of 2 greater than current_size*1.33, and each of its elements are actually forward-linked list entries. However, it probably doesn't fully explain the sizes you're seeing (unless the objects you're storing are very large).

One thing that might help is to create the table with sufficient size to hold all likely entries, as this will reduce the need for rehashing (space from old copies is likely to hang around until the gc sees a need to reclaim it). It will also probably make things quicker. Another possibility is to raise the load factor, although this might affect performance.

HIH

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how much memory my hash table is consuming?