File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how much memory my hash table is consuming?

 
Sekhar Mondal
Greenhorn
Posts: 4
Chrome Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Clapham
Sheriff
Pie
Posts: 20209
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47313
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
Chrome Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
Chrome Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 9501
50
Eclipse IDE Hibernate Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic