Large JVM memory size.

The application that we are working on requires very fast response times and we are thinking of implementing some caching mechanisms using singleton.

The scary thing is that cache size may be quite large -- approximately 500MB - 1GB.

Question that I have consists of two issues:

1) How JVM would handle such large amount of memory dedicated to it ? Is there any limitations on memory size ?
2) In terms of the speed, shall we expect any performance degradation when JVM deals with such large objects ?

Thank you for your help.
Who is Participating?
I run a banking application to a limit of 1540 Mb; using the SUN JRE 1.4.2_03 there seemed to be a limit there.
I used very high quantities of small objects.
To my surprise the CPU usage was very low, so the garbage collector had no problems.
The application run repeatedly for 90 hours.
So, there isn't really a problem with major JRE's.
Only two advises:
1) monitor your memory usage (I put it in the aboutbox so everybody could inspect it),
2) keep off calling .gc() it does more harm than good.

1) How JVM would handle such large amount of memory dedicated to it ? Is there any limitations on memory size ?
You can increase the memory size for the JVM using the following
java -Xms256m -Xmx512m

2) In terms of the speed, shall we expect any performance degradation when JVM deals with such large objects ?
If indeed you have so much of data cache the performance really depends on how you actually use the cache. Basically like you might be loading the whole data into memory and for navigating to the required data from the clients perspective depends on how u program to retrieve the data.
sasha_kvAuthor Commented:
1) I am familiar how to  increase memory size for JVM. The question here is more conceptual on limitations of memory size.

I've found this quote on the internet and not sure about validity of the this statement:

-- On 32-bit processor machines, the largest contiguous memory address space the operating system can allocate to a process is 1.8GB. Because of this, the maximum heap size can only be set up to 1.8GB. On 64-bit processor machines, the 1.8 GB limit does not apply, as 64-bit processor machines have a larger memory address space."

2) Cache mechanism will be implemented using HashMap, where userID (int) would represent a key, and UserVO that contains all the necessary data about a user would represent a value. If desiralized version of UserVO takes up let's say 10kb, then caching 50,000 users would require 500mb of memory. (if my math is correct :)

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Tommy BraasCommented:
Hi sasha_kv,

As far as limits on heap memory allocation. It really (apart from obvious 'physical' address space constraints) depends largely on the JVM implementation. I don't see a problem with a 500 MB of cache. We have caches here which exceed that amount. As far as performance goes, you might see a decrease in performance if you have a lot of objects with the same hash code, which is to be expected with a container type such as a hash table. How are you guarding access to the cache?


Look into using the LinkedHashMap.  It combines a linked list with the hashmap where the linked list is the Least Recently Used element.  This allows you to set a maxsize of your cache and to remove the oldest item in the cache.

You HAVE to set a maxsize of your cache (even if you never reach it).   You will probably NEVER reach the 1.8G maximum imposed by Windows.  When allocated memory starts approching the size of the REAL memory, the OS task scheduler will start thrashing (spending more time swaping memory than executing tasks).  This will degrade performance significantly.

I have seen this happen on both Windows and Unix environments (though the unix handled a larger memory allocation before thrashing).
sasha_kvAuthor Commented:
Thanks very much for everyone's input !!!
Tommy BraasCommented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.