?
Solved

Are Hashtable and Treeset heavy on the resources (memory)

Posted on 2011-03-06
8
Medium Priority
?
730 Views
Last Modified: 2012-05-11
Hi,
I'm developing an application where I'm planning to use two hashtables with about a size of 1000 each. In the value, each value will be storing a treeset as an object containing about 1000 values. What I'd like to know is if this hashtable and treeset setup with such a large size makes the design very resource heavy?

As per my understanding , Hashtables usually start with a default initial capacity of about 11 (or 16). So 1000 in this case might mean a lot. Is that correct?

Thanks.
0
Comment
Question by:orazen12
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 92

Accepted Solution

by:
objects earned 668 total points
ID: 35053459
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35053995
On most modern computers where you can have several  hundred megabytes of memory and maybe even
more than 1 GB for your application these requirements do not seem to be prohibitive - you'll probably
have to increase the amount of allocated memory  in the options for virtual machine, say
-Xmx512M  or someting like that.
0
 

Author Comment

by:orazen12
ID: 35054596
Thanks ObJects.

For_Yan,
My server has 1 GB memory out of which 750MB is already being used (atleast that's what it is showing me in the webmin). Do you mean to say I'd need approx 1GB for this kind of operation or it should be ok with with my current system. It is doing a lot of other stuff too. Is there a way to check how much memory my system is using for this kind of operation?

Thanks.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 13

Expert Comment

by:darren-w-
ID: 35055068
Hi,

Your computer would start using the swap if ram  is full, and this would then in turn slow down processing time as read-writes  from disk will be slower, apart from this it should not be a problem.

Darren
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 664 total points
ID: 35055113
I think the best way is first to write it in a straightforward way using all hashtables you need - make sure you are not getting java out of memory messages (provide sufficiently big number in -Xmx) and then observe - if you feel that your performance is too slow for your business  purposes, then try to monitor with your system means if your program is indeed doing a lot of memory swaps, then start thinking how to design your program to reduce memory size. My guess is that you'll not see too much swapping.
0
 
LVL 10

Assisted Solution

by:gordon_vt02
gordon_vt02 earned 668 total points
ID: 35058193
What kind of values are you storing?  The overhead of each Hashtable and TreeSet is fairly minimal so you need to figure out how much storage each object in the TreeSet requires and then you can estimate the amount of memory required.

Sk = memory for hash key
Se = memory for each tree entry
n = number of hash entries
m = number of tree set entries

App Mem = n * (Sk + (m * Se))

So, if your hash key is a long (8 bytes) and your TreeSets contain ints (4 bytes), with 1000 sets of 1000 items you would use:

1000 * (8 + (1000 * 4)) = 4,000,800 bytes = ~3.8 MB

If your value objects contain more complex data structures, especially variable length members like strings or arrays, you can come up with a good range and evaluate a worst-case scenario to make sure you have enough memory.  You aren't talking about a whole lot of data objects though, so unless each object is pretty big, you probably won't even need to modify the default JVM memory settings, and setting it to use at most the 250MB you have remaining should give plenty of room without swapping.
0
 
LVL 10

Expert Comment

by:gordon_vt02
ID: 35058201
Oops, flipped the 0 and 8 in that calculation.  Should be 4,008,000 bytes = ~3.8 MB.
0
 

Author Closing Comment

by:orazen12
ID: 35125537
Thanks.
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses
Course of the Month15 days, 3 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question